kuende-fakeredis 0.6.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -2
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/fakeredis.gemspec +1 -2
- data/lib/fakeredis.rb +12 -0
- data/lib/fakeredis/command_executor.rb +6 -3
- data/lib/fakeredis/sort_method.rb +1 -1
- data/lib/fakeredis/sorted_set_store.rb +1 -1
- data/lib/fakeredis/version.rb +1 -1
- data/lib/redis/connection/memory.rb +81 -22
- data/spec/command_executor_spec.rb +15 -0
- data/spec/fakeredis_spec.rb +21 -0
- data/spec/hashes_spec.rb +4 -0
- data/spec/lists_spec.rb +13 -0
- data/spec/memory_spec.rb +79 -6
- data/spec/sets_spec.rb +54 -0
- data/spec/sorted_sets_spec.rb +16 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/spec_helper_live_redis.rb +4 -4
- data/spec/support/shared_examples/sortable.rb +4 -0
- metadata +17 -22
- data/Guardfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc0ed06145e5a35f4b3c3628faa81569bbf46d1
|
4
|
+
data.tar.gz: 6a9a2d56687e918e9bcde704c67ec50afd05bb7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfd38f75adaa13bd05fd1c3870d25c2d59b1077a4c3fd5cb2781a885eec502864d519e416d5c913b7b60b81d0da12d76e3be27933098839454705fb73e1a3896
|
7
|
+
data.tar.gz: f0be187c75bafde58f77705355396c840a7ed9ad82b89b24a1825168ae9f181d9e2f9f31fef0c05d7de243ff2378c517abc15eeec525fec0a3c9dfb93b08246a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
data/fakeredis.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency
|
21
|
+
s.add_runtime_dependency "redis", ">= 3.3.5", "< 5.0"
|
22
22
|
s.add_development_dependency(%q<rspec>, ["~> 3.0"])
|
23
|
-
s.add_development_dependency "guard-rspec"
|
24
23
|
end
|
data/lib/fakeredis.rb
CHANGED
@@ -3,4 +3,16 @@ require 'redis/connection/memory'
|
|
3
3
|
|
4
4
|
module FakeRedis
|
5
5
|
Redis = ::Redis
|
6
|
+
|
7
|
+
def self.enable
|
8
|
+
Redis::Connection.drivers << Redis::Connection::Memory unless enabled?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.enabled?
|
12
|
+
Redis::Connection.drivers.last == Redis::Connection::Memory
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.disable
|
16
|
+
Redis::Connection.drivers.delete_if {|driver| Redis::Connection::Memory == driver }
|
17
|
+
end
|
6
18
|
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module FakeRedis
|
2
2
|
module CommandExecutor
|
3
3
|
def write(command)
|
4
|
-
meffod = command.
|
4
|
+
meffod = command[0].to_s.downcase.to_sym
|
5
|
+
args = command[1..-1]
|
5
6
|
|
6
7
|
if in_multi && !(TRANSACTION_COMMANDS.include? meffod) # queue commands
|
7
|
-
queued_commands << [meffod, *
|
8
|
+
queued_commands << [meffod, *args]
|
8
9
|
reply = 'QUEUED'
|
10
|
+
elsif respond_to?(meffod) && method(meffod).arity.zero?
|
11
|
+
reply = send(meffod)
|
9
12
|
elsif respond_to?(meffod)
|
10
|
-
reply = send(meffod, *
|
13
|
+
reply = send(meffod, *args)
|
11
14
|
else
|
12
15
|
raise Redis::CommandError, "ERR unknown command '#{meffod}'"
|
13
16
|
end
|
data/lib/fakeredis/version.rb
CHANGED
@@ -9,7 +9,6 @@ require "fakeredis/sorted_set_store"
|
|
9
9
|
require "fakeredis/transaction_commands"
|
10
10
|
require "fakeredis/zset"
|
11
11
|
require "fakeredis/bitop_command"
|
12
|
-
require "fakeredis/version"
|
13
12
|
|
14
13
|
class Redis
|
15
14
|
module Connection
|
@@ -90,6 +89,15 @@ class Redis
|
|
90
89
|
def disconnect
|
91
90
|
end
|
92
91
|
|
92
|
+
def client(command, options = {})
|
93
|
+
case command
|
94
|
+
when :setname then true
|
95
|
+
when :getname then nil
|
96
|
+
else
|
97
|
+
raise Redis::CommandError, "ERR unknown command '#{command}'"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
93
101
|
def timeout=(usecs)
|
94
102
|
end
|
95
103
|
|
@@ -347,7 +355,14 @@ class Redis
|
|
347
355
|
|
348
356
|
def lrange(key, startidx, endidx)
|
349
357
|
data_type_check(key, Array)
|
350
|
-
|
358
|
+
if data[key]
|
359
|
+
# In Ruby when negative start index is out of range Array#slice returns
|
360
|
+
# nil which is not the case for lrange in Redis.
|
361
|
+
startidx = 0 if startidx < 0 && startidx.abs > data[key].size
|
362
|
+
data[key][startidx..endidx] || []
|
363
|
+
else
|
364
|
+
[]
|
365
|
+
end
|
351
366
|
end
|
352
367
|
|
353
368
|
def ltrim(key, start, stop)
|
@@ -380,9 +395,9 @@ class Redis
|
|
380
395
|
index = data[key].index(pivot.to_s)
|
381
396
|
return -1 if index.nil?
|
382
397
|
|
383
|
-
case where
|
384
|
-
when
|
385
|
-
when
|
398
|
+
case where.to_s
|
399
|
+
when /\Abefore\z/i then data[key].insert(index, value)
|
400
|
+
when /\Aafter\z/i then data[key].insert(index + 1, value)
|
386
401
|
else raise_syntax_error
|
387
402
|
end
|
388
403
|
end
|
@@ -553,11 +568,14 @@ class Redis
|
|
553
568
|
result
|
554
569
|
end
|
555
570
|
|
556
|
-
def spop(key)
|
571
|
+
def spop(key, count = nil)
|
557
572
|
data_type_check(key, ::Set)
|
558
|
-
|
559
|
-
|
560
|
-
|
573
|
+
results = (count || 1).times.map do
|
574
|
+
elem = srandmember(key)
|
575
|
+
srem(key, elem)
|
576
|
+
elem
|
577
|
+
end.compact
|
578
|
+
count.nil? ? results.first : results
|
561
579
|
end
|
562
580
|
|
563
581
|
def scard(key)
|
@@ -620,6 +638,44 @@ class Redis
|
|
620
638
|
number.nil? ? srandmember_single(key) : srandmember_multiple(key, number)
|
621
639
|
end
|
622
640
|
|
641
|
+
def sscan(key, start_cursor, *args)
|
642
|
+
data_type_check(key, ::Set)
|
643
|
+
return ["0", []] unless data[key]
|
644
|
+
|
645
|
+
match = "*"
|
646
|
+
count = 10
|
647
|
+
|
648
|
+
if args.size.odd?
|
649
|
+
raise_argument_error('sscan')
|
650
|
+
end
|
651
|
+
|
652
|
+
if idx = args.index("MATCH")
|
653
|
+
match = args[idx + 1]
|
654
|
+
end
|
655
|
+
|
656
|
+
if idx = args.index("COUNT")
|
657
|
+
count = args[idx + 1]
|
658
|
+
end
|
659
|
+
|
660
|
+
start_cursor = start_cursor.to_i
|
661
|
+
|
662
|
+
cursor = start_cursor
|
663
|
+
next_keys = []
|
664
|
+
|
665
|
+
if start_cursor + count >= data[key].length
|
666
|
+
next_keys = (data[key].to_a)[start_cursor..-1]
|
667
|
+
cursor = 0
|
668
|
+
else
|
669
|
+
cursor = start_cursor + count
|
670
|
+
next_keys = (data[key].to_a)[start_cursor..cursor-1]
|
671
|
+
end
|
672
|
+
|
673
|
+
filtered_next_keys = next_keys.select{ |k,v| File.fnmatch(match, k)}
|
674
|
+
result = filtered_next_keys.flatten.map(&:to_s)
|
675
|
+
|
676
|
+
return ["#{cursor}", result]
|
677
|
+
end
|
678
|
+
|
623
679
|
def del(*keys)
|
624
680
|
keys = keys.flatten(1)
|
625
681
|
raise_argument_error('del') if keys.empty?
|
@@ -735,6 +791,7 @@ class Redis
|
|
735
791
|
data[key][field[0].to_s] = field[1].to_s
|
736
792
|
end
|
737
793
|
end
|
794
|
+
"OK"
|
738
795
|
end
|
739
796
|
|
740
797
|
def hmget(key, *fields)
|
@@ -914,10 +971,6 @@ class Redis
|
|
914
971
|
match = "*"
|
915
972
|
count = 10
|
916
973
|
|
917
|
-
if args.size.odd?
|
918
|
-
raise_argument_error('scan')
|
919
|
-
end
|
920
|
-
|
921
974
|
if idx = args.index("MATCH")
|
922
975
|
match = args[idx + 1]
|
923
976
|
end
|
@@ -927,20 +980,25 @@ class Redis
|
|
927
980
|
end
|
928
981
|
|
929
982
|
start_cursor = start_cursor.to_i
|
930
|
-
data_type_check(start_cursor,
|
983
|
+
data_type_check(start_cursor, Integer)
|
931
984
|
|
932
985
|
cursor = start_cursor
|
933
|
-
|
986
|
+
returned_keys = []
|
987
|
+
final_page = start_cursor + count >= keys(match).length
|
988
|
+
|
989
|
+
if final_page
|
990
|
+
previous_keys_been_deleted = (count >= keys(match).length)
|
991
|
+
start_index = previous_keys_been_deleted ? 0 : cursor
|
934
992
|
|
935
|
-
|
936
|
-
next_keys = keys(match)[start_cursor..-1]
|
993
|
+
returned_keys = keys(match)[start_index..-1]
|
937
994
|
cursor = 0
|
938
995
|
else
|
939
|
-
|
940
|
-
|
996
|
+
end_index = start_cursor + (count - 1)
|
997
|
+
returned_keys = keys(match)[start_cursor..end_index]
|
998
|
+
cursor = start_cursor + count
|
941
999
|
end
|
942
1000
|
|
943
|
-
return "#{cursor}",
|
1001
|
+
return "#{cursor}", returned_keys
|
944
1002
|
end
|
945
1003
|
|
946
1004
|
def zadd(key, *args)
|
@@ -1032,7 +1090,7 @@ class Redis
|
|
1032
1090
|
results = sort_keys(data[key])
|
1033
1091
|
# Select just the keys unless we want scores
|
1034
1092
|
results = results.map(&:first) unless with_scores
|
1035
|
-
results[start..stop].flatten.map(&:to_s)
|
1093
|
+
(results[start..stop] || []).flatten.map(&:to_s)
|
1036
1094
|
end
|
1037
1095
|
|
1038
1096
|
def zrangebylex(key, start, stop, *opts)
|
@@ -1241,7 +1299,7 @@ class Redis
|
|
1241
1299
|
end
|
1242
1300
|
|
1243
1301
|
start_cursor = start_cursor.to_i
|
1244
|
-
data_type_check(start_cursor,
|
1302
|
+
data_type_check(start_cursor, Integer)
|
1245
1303
|
|
1246
1304
|
cursor = start_cursor
|
1247
1305
|
next_keys = []
|
@@ -1372,4 +1430,5 @@ class Redis
|
|
1372
1430
|
end
|
1373
1431
|
end
|
1374
1432
|
|
1433
|
+
# FIXME this line should be deleted as explicit enabling is better
|
1375
1434
|
Redis::Connection.drivers << Redis::Connection::Memory
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe FakeRedis::CommandExecutor do
|
4
|
+
|
5
|
+
let(:redis) { Redis.new }
|
6
|
+
|
7
|
+
context '#write' do
|
8
|
+
it 'does not modify its argument' do
|
9
|
+
command = [:get, 'key']
|
10
|
+
redis.write(command)
|
11
|
+
expect(command).to eql([:get, 'key'])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FakeRedis do
|
4
|
+
after { described_class.disable }
|
5
|
+
|
6
|
+
describe '.enable' do
|
7
|
+
it 'in memory connection' do
|
8
|
+
described_class.enable
|
9
|
+
expect(described_class.enabled?).to be_truthy
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.disable' do
|
14
|
+
before { described_class.enable }
|
15
|
+
|
16
|
+
it 'in memory connection' do
|
17
|
+
described_class.disable
|
18
|
+
expect(described_class.enabled?).to be_falsy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/hashes_spec.rb
CHANGED
@@ -137,6 +137,10 @@ module FakeRedis
|
|
137
137
|
expect { @client.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3") }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET")
|
138
138
|
end
|
139
139
|
|
140
|
+
it "should return OK on success" do
|
141
|
+
expect(@client.hmset("key", "k1", "value1")).to eq("OK")
|
142
|
+
end
|
143
|
+
|
140
144
|
it "should set multiple hash fields to multiple values" do
|
141
145
|
@client.hmset("key", "k1", "value1", "k2", "value2")
|
142
146
|
|
data/spec/lists_spec.rb
CHANGED
@@ -25,6 +25,18 @@ module FakeRedis
|
|
25
25
|
expect(@client.lrange("key1", 0, -1)).to eq(["v1", "v2", "v3", "99", "100"])
|
26
26
|
end
|
27
27
|
|
28
|
+
it "inserts with case-insensitive position token" do
|
29
|
+
@client.rpush("key1", "v1")
|
30
|
+
@client.rpush("key1", "v4")
|
31
|
+
|
32
|
+
@client.linsert("key1", :BEFORE, "v4", "v2")
|
33
|
+
@client.linsert("key1", "Before", "v4", "v3")
|
34
|
+
@client.linsert("key1", :AFTER, "v4", "v5")
|
35
|
+
@client.linsert("key1", "After", "v5", "v6")
|
36
|
+
|
37
|
+
expect(@client.lrange("key1", 0, -1)).to eq(%w(v1 v2 v3 v4 v5 v6))
|
38
|
+
end
|
39
|
+
|
28
40
|
it "should not insert if after/before index not found" do
|
29
41
|
@client.rpush("key", "v1")
|
30
42
|
expect(@client.linsert("key", :before, "unknown", "v2")).to eq(-1)
|
@@ -89,6 +101,7 @@ module FakeRedis
|
|
89
101
|
@client.rpush("key1", "v3")
|
90
102
|
|
91
103
|
expect(@client.lrange("key1", 1, -1)).to eq(["v2", "v3"])
|
104
|
+
expect(@client.lrange("key1", -999, -1)).to eq(["v1", "v2", "v3"])
|
92
105
|
end
|
93
106
|
|
94
107
|
it "should remove elements from a list" do
|
data/spec/memory_spec.rb
CHANGED
@@ -1,28 +1,101 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec.describe FakeRedis do
|
4
|
+
let(:redis) { Redis.new }
|
5
|
+
|
6
|
+
def populate_keys_in_redis(num)
|
7
|
+
num.times do |count|
|
8
|
+
redis.set("key#{count}", count)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#write' do
|
13
|
+
it 'should not send unexpected arguments' do
|
14
|
+
expect { redis.write(['info', 'server']) }.not_to raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#scan' do
|
19
|
+
def result
|
20
|
+
returned_keys = []
|
21
|
+
cursor = 0
|
22
|
+
|
23
|
+
loop do
|
24
|
+
cursor, keys = redis.scan(cursor, match_arguments)
|
25
|
+
returned_keys += keys
|
26
|
+
break if cursor == '0'
|
27
|
+
end
|
28
|
+
returned_keys
|
29
|
+
end
|
30
|
+
|
31
|
+
before do
|
32
|
+
populate_keys_in_redis(11)
|
33
|
+
end
|
34
|
+
|
35
|
+
context('when deleting') do
|
36
|
+
it('preverves cursor') do
|
37
|
+
cursor, keys = redis.scan('0')
|
38
|
+
keys.each { |key| redis.del(key) }
|
39
|
+
_, keys = redis.scan(cursor)
|
40
|
+
expect(keys).to eq(%w(key10))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with one namespace' do
|
45
|
+
let(:match_arguments) { {} }
|
46
|
+
|
47
|
+
it 'returns the expected array of keys' do
|
48
|
+
expect(result).to match_array(redis.keys)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with multiple namespaces' do
|
53
|
+
let(:namespaced_key) { 'test' }
|
54
|
+
let(:match_arguments) { { match: namespaced_key } }
|
55
|
+
|
56
|
+
before { redis.set(namespaced_key, 12) }
|
57
|
+
|
58
|
+
it 'returns the expected array of keys' do
|
59
|
+
expect(result).to match_array([namespaced_key])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
4
64
|
describe 'time' do
|
5
65
|
before(:each) do
|
6
|
-
@client = Redis.new
|
7
66
|
allow(Time).to receive_message_chain(:now, :to_f).and_return(1397845595.5139461)
|
8
67
|
end
|
9
68
|
|
10
69
|
it 'is an array' do
|
11
|
-
expect(
|
70
|
+
expect(redis.time).to be_an_instance_of(Array)
|
12
71
|
end
|
13
72
|
|
14
73
|
it 'has two elements' do
|
15
|
-
expect(
|
74
|
+
expect(redis.time.count).to eql 2
|
16
75
|
end
|
17
76
|
|
18
77
|
if fakeredis?
|
19
78
|
it 'has the current time in seconds' do
|
20
|
-
expect(
|
79
|
+
expect(redis.time.first).to eql 1397845595
|
21
80
|
end
|
22
81
|
|
23
82
|
it 'has the current leftover microseconds' do
|
24
|
-
expect(
|
83
|
+
expect(redis.time.last).to eql 513946
|
25
84
|
end
|
26
85
|
end
|
27
86
|
end
|
87
|
+
|
88
|
+
describe '#client' do
|
89
|
+
it 'returns 1 when command is :setname' do
|
90
|
+
expect(redis.write([:client, :setname])).to eq 1
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns nil when command is :getname' do
|
94
|
+
expect(redis.write([:client, :getname])).to eq nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'raises error for other commands' do
|
98
|
+
expect { redis.write([:client, :wrong]) }.to raise_error(Redis::CommandError, "ERR unknown command 'wrong'")
|
99
|
+
end
|
100
|
+
end
|
28
101
|
end
|
data/spec/sets_spec.rb
CHANGED
@@ -148,6 +148,22 @@ module FakeRedis
|
|
148
148
|
expect(["a", "b"].include?(@client.spop("key1"))).to be true
|
149
149
|
end
|
150
150
|
|
151
|
+
it "should pop multiple members from a set" do
|
152
|
+
@client.sadd("key1", "a")
|
153
|
+
@client.sadd("key1", "b")
|
154
|
+
@client.sadd("key1", "c")
|
155
|
+
|
156
|
+
vals = @client.spop("key1", 2)
|
157
|
+
expect(vals.count).to eq(2)
|
158
|
+
vals.each { |v| expect(["a", "b", "c"].include?(v)).to be true }
|
159
|
+
|
160
|
+
new_vals = @client.spop("key1", 2)
|
161
|
+
expect(new_vals.count).to eq(1)
|
162
|
+
expect(["a", "b", "c"].include?(new_vals.first)).to be true
|
163
|
+
|
164
|
+
expect(["a", "b", "c"]).to eq((vals + new_vals).sort)
|
165
|
+
end
|
166
|
+
|
151
167
|
it "should remove a member from a set" do
|
152
168
|
@client.sadd("key1", "a")
|
153
169
|
@client.sadd("key1", "b")
|
@@ -276,5 +292,43 @@ module FakeRedis
|
|
276
292
|
expect(@client.srandmember("key1", 1)).to eq([])
|
277
293
|
end
|
278
294
|
end
|
295
|
+
|
296
|
+
describe "#sscan" do
|
297
|
+
it 'with no arguments and few items, returns all items' do
|
298
|
+
@client.sadd('set', ['name', 'Jack', 'age', '33'])
|
299
|
+
result = @client.sscan('set', 0)
|
300
|
+
|
301
|
+
expect(result[0]).to eq('0')
|
302
|
+
expect(result[1]).to eq(['name', 'Jack', 'age', '33'])
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'with a count should return that number of members or more' do
|
306
|
+
@client.sadd('set', ['a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'])
|
307
|
+
result = @client.sscan('set', 0, count: 3)
|
308
|
+
expect(result[0]).to eq('3')
|
309
|
+
expect(result[1]).to eq([ 'a', '1', 'b'])
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'returns items starting at the provided cursor' do
|
313
|
+
@client.sadd('set', ['a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'])
|
314
|
+
result = @client.sscan('set', 2, count: 3)
|
315
|
+
expect(result[0]).to eq('5')
|
316
|
+
expect(result[1]).to eq(['b', '2', 'c'])
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'with match, returns items matching the given pattern' do
|
320
|
+
@client.sadd('set', ['aa', '1', 'b', '2', 'cc', '3', 'd', '4', 'ee', '5', 'f', '6', 'gg', '7'])
|
321
|
+
result = @client.sscan('set', 2, count: 7, match: '??')
|
322
|
+
expect(result[0]).to eq('9')
|
323
|
+
expect(result[1]).to eq(['cc','ee'])
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'returns an empty result if the key is not found' do
|
327
|
+
result = @client.sscan('set', 0)
|
328
|
+
|
329
|
+
expect(result[0]).to eq('0')
|
330
|
+
expect(result[1]).to eq([])
|
331
|
+
end
|
332
|
+
end
|
279
333
|
end
|
280
334
|
end
|
data/spec/sorted_sets_spec.rb
CHANGED
@@ -306,6 +306,22 @@ module FakeRedis
|
|
306
306
|
it "should error with an invalid aggregate" do
|
307
307
|
expect { @client.zinterstore("out", %w(key1 key2), :aggregate => :invalid) }.to raise_error(Redis::CommandError, "ERR syntax error")
|
308
308
|
end
|
309
|
+
|
310
|
+
it 'stores nothing when there are no members in common' do
|
311
|
+
@client.zadd("k1", 1, "1")
|
312
|
+
@client.zadd("k1", 1, "2")
|
313
|
+
@client.sadd("k2", "a")
|
314
|
+
@client.sadd("k3", "b")
|
315
|
+
|
316
|
+
expect(@client.zinterstore("out", %w(k1 k2 k3))).to eq(0)
|
317
|
+
expect(@client.zrange("out", 0, -1)).to eq([])
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'handles range start being higher than number of members' do
|
321
|
+
@client.zadd("key", 1, "1")
|
322
|
+
|
323
|
+
expect(@client.zrange("key", 10, 10)).to eq([])
|
324
|
+
end
|
309
325
|
end
|
310
326
|
|
311
327
|
context "zremrangebyscore" do
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,11 @@ require "fakeredis/rspec"
|
|
7
7
|
require "support/shared_examples/sortable"
|
8
8
|
require "support/shared_examples/bitwise_operation"
|
9
9
|
|
10
|
+
|
10
11
|
RSpec.configure do |config|
|
12
|
+
# Enable memory adapter
|
13
|
+
config.before(:each) { FakeRedis.enable }
|
14
|
+
|
11
15
|
# replaces -b -fdoc --color in .rspec
|
12
16
|
config.color = true
|
13
17
|
config.default_formatter = "doc"
|
@@ -25,5 +29,5 @@ RSpec.configure do |config|
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def fakeredis?
|
28
|
-
|
32
|
+
FakeRedis.enabled?
|
29
33
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
# Remove memory so we test against actual redis
|
4
|
-
Redis::Connection.drivers.pop
|
5
|
-
|
6
3
|
RSpec.configure do |config|
|
7
4
|
config.before(:each) do
|
5
|
+
# Disable so we test against actual redis
|
6
|
+
FakeRedis.disable
|
7
|
+
|
8
8
|
Redis.new.flushall
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def fakeredis?
|
13
|
-
|
13
|
+
FakeRedis.enabled?
|
14
14
|
end
|
@@ -53,6 +53,10 @@ shared_examples_for "a sortable" do
|
|
53
53
|
it 'only returns requested window in the enumerable' do
|
54
54
|
expect(@client.sort(@key, :limit => [0, 1])).to eq(['1'])
|
55
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([])
|
59
|
+
end
|
56
60
|
end
|
57
61
|
|
58
62
|
context 'store' do
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuende-fakeredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.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: 2017-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.3.5
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 3.3.5
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +44,6 @@ dependencies:
|
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '3.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: guard-rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
47
|
description: Fake (In-memory) driver for redis-rb. Useful for testing environment
|
56
48
|
and machines without Redis.
|
57
49
|
email:
|
@@ -63,7 +55,6 @@ files:
|
|
63
55
|
- ".gitignore"
|
64
56
|
- ".travis.yml"
|
65
57
|
- Gemfile
|
66
|
-
- Guardfile
|
67
58
|
- LICENSE
|
68
59
|
- README.md
|
69
60
|
- Rakefile
|
@@ -84,8 +75,10 @@ files:
|
|
84
75
|
- lib/fakeredis/zset.rb
|
85
76
|
- lib/redis/connection/memory.rb
|
86
77
|
- spec/bitop_command_spec.rb
|
78
|
+
- spec/command_executor_spec.rb
|
87
79
|
- spec/compatibility_spec.rb
|
88
80
|
- spec/connection_spec.rb
|
81
|
+
- spec/fakeredis_spec.rb
|
89
82
|
- spec/hashes_spec.rb
|
90
83
|
- spec/keys_spec.rb
|
91
84
|
- spec/lists_spec.rb
|
@@ -122,14 +115,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
115
|
version: '0'
|
123
116
|
requirements: []
|
124
117
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.5.2
|
126
119
|
signing_key:
|
127
120
|
specification_version: 4
|
128
121
|
summary: Fake (In-memory) driver for redis-rb.
|
129
122
|
test_files:
|
130
123
|
- spec/bitop_command_spec.rb
|
124
|
+
- spec/command_executor_spec.rb
|
131
125
|
- spec/compatibility_spec.rb
|
132
126
|
- spec/connection_spec.rb
|
127
|
+
- spec/fakeredis_spec.rb
|
133
128
|
- spec/hashes_spec.rb
|
134
129
|
- spec/keys_spec.rb
|
135
130
|
- spec/lists_spec.rb
|
data/Guardfile
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
ignore([%r{^bin/*}, %r{^lib/*}, %r{^tmp/*}])
|
2
|
-
|
3
|
-
guard 'rspec', cmd: 'bundle exec rspec', all_after_pass: false, all_on_start: false do
|
4
|
-
watch(%r{^spec/.+_spec\.rb$})
|
5
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
6
|
-
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
7
|
-
watch('spec/spec_helper.rb') { "spec" }
|
8
|
-
end
|