fakeredis 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/lib/fakeredis/version.rb +1 -1
- data/lib/redis/connection/memory.rb +79 -25
- data/spec/hashes_spec.rb +25 -0
- data/spec/keys_spec.rb +33 -8
- data/spec/lists_spec.rb +33 -0
- data/spec/sets_spec.rb +14 -0
- data/spec/sorted_sets_spec.rb +20 -2
- data/spec/strings_spec.rb +9 -0
- data/spec/upcase_method_name_spec.rb +18 -0
- metadata +11 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88195a8e3e41a553347ff30096fac78a8dcec153
|
4
|
+
data.tar.gz: 3ea4aa2ec9ec9857486a503ef8032b2f22562a60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28fd4cbbe0ec660365112a7b7485c950771a4c8d75c933d0d55afdb3cfbdabdd1fdeba98d687e9050b01fdf2e52e07278b8497a8d0e03ac97f974c0211afaa72
|
7
|
+
data.tar.gz: 0c5c519761c03545a014d0822c3c4a32d63ea6ae3bd96f7c7b6e433dd5acf646dec8b195b5675838cd56e3ac6e5320164654318724e8c3e57ee8f53e32a408cd
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/fakeredis/version.rb
CHANGED
@@ -77,7 +77,7 @@ class Redis
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def write(command)
|
80
|
-
meffod = command.shift
|
80
|
+
meffod = command.shift.to_s.downcase.to_sym
|
81
81
|
if respond_to?(meffod)
|
82
82
|
reply = send(meffod, *command)
|
83
83
|
else
|
@@ -131,7 +131,7 @@ class Redis
|
|
131
131
|
|
132
132
|
def info
|
133
133
|
{
|
134
|
-
"redis_version" => "
|
134
|
+
"redis_version" => "2.6.16",
|
135
135
|
"connected_clients" => "1",
|
136
136
|
"connected_slaves" => "0",
|
137
137
|
"used_memory" => "3187",
|
@@ -185,7 +185,7 @@ class Redis
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def mget(*keys)
|
188
|
-
|
188
|
+
raise_argument_error('mget') if keys.empty?
|
189
189
|
# We work with either an array, or list of arguments
|
190
190
|
keys = keys.first if keys.size == 1
|
191
191
|
data.values_at(*keys)
|
@@ -212,6 +212,7 @@ class Redis
|
|
212
212
|
end
|
213
213
|
|
214
214
|
def hdel(key, field)
|
215
|
+
field = field.to_s
|
215
216
|
data_type_check(key, Hash)
|
216
217
|
data[key] && data[key].delete(field)
|
217
218
|
remove_key_for_empty_collection(key)
|
@@ -224,8 +225,7 @@ class Redis
|
|
224
225
|
end
|
225
226
|
|
226
227
|
def keys(pattern = "*")
|
227
|
-
|
228
|
-
data.keys.select { |key| key =~ regexp }
|
228
|
+
data.keys.select { |key| File.fnmatch(pattern, key) }
|
229
229
|
end
|
230
230
|
|
231
231
|
def randomkey
|
@@ -266,7 +266,18 @@ class Redis
|
|
266
266
|
def ltrim(key, start, stop)
|
267
267
|
data_type_check(key, Array)
|
268
268
|
return unless data[key]
|
269
|
-
|
269
|
+
|
270
|
+
if start < 0 && data[key].count < start.abs
|
271
|
+
# Example: we have a list of 3 elements and
|
272
|
+
# we give it a ltrim list, -5, -1. This means
|
273
|
+
# it should trim to a max of 5. Since 3 < 5
|
274
|
+
# we should not touch the list. This is consistent
|
275
|
+
# with behavior of real Redis's ltrim with a negative
|
276
|
+
# start argument.
|
277
|
+
data[key]
|
278
|
+
else
|
279
|
+
data[key] = data[key][start..stop]
|
280
|
+
end
|
270
281
|
end
|
271
282
|
|
272
283
|
def lindex(key, index)
|
@@ -281,14 +292,14 @@ class Redis
|
|
281
292
|
case where
|
282
293
|
when :before then data[key].insert(index, value)
|
283
294
|
when :after then data[key].insert(index + 1, value)
|
284
|
-
else
|
295
|
+
else raise_syntax_error
|
285
296
|
end
|
286
297
|
end
|
287
298
|
|
288
299
|
def lset(key, index, value)
|
289
300
|
data_type_check(key, Array)
|
290
301
|
return unless data[key]
|
291
|
-
raise
|
302
|
+
raise Redis::CommandError, "ERR index out of range" if index >= data[key].size
|
292
303
|
data[key][index] = value
|
293
304
|
end
|
294
305
|
|
@@ -374,6 +385,7 @@ class Redis
|
|
374
385
|
def sadd(key, value)
|
375
386
|
data_type_check(key, ::Set)
|
376
387
|
value = Array(value)
|
388
|
+
raise_argument_error('sadd') if value.empty?
|
377
389
|
|
378
390
|
result = if data[key]
|
379
391
|
old_set = data[key].dup
|
@@ -417,6 +429,8 @@ class Redis
|
|
417
429
|
end
|
418
430
|
|
419
431
|
def sinter(*keys)
|
432
|
+
raise_argument_error('sinter') if keys.empty?
|
433
|
+
|
420
434
|
keys.each { |k| data_type_check(k, ::Set) }
|
421
435
|
return ::Set.new if keys.any? { |k| data[k].nil? }
|
422
436
|
keys = keys.map { |k| data[k] || ::Set.new }
|
@@ -448,7 +462,7 @@ class Redis
|
|
448
462
|
def sdiff(key1, *keys)
|
449
463
|
[key1, *keys].each { |k| data_type_check(k, ::Set) }
|
450
464
|
keys = keys.map { |k| data[k] || ::Set.new }
|
451
|
-
keys.inject(data[key1]) do |memo, set|
|
465
|
+
keys.inject(data[key1] || Set.new) do |memo, set|
|
452
466
|
memo - set
|
453
467
|
end.to_a
|
454
468
|
end
|
@@ -467,7 +481,8 @@ class Redis
|
|
467
481
|
|
468
482
|
def del(*keys)
|
469
483
|
keys = keys.flatten(1)
|
470
|
-
|
484
|
+
raise_argument_error('del') if keys.empty?
|
485
|
+
|
471
486
|
old_count = data.keys.size
|
472
487
|
keys.each do |key|
|
473
488
|
data.delete(key)
|
@@ -510,7 +525,7 @@ class Redis
|
|
510
525
|
if data.expires.include?(key) && (ttl = data.expires[key].to_i - Time.now.to_i) > 0
|
511
526
|
ttl
|
512
527
|
else
|
513
|
-
-1
|
528
|
+
exists(key) ? -1 : -2
|
514
529
|
end
|
515
530
|
end
|
516
531
|
|
@@ -546,16 +561,30 @@ class Redis
|
|
546
561
|
def hmset(key, *fields)
|
547
562
|
# mapped_hmset gives us [[:k1, "v1", :k2, "v2"]] for `fields`. Fix that.
|
548
563
|
fields = fields[0] if mapped_param?(fields)
|
549
|
-
|
564
|
+
raise_argument_error('hmset') if fields.empty?
|
565
|
+
|
566
|
+
is_list_of_arrays = fields.all?{|field| field.instance_of?(Array)}
|
567
|
+
|
568
|
+
raise_argument_error('hmset') if fields.size.odd? and !is_list_of_arrays
|
569
|
+
raise_argument_error('hmset') if is_list_of_arrays and !fields.all?{|field| field.length == 2}
|
570
|
+
|
550
571
|
data_type_check(key, Hash)
|
551
572
|
data[key] ||= {}
|
552
|
-
|
553
|
-
|
573
|
+
|
574
|
+
if is_list_of_arrays
|
575
|
+
fields.each do |pair|
|
576
|
+
data[key][pair[0].to_s] = pair[1].to_s
|
577
|
+
end
|
578
|
+
else
|
579
|
+
fields.each_slice(2) do |field|
|
580
|
+
data[key][field[0].to_s] = field[1].to_s
|
581
|
+
end
|
554
582
|
end
|
555
583
|
end
|
556
584
|
|
557
585
|
def hmget(key, *fields)
|
558
|
-
|
586
|
+
raise_argument_error('hmget') if fields.empty?
|
587
|
+
|
559
588
|
data_type_check(key, Hash)
|
560
589
|
fields.map do |field|
|
561
590
|
field = field.to_s
|
@@ -581,8 +610,9 @@ class Redis
|
|
581
610
|
|
582
611
|
def hincrby(key, field, increment)
|
583
612
|
data_type_check(key, Hash)
|
613
|
+
field = field.to_s
|
584
614
|
if data[key]
|
585
|
-
data[key][field] = (data[key][field
|
615
|
+
data[key][field] = (data[key][field].to_i + increment.to_i).to_s
|
586
616
|
else
|
587
617
|
data[key] = { field => increment.to_s }
|
588
618
|
end
|
@@ -592,7 +622,7 @@ class Redis
|
|
592
622
|
def hexists(key, field)
|
593
623
|
data_type_check(key, Hash)
|
594
624
|
return false unless data[key]
|
595
|
-
data[key].key?(field)
|
625
|
+
data[key].key?(field.to_s)
|
596
626
|
end
|
597
627
|
|
598
628
|
def sync ; end
|
@@ -625,6 +655,7 @@ class Redis
|
|
625
655
|
def setex(key, seconds, value)
|
626
656
|
data[key] = value.to_s
|
627
657
|
expire(key, seconds)
|
658
|
+
"OK"
|
628
659
|
end
|
629
660
|
|
630
661
|
def setrange(key, offset, value)
|
@@ -636,6 +667,10 @@ class Redis
|
|
636
667
|
def mset(*pairs)
|
637
668
|
# Handle pairs for mapped_mset command
|
638
669
|
pairs = pairs[0] if mapped_param?(pairs)
|
670
|
+
raise_argument_error('mset') if pairs.empty? || pairs.size == 1
|
671
|
+
# We have to reply with a different error message here to be consistent with redis-rb 3.0.6 / redis-server 2.8.1
|
672
|
+
raise_argument_error("mset", "mset_odd") if pairs.size.odd?
|
673
|
+
|
639
674
|
pairs.each_slice(2) do |pair|
|
640
675
|
data[pair[0].to_s] = pair[1].to_s
|
641
676
|
end
|
@@ -680,6 +715,7 @@ class Redis
|
|
680
715
|
case data[key]
|
681
716
|
when nil then "none"
|
682
717
|
when String then "string"
|
718
|
+
when ZSet then "zset"
|
683
719
|
when Hash then "hash"
|
684
720
|
when Array then "list"
|
685
721
|
when ::Set then "set"
|
@@ -713,20 +749,20 @@ class Redis
|
|
713
749
|
def zadd(key, *args)
|
714
750
|
if !args.first.is_a?(Array)
|
715
751
|
if args.size < 2
|
716
|
-
|
752
|
+
raise_argument_error('zadd')
|
717
753
|
elsif args.size.odd?
|
718
|
-
|
754
|
+
raise_syntax_error
|
719
755
|
end
|
720
756
|
else
|
721
757
|
unless args.all? {|pair| pair.size == 2 }
|
722
|
-
|
758
|
+
raise_syntax_error
|
723
759
|
end
|
724
760
|
end
|
725
761
|
|
726
762
|
data_type_check(key, ZSet)
|
727
763
|
data[key] ||= ZSet.new
|
728
764
|
|
729
|
-
if args.size == 2
|
765
|
+
if args.size == 2 && !(Array === args.first)
|
730
766
|
score, value = args
|
731
767
|
exists = !data[key].key?(value.to_s)
|
732
768
|
data[key][value.to_s] = score
|
@@ -746,7 +782,7 @@ class Redis
|
|
746
782
|
return 0 unless data[key]
|
747
783
|
|
748
784
|
response = values.map do |v|
|
749
|
-
data[key].delete(v) if data[key].has_key?(v)
|
785
|
+
data[key].delete(v.to_s) if data[key].has_key?(v.to_s)
|
750
786
|
end.compact.size
|
751
787
|
|
752
788
|
remove_key_for_empty_collection(key)
|
@@ -780,12 +816,16 @@ class Redis
|
|
780
816
|
|
781
817
|
def zrank(key, value)
|
782
818
|
data_type_check(key, ZSet)
|
783
|
-
|
819
|
+
z = data[key]
|
820
|
+
return unless z
|
821
|
+
z.keys.sort_by {|k| z[k] }.index(value.to_s)
|
784
822
|
end
|
785
823
|
|
786
824
|
def zrevrank(key, value)
|
787
825
|
data_type_check(key, ZSet)
|
788
|
-
|
826
|
+
z = data[key]
|
827
|
+
return unless z
|
828
|
+
z.keys.sort_by {|k| -z[k] }.index(value.to_s)
|
789
829
|
end
|
790
830
|
|
791
831
|
def zrange(key, start, stop, with_scores = nil)
|
@@ -834,6 +874,7 @@ class Redis
|
|
834
874
|
end
|
835
875
|
|
836
876
|
def zrevrangebyscore(key, max, min, *opts)
|
877
|
+
opts = opts.flatten
|
837
878
|
data_type_check(key, ZSet)
|
838
879
|
return [] unless data[key]
|
839
880
|
|
@@ -882,6 +923,19 @@ class Redis
|
|
882
923
|
end
|
883
924
|
|
884
925
|
private
|
926
|
+
def raise_argument_error(command, match_string=command)
|
927
|
+
error_message = if %w(hmset mset_odd).include?(match_string.downcase)
|
928
|
+
"ERR wrong number of arguments for #{command.upcase}"
|
929
|
+
else
|
930
|
+
"ERR wrong number of arguments for '#{command}' command"
|
931
|
+
end
|
932
|
+
|
933
|
+
raise Redis::CommandError, error_message
|
934
|
+
end
|
935
|
+
|
936
|
+
def raise_syntax_error
|
937
|
+
raise Redis::CommandError, "ERR syntax error"
|
938
|
+
end
|
885
939
|
|
886
940
|
def remove_key_for_empty_collection(key)
|
887
941
|
del(key) if data[key] && data[key].empty?
|
@@ -890,7 +944,7 @@ class Redis
|
|
890
944
|
def data_type_check(key, klass)
|
891
945
|
if data[key] && !data[key].is_a?(klass)
|
892
946
|
warn "Operation against a key holding the wrong kind of value: Expected #{klass} at #{key}."
|
893
|
-
raise Redis::CommandError.new("
|
947
|
+
raise Redis::CommandError.new("WRONGTYPE Operation against a key holding the wrong kind of value")
|
894
948
|
end
|
895
949
|
end
|
896
950
|
|
data/spec/hashes_spec.rb
CHANGED
@@ -153,5 +153,30 @@ module FakeRedis
|
|
153
153
|
@client.hvals("key1").should =~ ["val1", "val2"]
|
154
154
|
end
|
155
155
|
|
156
|
+
it "should accept a list of array pairs as arguments and not throw an invalid argument number error" do
|
157
|
+
@client.hmset("key1", [:k1, "val1"], [:k2, "val2"], [:k3, "val3"])
|
158
|
+
@client.hget("key1", :k1).should be == "val1"
|
159
|
+
@client.hget("key1", :k2).should be == "val2"
|
160
|
+
@client.hget("key1", :k3).should be == "val3"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should reject a list of arrays that contain an invalid number of arguments" do
|
164
|
+
expect { @client.hmset("key1", [:k1, "val1"], [:k2, "val2", "bogus val"]) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should convert a integer field name to string for hdel" do
|
168
|
+
@client.hset("key1", "1", 1)
|
169
|
+
@client.hdel("key1", 1).should be(1)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should convert a integer field name to string for hexists" do
|
173
|
+
@client.hset("key1", "1", 1)
|
174
|
+
@client.hexists("key1", 1).should be_true
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should convert a integer field name to string for hincrby" do
|
178
|
+
@client.hset("key1", 1, 0)
|
179
|
+
@client.hincrby("key1", 1, 1).should be(1)
|
180
|
+
end
|
156
181
|
end
|
157
182
|
end
|
data/spec/keys_spec.rb
CHANGED
@@ -58,11 +58,11 @@ module FakeRedis
|
|
58
58
|
@client.ttl("key1").should be == -1
|
59
59
|
end
|
60
60
|
|
61
|
-
it "should not have a ttl if expired" do
|
61
|
+
it "should not have a ttl if expired (and thus key does not exist)" do
|
62
62
|
@client.set("key1", "1")
|
63
63
|
@client.expireat("key1", Time.now.to_i)
|
64
64
|
|
65
|
-
@client.ttl("key1").should be == -
|
65
|
+
@client.ttl("key1").should be == -2
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should not find a key if expired" do
|
@@ -102,7 +102,10 @@ module FakeRedis
|
|
102
102
|
@client.set("akeyd", "4")
|
103
103
|
@client.set("key1", "5")
|
104
104
|
|
105
|
+
@client.mset("database", 1, "above", 2, "suitability", 3, "able", 4)
|
106
|
+
|
105
107
|
@client.keys("key:*").should =~ ["key:a", "key:b", "key:c"]
|
108
|
+
@client.keys("ab*").should =~ ["above", "able"]
|
106
109
|
end
|
107
110
|
|
108
111
|
it "should remove the expiration from a key" do
|
@@ -147,10 +150,28 @@ module FakeRedis
|
|
147
150
|
end
|
148
151
|
|
149
152
|
it "should determine the type stored at key" do
|
150
|
-
|
153
|
+
# Non-existing key
|
154
|
+
@client.type("key0").should be == "none"
|
151
155
|
|
156
|
+
# String
|
157
|
+
@client.set("key1", "1")
|
152
158
|
@client.type("key1").should be == "string"
|
153
|
-
|
159
|
+
|
160
|
+
# List
|
161
|
+
@client.lpush("key2", "1")
|
162
|
+
@client.type("key2").should be == "list"
|
163
|
+
|
164
|
+
# Set
|
165
|
+
@client.sadd("key3", "1")
|
166
|
+
@client.type("key3").should be == "set"
|
167
|
+
|
168
|
+
# Sorted Set
|
169
|
+
@client.zadd("key4", 1.0, "1")
|
170
|
+
@client.type("key4").should be == "zset"
|
171
|
+
|
172
|
+
# Hash
|
173
|
+
@client.hset("key5", "a", "1")
|
174
|
+
@client.type("key5").should be == "hash"
|
154
175
|
end
|
155
176
|
|
156
177
|
it "should convert the value into a string before storing" do
|
@@ -164,6 +185,10 @@ module FakeRedis
|
|
164
185
|
@client.get("key3").should be == "1"
|
165
186
|
end
|
166
187
|
|
188
|
+
it "should return 'OK' for the setex command" do
|
189
|
+
@client.setex("key4", 30, 1).should be == "OK"
|
190
|
+
end
|
191
|
+
|
167
192
|
it "should convert the key into a string before storing" do
|
168
193
|
@client.set(123, "foo")
|
169
194
|
@client.keys.should include("123")
|
@@ -180,12 +205,12 @@ module FakeRedis
|
|
180
205
|
|
181
206
|
it "should only operate against keys containing string values" do
|
182
207
|
@client.sadd("key1", "one")
|
183
|
-
lambda { @client.get("key1") }.should raise_error(Redis::CommandError, "
|
184
|
-
lambda { @client.getset("key1", 1) }.should raise_error(Redis::CommandError, "
|
208
|
+
lambda { @client.get("key1") }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
|
209
|
+
lambda { @client.getset("key1", 1) }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
|
185
210
|
|
186
211
|
@client.hset("key2", "one", "two")
|
187
|
-
lambda { @client.get("key2") }.should raise_error(Redis::CommandError, "
|
188
|
-
lambda { @client.getset("key2", 1) }.should raise_error(Redis::CommandError, "
|
212
|
+
lambda { @client.get("key2") }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
|
213
|
+
lambda { @client.getset("key2", 1) }.should raise_error(Redis::CommandError, "WRONGTYPE Operation against a key holding the wrong kind of value")
|
189
214
|
end
|
190
215
|
|
191
216
|
it "should move a key from one database to another successfully" do
|
data/spec/lists_spec.rb
CHANGED
@@ -123,6 +123,39 @@ module FakeRedis
|
|
123
123
|
@client.lrange("key1", 0, -1).should be == ["two", "three"]
|
124
124
|
end
|
125
125
|
|
126
|
+
|
127
|
+
context "when the list is smaller than the requested trim" do
|
128
|
+
before { @client.rpush("listOfOne", "one") }
|
129
|
+
|
130
|
+
context "trimming with a negative start (specifying a max)" do
|
131
|
+
before { @client.ltrim("listOfOne", -5, -1) }
|
132
|
+
|
133
|
+
it "returns the unmodified list" do
|
134
|
+
@client.lrange("listOfOne", 0, -1).should be == ["one"]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when the list is larger than the requested trim" do
|
140
|
+
before do
|
141
|
+
@client.rpush("maxTest", "one")
|
142
|
+
@client.rpush("maxTest", "two")
|
143
|
+
@client.rpush("maxTest", "three")
|
144
|
+
@client.rpush("maxTest", "four")
|
145
|
+
@client.rpush("maxTest", "five")
|
146
|
+
@client.rpush("maxTest", "six")
|
147
|
+
end
|
148
|
+
|
149
|
+
context "trimming with a negative start (specifying a max)" do
|
150
|
+
before { @client.ltrim("maxTest", -5, -1) }
|
151
|
+
|
152
|
+
it "should trim a list to the specified maximum size" do
|
153
|
+
@client.lrange("maxTest", 0, -1).should be == ["two","three", "four", "five", "six"]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
|
126
159
|
it "should remove and return the last element in a list" do
|
127
160
|
@client.rpush("key1", "one")
|
128
161
|
@client.rpush("key1", "two")
|
data/spec/sets_spec.rb
CHANGED
@@ -13,6 +13,13 @@ module FakeRedis
|
|
13
13
|
@client.smembers("key").should be == ["value"]
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should raise error if command arguments count is not enough" do
|
17
|
+
expect { @client.sadd("key", []) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'sadd' command")
|
18
|
+
expect { @client.sinter(*[]) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'sinter' command")
|
19
|
+
|
20
|
+
@client.smembers("key").should be_empty
|
21
|
+
end
|
22
|
+
|
16
23
|
it "should add multiple members to a set" do
|
17
24
|
@client.sadd("key", %w(value other something more)).should be == 4
|
18
25
|
@client.sadd("key", %w(and additional values)).should be == 3
|
@@ -39,6 +46,13 @@ module FakeRedis
|
|
39
46
|
@client.sdiff("key1", "key2", "key3").should =~ ["b", "d"]
|
40
47
|
end
|
41
48
|
|
49
|
+
it "should subtract from a nonexistent set" do
|
50
|
+
@client.sadd("key2", "a")
|
51
|
+
@client.sadd("key2", "b")
|
52
|
+
|
53
|
+
@client.sdiff("key1", "key2").should == []
|
54
|
+
end
|
55
|
+
|
42
56
|
it "should subtract multiple sets and store the resulting set in a key" do
|
43
57
|
@client.sadd("key1", "a")
|
44
58
|
@client.sadd("key1", "b")
|
data/spec/sorted_sets_spec.rb
CHANGED
@@ -44,6 +44,10 @@ module FakeRedis
|
|
44
44
|
@client.zscore("key", "val2").should be == 2
|
45
45
|
@client.zscore("key", "val3").should be == 3
|
46
46
|
@client.zscore("key", "val4").should be == 4
|
47
|
+
|
48
|
+
@client.zadd("key", [[5, "val5"], [3, "val6"]]).should be == 2
|
49
|
+
@client.zscore("key", "val5").should be == 5
|
50
|
+
@client.zscore("key", "val6").should be == 3
|
47
51
|
end
|
48
52
|
|
49
53
|
it "should error with wrong number of arguments when adding members" do
|
@@ -178,10 +182,10 @@ module FakeRedis
|
|
178
182
|
@client.zrevrangebyscore("key", 100, 0).should be == ["three", "two", "one"]
|
179
183
|
@client.zrevrangebyscore("key", 2, 1).should be == ["two", "one"]
|
180
184
|
@client.zrevrangebyscore("key", 1, 2).should be == []
|
181
|
-
@client.zrevrangebyscore("key", 2, 1, :with_scores => true).should be == [["two", 2], ["one", 1]]
|
185
|
+
@client.zrevrangebyscore("key", 2, 1, :with_scores => true).should be == [["two", 2.0], ["one", 1.0]]
|
182
186
|
@client.zrevrangebyscore("key", 100, 0, :limit => [0, 1]).should be == ["three"]
|
183
187
|
@client.zrevrangebyscore("key", 100, 0, :limit => [0, -1]).should be == ["three", "two", "one"]
|
184
|
-
@client.zrevrangebyscore("key", 100, 0, :limit => [1, -1], :with_scores => true).should be == [["two", 2], ["one", 1]]
|
188
|
+
@client.zrevrangebyscore("key", 100, 0, :limit => [1, -1], :with_scores => true).should be == [["two", 2.0], ["one", 1.0]]
|
185
189
|
end
|
186
190
|
|
187
191
|
it "should determine the index of a member in a sorted set" do
|
@@ -202,6 +206,14 @@ module FakeRedis
|
|
202
206
|
@client.zrevrank("key", "four").should be_nil
|
203
207
|
end
|
204
208
|
|
209
|
+
it "should not raise errors for zrank() on accessing a non-existing key in a sorted set" do
|
210
|
+
@client.zrank("no_such_key", "no_suck_id").should be_nil
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should not raise errors for zrevrank() on accessing a non-existing key in a sorted set" do
|
214
|
+
@client.zrevrank("no_such_key", "no_suck_id").should be_nil
|
215
|
+
end
|
216
|
+
|
205
217
|
describe "#zinterstore" do
|
206
218
|
before do
|
207
219
|
@client.zadd("key1", 1, "one")
|
@@ -409,5 +421,11 @@ module FakeRedis
|
|
409
421
|
#it "should get the score associated with the given member in a sorted set"
|
410
422
|
|
411
423
|
#it "should add multiple sorted sets and store the resulting sorted set in a new key"
|
424
|
+
|
425
|
+
it "zrem should remove members add by zadd" do
|
426
|
+
@client.zadd("key1", 1, 3)
|
427
|
+
@client.zrem("key1", 3)
|
428
|
+
@client.zscore("key1", 3).should be_nil
|
429
|
+
end
|
412
430
|
end
|
413
431
|
end
|
data/spec/strings_spec.rb
CHANGED
@@ -158,6 +158,15 @@ module FakeRedis
|
|
158
158
|
@client.get("key2").should be == "value2"
|
159
159
|
end
|
160
160
|
|
161
|
+
it "should raise error if command arguments count is wrong" do
|
162
|
+
expect { @client.mset }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'mset' command")
|
163
|
+
expect { @client.mset(:key1) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'mset' command")
|
164
|
+
expect { @client.mset(:key1, "value", :key2) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for MSET")
|
165
|
+
|
166
|
+
@client.get("key1").should be_nil
|
167
|
+
@client.get("key2").should be_nil
|
168
|
+
end
|
169
|
+
|
161
170
|
it "should set multiple keys to multiple values, only if none of the keys exist" do
|
162
171
|
@client.msetnx(:key1, "value1", :key2, "value2").should be == true
|
163
172
|
@client.msetnx(:key1, "value3", :key2, "value4").should be == false
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FakeRedis
|
4
|
+
describe "UPCASE method name will call downcase method" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = Redis.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#ZCOUNT" do
|
11
|
+
@client.ZCOUNT("key", 2, 3).should == @client.zcount("key", 2, 3)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "#ZSCORE" do
|
15
|
+
@client.ZSCORE("key", 2).should == @client.zscore("key", 2)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakeredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Guillermo Iguaran
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,17 +27,15 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 2.0.0
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 2.0.0
|
46
41
|
description: Fake (In-memory) driver for redis-rb. Useful for testing environment
|
@@ -80,30 +75,30 @@ files:
|
|
80
75
|
- spec/spec_helper_live_redis.rb
|
81
76
|
- spec/strings_spec.rb
|
82
77
|
- spec/transactions_spec.rb
|
78
|
+
- spec/upcase_method_name_spec.rb
|
83
79
|
homepage: https://guilleiguaran.github.com/fakeredis
|
84
80
|
licenses:
|
85
81
|
- MIT
|
82
|
+
metadata: {}
|
86
83
|
post_install_message:
|
87
84
|
rdoc_options: []
|
88
85
|
require_paths:
|
89
86
|
- lib
|
90
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
88
|
requirements:
|
93
|
-
- -
|
89
|
+
- - '>='
|
94
90
|
- !ruby/object:Gem::Version
|
95
91
|
version: '0'
|
96
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
93
|
requirements:
|
99
|
-
- -
|
94
|
+
- - '>='
|
100
95
|
- !ruby/object:Gem::Version
|
101
96
|
version: '0'
|
102
97
|
requirements: []
|
103
98
|
rubyforge_project:
|
104
|
-
rubygems_version:
|
99
|
+
rubygems_version: 2.0.14
|
105
100
|
signing_key:
|
106
|
-
specification_version:
|
101
|
+
specification_version: 4
|
107
102
|
summary: Fake (In-memory) driver for redis-rb.
|
108
103
|
test_files:
|
109
104
|
- spec/compatibility_spec.rb
|
@@ -118,3 +113,4 @@ test_files:
|
|
118
113
|
- spec/spec_helper_live_redis.rb
|
119
114
|
- spec/strings_spec.rb
|
120
115
|
- spec/transactions_spec.rb
|
116
|
+
- spec/upcase_method_name_spec.rb
|