fakeredis 0.5.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +14 -5
- data/LICENSE +1 -1
- data/README.md +42 -24
- data/fakeredis.gemspec +1 -1
- data/lib/fakeredis.rb +28 -0
- data/lib/fakeredis/bitop_command.rb +56 -0
- data/lib/fakeredis/command_executor.rb +6 -9
- data/lib/fakeredis/expiring_hash.rb +3 -5
- data/lib/fakeredis/geo_commands.rb +142 -0
- data/lib/fakeredis/geo_set.rb +84 -0
- data/lib/fakeredis/minitest.rb +24 -0
- data/lib/fakeredis/rspec.rb +1 -0
- data/lib/fakeredis/sort_method.rb +3 -3
- data/lib/fakeredis/sorted_set_store.rb +1 -1
- data/lib/fakeredis/transaction_commands.rb +2 -2
- data/lib/fakeredis/version.rb +1 -1
- data/lib/fakeredis/zset.rb +8 -2
- data/lib/redis/connection/memory.rb +650 -82
- data/spec/bitop_command_spec.rb +209 -0
- data/spec/command_executor_spec.rb +15 -0
- data/spec/compatibility_spec.rb +1 -1
- data/spec/connection_spec.rb +21 -21
- data/spec/fakeredis_spec.rb +73 -0
- data/spec/geo_set_spec.rb +164 -0
- data/spec/hashes_spec.rb +138 -57
- data/spec/hyper_log_logs_spec.rb +50 -0
- data/spec/keys_spec.rb +232 -90
- data/spec/lists_spec.rb +91 -35
- data/spec/memory_spec.rb +80 -7
- data/spec/server_spec.rb +38 -24
- data/spec/sets_spec.rb +112 -46
- data/spec/sort_method_spec.rb +6 -0
- data/spec/sorted_sets_spec.rb +482 -150
- data/spec/spec_helper.rb +9 -18
- data/spec/spec_helper_live_redis.rb +4 -4
- data/spec/strings_spec.rb +113 -79
- data/spec/subscription_spec.rb +107 -0
- data/spec/support/shared_examples/bitwise_operation.rb +59 -0
- data/spec/support/shared_examples/sortable.rb +20 -16
- data/spec/transactions_spec.rb +34 -13
- data/spec/upcase_method_name_spec.rb +2 -2
- metadata +23 -6
@@ -0,0 +1,59 @@
|
|
1
|
+
shared_examples_for "a bitwise operation" do |operator|
|
2
|
+
it 'raises an argument error when not passed any source keys' do
|
3
|
+
expect { @client.bitop(operator, "destkey") }.to raise_error(Redis::CommandError)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "should not create destination key if nothing found" do
|
7
|
+
expect(@client.bitop(operator, "dest1", "nothing_here1")).to eq(0)
|
8
|
+
expect(@client.exists("dest1")).to eq(false)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should accept operator as a case-insensitive symbol" do
|
12
|
+
@client.set("key1", "foobar")
|
13
|
+
@client.bitop(operator.to_s.downcase.to_sym, "dest1", "key1")
|
14
|
+
@client.bitop(operator.to_s.upcase.to_sym, "dest2", "key1")
|
15
|
+
|
16
|
+
expect(@client.get("dest1")).to eq("foobar")
|
17
|
+
expect(@client.get("dest2")).to eq("foobar")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should accept operator as a case-insensitive string" do
|
21
|
+
@client.set("key1", "foobar")
|
22
|
+
@client.bitop(operator.to_s.downcase, "dest1", "key1")
|
23
|
+
@client.bitop(operator.to_s.upcase, "dest2", "key1")
|
24
|
+
|
25
|
+
expect(@client.get("dest1")).to eq("foobar")
|
26
|
+
expect(@client.get("dest2")).to eq("foobar")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should copy original string for single key" do
|
30
|
+
@client.set("key1", "foobar")
|
31
|
+
@client.bitop(operator, "dest1", "key1")
|
32
|
+
|
33
|
+
expect(@client.get("dest1")).to eq("foobar")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should copy original string for single key" do
|
37
|
+
@client.set("key1", "foobar")
|
38
|
+
@client.bitop(operator, "dest1", "key1")
|
39
|
+
|
40
|
+
expect(@client.get("dest1")).to eq("foobar")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return length of the string stored in the destination key" do
|
44
|
+
@client.set("key1", "foobar")
|
45
|
+
@client.set("key2", "baz")
|
46
|
+
|
47
|
+
expect(@client.bitop(operator, "dest1", "key1")).to eq(6)
|
48
|
+
expect(@client.bitop(operator, "dest2", "key2")).to eq(3)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should overwrite previous value with new one" do
|
52
|
+
@client.set("key1", "foobar")
|
53
|
+
@client.set("key2", "baz")
|
54
|
+
@client.bitop(operator, "dest1", "key1")
|
55
|
+
@client.bitop(operator, "dest1", "key2")
|
56
|
+
|
57
|
+
expect(@client.get("dest1")).to eq("baz")
|
58
|
+
end
|
59
|
+
end
|
@@ -1,69 +1,73 @@
|
|
1
1
|
shared_examples_for "a sortable" do
|
2
2
|
it 'returns empty array on nil' do
|
3
|
-
@client.sort(nil).
|
3
|
+
expect(@client.sort(nil)).to eq([])
|
4
4
|
end
|
5
5
|
|
6
6
|
context 'ordering' do
|
7
7
|
it 'orders ascending by default' do
|
8
|
-
@client.sort(@key).
|
8
|
+
expect(@client.sort(@key)).to eq(['1', '2'])
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'orders by ascending when specified' do
|
12
|
-
@client.sort(@key, :order => "ASC").
|
12
|
+
expect(@client.sort(@key, :order => "ASC")).to eq(['1', '2'])
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'orders by descending when specified' do
|
16
|
-
@client.sort(@key, :order => "DESC").
|
16
|
+
expect(@client.sort(@key, :order => "DESC")).to eq(['2', '1'])
|
17
17
|
end
|
18
18
|
|
19
19
|
it "orders by ascending when alpha is specified" do
|
20
|
-
@client.sort(@key, :order => "ALPHA").
|
20
|
+
expect(@client.sort(@key, :order => "ALPHA")).to eq(["1", "2"])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'projections' do
|
25
25
|
it 'projects element when :get is "#"' do
|
26
|
-
@client.sort(@key, :get => '#').
|
26
|
+
expect(@client.sort(@key, :get => '#')).to eq(['1', '2'])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'projects through a key pattern' do
|
30
|
-
@client.sort(@key, :get => 'fake-redis-test:values_*').
|
30
|
+
expect(@client.sort(@key, :get => 'fake-redis-test:values_*')).to eq(['a', 'b'])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'projects through a key pattern and reflects element' do
|
34
|
-
@client.sort(@key, :get => ['#', 'fake-redis-test:values_*']).
|
34
|
+
expect(@client.sort(@key, :get => ['#', 'fake-redis-test:values_*'])).to eq([['1', 'a'], ['2', 'b']])
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'projects through a hash key pattern' do
|
38
|
-
@client.sort(@key, :get => 'fake-redis-test:hash_*->key').
|
38
|
+
expect(@client.sort(@key, :get => 'fake-redis-test:hash_*->key')).to eq(['x', 'y'])
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'weights' do
|
43
43
|
it 'weights by projecting through a key pattern' do
|
44
|
-
@client.sort(@key, :by => "fake-redis-test:weight_*").
|
44
|
+
expect(@client.sort(@key, :by => "fake-redis-test:weight_*")).to eq(['2', '1'])
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'weights by projecting through a key pattern and a specific order' do
|
48
|
-
@client.sort(@key, :order => "DESC", :by => "fake-redis-test:weight_*").
|
48
|
+
expect(@client.sort(@key, :order => "DESC", :by => "fake-redis-test:weight_*")).to eq(['1', '2'])
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'limit' do
|
53
53
|
it 'only returns requested window in the enumerable' do
|
54
|
-
@client.sort(@key, :limit => [0, 1]).
|
54
|
+
expect(@client.sort(@key, :limit => [0, 1])).to eq(['1'])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns an empty array if the offset if more than the length of the list' do
|
58
|
+
expect(@client.sort(@key, :limit => [3, 1])).to eq([])
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
62
|
context 'store' do
|
59
63
|
it 'stores into another key' do
|
60
|
-
@client.sort(@key, :store => "fake-redis-test:some_bucket").
|
61
|
-
@client.lrange("fake-redis-test:some_bucket", 0, -1).
|
64
|
+
expect(@client.sort(@key, :store => "fake-redis-test:some_bucket")).to eq(2)
|
65
|
+
expect(@client.lrange("fake-redis-test:some_bucket", 0, -1)).to eq(['1', '2'])
|
62
66
|
end
|
63
67
|
|
64
68
|
it "stores into another key with other options specified" do
|
65
|
-
@client.sort(@key, :store => "fake-redis-test:some_bucket", :by => "fake-redis-test:weight_*").
|
66
|
-
@client.lrange("fake-redis-test:some_bucket", 0, -1).
|
69
|
+
expect(@client.sort(@key, :store => "fake-redis-test:some_bucket", :by => "fake-redis-test:weight_*")).to eq(2)
|
70
|
+
expect(@client.lrange("fake-redis-test:some_bucket", 0, -1)).to eq(['2', '1'])
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
data/spec/transactions_spec.rb
CHANGED
@@ -12,12 +12,12 @@ module FakeRedis
|
|
12
12
|
|
13
13
|
context '#multi' do
|
14
14
|
it "should respond with 'OK'" do
|
15
|
-
@client.multi.
|
15
|
+
expect(@client.multi).to eq('OK')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should forbid nesting" do
|
19
19
|
@client.multi
|
20
|
-
|
20
|
+
expect{@client.multi}.to raise_error(Redis::CommandError)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should mark the start of a transaction block" do
|
@@ -28,24 +28,24 @@ module FakeRedis
|
|
28
28
|
multi.mget("key1", "key2")
|
29
29
|
end
|
30
30
|
|
31
|
-
transaction.
|
31
|
+
expect(transaction).to eq(["OK", "OK", true, ["1", "2"]])
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context '#discard' do
|
36
|
-
it "should
|
36
|
+
it "should respond with 'OK' after #multi" do
|
37
37
|
@client.multi
|
38
|
-
@client.discard.
|
38
|
+
expect(@client.discard).to eq('OK')
|
39
39
|
end
|
40
40
|
|
41
41
|
it "can't be run outside of #multi/#exec" do
|
42
|
-
|
42
|
+
expect{@client.discard}.to raise_error(Redis::CommandError)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context '#exec' do
|
47
47
|
it "can't be run outside of #multi" do
|
48
|
-
|
48
|
+
expect{@client.exec}.to raise_error(Redis::CommandError)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -57,8 +57,8 @@ module FakeRedis
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "makes commands respond with 'QUEUED'" do
|
60
|
-
@client.set(@string, 'string').
|
61
|
-
@client.lpush(@list, 'list').
|
60
|
+
expect(@client.set(@string, 'string')).to eq('QUEUED')
|
61
|
+
expect(@client.lpush(@list, 'list')).to eq('QUEUED')
|
62
62
|
end
|
63
63
|
|
64
64
|
it "gives you the commands' responses when you call #exec" do
|
@@ -66,7 +66,7 @@ module FakeRedis
|
|
66
66
|
@client.lpush(@list, 'list')
|
67
67
|
@client.lpush(@list, 'list')
|
68
68
|
|
69
|
-
@client.exec.
|
69
|
+
expect(@client.exec).to eq(['OK', 1, 2])
|
70
70
|
end
|
71
71
|
|
72
72
|
it "does not raise exceptions, but rather puts them in #exec's response" do
|
@@ -75,9 +75,30 @@ module FakeRedis
|
|
75
75
|
@client.lpush(@list, 'list')
|
76
76
|
|
77
77
|
responses = @client.exec
|
78
|
-
responses[0].
|
79
|
-
responses[1].
|
80
|
-
responses[2].
|
78
|
+
expect(responses[0]).to eq('OK')
|
79
|
+
expect(responses[1]).to be_a(RuntimeError)
|
80
|
+
expect(responses[2]).to eq(1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'executing hash commands in a block' do
|
85
|
+
it "returns true if the nested hash command succeeds" do
|
86
|
+
responses = @client.multi { |multi| multi.hset('hash', 'key', 'value') }
|
87
|
+
|
88
|
+
expect(responses[0]).to eq(true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'executing set commands in a block' do
|
93
|
+
it "returns commands' responses for nested commands" do
|
94
|
+
@client.sadd('set', 'member1')
|
95
|
+
|
96
|
+
responses = @client.multi do |multi|
|
97
|
+
multi.sadd('set', 'member1')
|
98
|
+
multi.sadd('set', 'member2')
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(responses).to eq([false, true])
|
81
102
|
end
|
82
103
|
end
|
83
104
|
end
|
@@ -8,11 +8,11 @@ module FakeRedis
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "#ZCOUNT" do
|
11
|
-
@client.ZCOUNT("key", 2, 3).
|
11
|
+
expect(@client.ZCOUNT("key", 2, 3)).to eq(@client.zcount("key", 2, 3))
|
12
12
|
end
|
13
13
|
|
14
14
|
it "#ZSCORE" do
|
15
|
-
@client.ZSCORE("key", 2).
|
15
|
+
expect(@client.ZSCORE("key", 2)).to eq(@client.zscore("key", 2))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakeredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Iguaran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,8 +55,12 @@ files:
|
|
55
55
|
- fakeredis.gemspec
|
56
56
|
- lib/fake_redis.rb
|
57
57
|
- lib/fakeredis.rb
|
58
|
+
- lib/fakeredis/bitop_command.rb
|
58
59
|
- lib/fakeredis/command_executor.rb
|
59
60
|
- lib/fakeredis/expiring_hash.rb
|
61
|
+
- lib/fakeredis/geo_commands.rb
|
62
|
+
- lib/fakeredis/geo_set.rb
|
63
|
+
- lib/fakeredis/minitest.rb
|
60
64
|
- lib/fakeredis/rspec.rb
|
61
65
|
- lib/fakeredis/sort_method.rb
|
62
66
|
- lib/fakeredis/sorted_set_argument_handler.rb
|
@@ -65,9 +69,14 @@ files:
|
|
65
69
|
- lib/fakeredis/version.rb
|
66
70
|
- lib/fakeredis/zset.rb
|
67
71
|
- lib/redis/connection/memory.rb
|
72
|
+
- spec/bitop_command_spec.rb
|
73
|
+
- spec/command_executor_spec.rb
|
68
74
|
- spec/compatibility_spec.rb
|
69
75
|
- spec/connection_spec.rb
|
76
|
+
- spec/fakeredis_spec.rb
|
77
|
+
- spec/geo_set_spec.rb
|
70
78
|
- spec/hashes_spec.rb
|
79
|
+
- spec/hyper_log_logs_spec.rb
|
71
80
|
- spec/keys_spec.rb
|
72
81
|
- spec/lists_spec.rb
|
73
82
|
- spec/memory_spec.rb
|
@@ -78,6 +87,8 @@ files:
|
|
78
87
|
- spec/spec_helper.rb
|
79
88
|
- spec/spec_helper_live_redis.rb
|
80
89
|
- spec/strings_spec.rb
|
90
|
+
- spec/subscription_spec.rb
|
91
|
+
- spec/support/shared_examples/bitwise_operation.rb
|
81
92
|
- spec/support/shared_examples/sortable.rb
|
82
93
|
- spec/transactions_spec.rb
|
83
94
|
- spec/upcase_method_name_spec.rb
|
@@ -100,15 +111,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
111
|
- !ruby/object:Gem::Version
|
101
112
|
version: '0'
|
102
113
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.2.0
|
114
|
+
rubygems_version: 3.0.3
|
105
115
|
signing_key:
|
106
116
|
specification_version: 4
|
107
117
|
summary: Fake (In-memory) driver for redis-rb.
|
108
118
|
test_files:
|
119
|
+
- spec/bitop_command_spec.rb
|
120
|
+
- spec/command_executor_spec.rb
|
109
121
|
- spec/compatibility_spec.rb
|
110
122
|
- spec/connection_spec.rb
|
123
|
+
- spec/fakeredis_spec.rb
|
124
|
+
- spec/geo_set_spec.rb
|
111
125
|
- spec/hashes_spec.rb
|
126
|
+
- spec/hyper_log_logs_spec.rb
|
112
127
|
- spec/keys_spec.rb
|
113
128
|
- spec/lists_spec.rb
|
114
129
|
- spec/memory_spec.rb
|
@@ -119,6 +134,8 @@ test_files:
|
|
119
134
|
- spec/spec_helper.rb
|
120
135
|
- spec/spec_helper_live_redis.rb
|
121
136
|
- spec/strings_spec.rb
|
137
|
+
- spec/subscription_spec.rb
|
138
|
+
- spec/support/shared_examples/bitwise_operation.rb
|
122
139
|
- spec/support/shared_examples/sortable.rb
|
123
140
|
- spec/transactions_spec.rb
|
124
141
|
- spec/upcase_method_name_spec.rb
|