fakeredis 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -0
- data/lib/fakeredis/rspec.rb +6 -7
- data/lib/fakeredis/version.rb +1 -1
- data/lib/redis/connection/memory.rb +73 -27
- data/spec/connection_spec.rb +2 -0
- data/spec/hashes_spec.rb +4 -4
- data/spec/keys_spec.rb +16 -2
- data/spec/lists_spec.rb +17 -1
- data/spec/sets_spec.rb +6 -0
- data/spec/sorted_sets_spec.rb +35 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/spec_helper_live_redis.rb +14 -0
- data/spec/strings_spec.rb +33 -1
- metadata +5 -3
data/README.md
CHANGED
@@ -64,6 +64,7 @@ Or:
|
|
64
64
|
* [obrie](https://github.com/obrie)
|
65
65
|
* [jredville](https://github.com/jredville)
|
66
66
|
* [redsquirrel](https://github.com/redsquirrel)
|
67
|
+
* [dpick](https://github.com/dpick)
|
67
68
|
* [Travis-CI](http://travis-ci.org/) (Travis-CI also uses Fakeredis in its tests!!!)
|
68
69
|
|
69
70
|
|
data/lib/fakeredis/rspec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# Require this either in your Gemfile or in RSpec's
|
2
|
-
# support scripts. Examples:
|
1
|
+
# Require this either in your Gemfile or in RSpec's
|
2
|
+
# support scripts. Examples:
|
3
3
|
#
|
4
4
|
# # Gemfile
|
5
5
|
# group :test do
|
6
6
|
# gem "rspec"
|
7
7
|
# gem "fakeredis", :require => "fakeredis/rspec"
|
8
|
-
# end
|
8
|
+
# end
|
9
9
|
#
|
10
10
|
# # spec/support/fakeredis.rb
|
11
11
|
# require 'fakeredis/rspec'
|
@@ -15,10 +15,9 @@ require 'rspec/core'
|
|
15
15
|
require 'fakeredis'
|
16
16
|
|
17
17
|
RSpec.configure do |c|
|
18
|
-
|
18
|
+
|
19
19
|
c.before do
|
20
|
-
|
21
|
-
redis.flushdb if redis.client.connection.is_a?(Redis::Connection::Memory)
|
20
|
+
Redis::Connection::Memory.instances.values.each &:flushdb
|
22
21
|
end
|
23
|
-
|
22
|
+
|
24
23
|
end
|
data/lib/fakeredis/version.rb
CHANGED
@@ -76,8 +76,12 @@ class Redis
|
|
76
76
|
@connected
|
77
77
|
end
|
78
78
|
|
79
|
+
def self.instances
|
80
|
+
@instances ||= {}
|
81
|
+
end
|
82
|
+
|
79
83
|
def self.connect(options = {})
|
80
|
-
self.new(true)
|
84
|
+
self.instances[options] ||= self.new(true)
|
81
85
|
end
|
82
86
|
|
83
87
|
def connect_unix(path, timeout)
|
@@ -181,7 +185,7 @@ class Redis
|
|
181
185
|
end
|
182
186
|
|
183
187
|
def mget(*keys)
|
184
|
-
raise
|
188
|
+
raise Redis::CommandError, "wrong number of arguments for 'mget' command" if keys.empty?
|
185
189
|
@data.values_at(*keys)
|
186
190
|
end
|
187
191
|
|
@@ -254,7 +258,7 @@ class Redis
|
|
254
258
|
|
255
259
|
def lrange(key, startidx, endidx)
|
256
260
|
data_type_check(key, Array)
|
257
|
-
@data[key] && @data[key][startidx..endidx]
|
261
|
+
(@data[key] && @data[key][startidx..endidx]) || []
|
258
262
|
end
|
259
263
|
|
260
264
|
def ltrim(key, start, stop)
|
@@ -275,7 +279,7 @@ class Redis
|
|
275
279
|
case where
|
276
280
|
when :before then @data[key].insert(index, value)
|
277
281
|
when :after then @data[key].insert(index + 1, value)
|
278
|
-
else raise
|
282
|
+
else raise Redis::CommandError, "ERR syntax error"
|
279
283
|
end
|
280
284
|
end
|
281
285
|
|
@@ -307,7 +311,9 @@ class Redis
|
|
307
311
|
def rpush(key, value)
|
308
312
|
data_type_check(key, Array)
|
309
313
|
@data[key] ||= []
|
310
|
-
|
314
|
+
[value].flatten.each do |val|
|
315
|
+
@data[key].push(val.to_s)
|
316
|
+
end
|
311
317
|
@data[key].size
|
312
318
|
end
|
313
319
|
|
@@ -320,7 +326,9 @@ class Redis
|
|
320
326
|
def lpush(key, value)
|
321
327
|
data_type_check(key, Array)
|
322
328
|
@data[key] ||= []
|
323
|
-
|
329
|
+
[value].flatten.each do |val|
|
330
|
+
@data[key].unshift(val.to_s)
|
331
|
+
end
|
324
332
|
@data[key].size
|
325
333
|
end
|
326
334
|
|
@@ -362,12 +370,20 @@ class Redis
|
|
362
370
|
|
363
371
|
def sadd(key, value)
|
364
372
|
data_type_check(key, ::Set)
|
365
|
-
|
366
|
-
|
373
|
+
value = Array(value)
|
374
|
+
|
375
|
+
result = if @data[key]
|
376
|
+
old_set = @data[key].dup
|
377
|
+
@data[key].merge(value.map(&:to_s))
|
378
|
+
(@data[key] - old_set).size
|
367
379
|
else
|
368
|
-
@data[key] = ::Set.new(
|
369
|
-
|
380
|
+
@data[key] = ::Set.new(value.map(&:to_s))
|
381
|
+
@data[key].size
|
370
382
|
end
|
383
|
+
|
384
|
+
# 0 = false, 1 = true, 2+ untouched
|
385
|
+
return result == 1 if result < 2
|
386
|
+
result
|
371
387
|
end
|
372
388
|
|
373
389
|
def srem(key, value)
|
@@ -447,8 +463,10 @@ class Redis
|
|
447
463
|
end
|
448
464
|
|
449
465
|
def del(*keys)
|
466
|
+
keys = keys.flatten(1)
|
467
|
+
raise Redis::CommandError, "ERR wrong number of arguments for 'del' command" if keys.empty?
|
450
468
|
old_count = @data.keys.size
|
451
|
-
keys.
|
469
|
+
keys.each do |key|
|
452
470
|
@data.delete(key)
|
453
471
|
end
|
454
472
|
deleted_count = old_count - @data.keys.size
|
@@ -523,7 +541,7 @@ class Redis
|
|
523
541
|
end
|
524
542
|
|
525
543
|
def hmset(key, *fields)
|
526
|
-
raise
|
544
|
+
raise Redis::CommandError, "wrong number of arguments for 'hmset' command" if fields.empty? || fields.size.odd?
|
527
545
|
data_type_check(key, Hash)
|
528
546
|
@data[key] ||= {}
|
529
547
|
fields.each_slice(2) do |field|
|
@@ -532,7 +550,7 @@ class Redis
|
|
532
550
|
end
|
533
551
|
|
534
552
|
def hmget(key, *fields)
|
535
|
-
raise
|
553
|
+
raise Redis::CommandError, "wrong number of arguments for 'hmget' command" if fields.empty?
|
536
554
|
data_type_check(key, Hash)
|
537
555
|
values = []
|
538
556
|
fields.map do |field|
|
@@ -631,26 +649,22 @@ class Redis
|
|
631
649
|
end
|
632
650
|
|
633
651
|
def incr(key)
|
634
|
-
@data
|
635
|
-
@data[key] = (@data[key].to_i + 1).to_s
|
652
|
+
@data.merge!({ key => (@data[key].to_i + 1).to_s || "1"})
|
636
653
|
@data[key].to_i
|
637
654
|
end
|
638
655
|
|
639
656
|
def incrby(key, by)
|
640
|
-
@data
|
641
|
-
@data[key] = (@data[key].to_i + by.to_i).to_s
|
657
|
+
@data.merge!({ key => (@data[key].to_i + by.to_i).to_s || by })
|
642
658
|
@data[key].to_i
|
643
659
|
end
|
644
660
|
|
645
661
|
def decr(key)
|
646
|
-
@data
|
647
|
-
@data[key] = (@data[key].to_i - 1).to_s
|
662
|
+
@data.merge!({ key => (@data[key].to_i - 1).to_s || "-1"})
|
648
663
|
@data[key].to_i
|
649
664
|
end
|
650
665
|
|
651
666
|
def decrby(key, by)
|
652
|
-
@data
|
653
|
-
@data[key] = (@data[key].to_i - by.to_i).to_s
|
667
|
+
@data.merge!({ key => ((@data[key].to_i - by.to_i) || (by.to_i * -1)).to_s })
|
654
668
|
@data[key].to_i
|
655
669
|
end
|
656
670
|
|
@@ -690,12 +704,34 @@ class Redis
|
|
690
704
|
"OK"
|
691
705
|
end
|
692
706
|
|
693
|
-
def zadd(key,
|
707
|
+
def zadd(key, *args)
|
708
|
+
if !args.first.is_a?(Array)
|
709
|
+
if args.size < 2
|
710
|
+
raise Redis::CommandError, "ERR wrong number of arguments for 'zadd' command"
|
711
|
+
elsif args.size.odd?
|
712
|
+
raise Redis::CommandError, "ERR syntax error"
|
713
|
+
end
|
714
|
+
else
|
715
|
+
unless args.all? {|pair| pair.size == 2 }
|
716
|
+
raise(Redis::CommandError, "ERR syntax error")
|
717
|
+
end
|
718
|
+
end
|
719
|
+
|
694
720
|
data_type_check(key, ZSet)
|
695
721
|
@data[key] ||= ZSet.new
|
696
|
-
|
697
|
-
|
698
|
-
|
722
|
+
|
723
|
+
if args.size == 2
|
724
|
+
score, value = args
|
725
|
+
exists = !@data[key].key?(value.to_s)
|
726
|
+
@data[key][value.to_s] = score
|
727
|
+
else
|
728
|
+
# Turn [1, 2, 3, 4] into [[1, 2], [3, 4]] unless it is already
|
729
|
+
args = args.each_slice(2).to_a unless args.first.is_a?(Array)
|
730
|
+
exists = args.map(&:last).map { |el| @data[key].key?(el.to_s) }.count(false)
|
731
|
+
args.each { |score, value| @data[key][value.to_s] = score }
|
732
|
+
end
|
733
|
+
|
734
|
+
exists
|
699
735
|
end
|
700
736
|
|
701
737
|
def zrem(key, value)
|
@@ -811,7 +847,8 @@ class Redis
|
|
811
847
|
hashes = keys.map do |src|
|
812
848
|
case @data[src]
|
813
849
|
when ::Set
|
814
|
-
|
850
|
+
# Every value has a score of 1
|
851
|
+
Hash[@data[src].map {|k,v| [k, 1]}]
|
815
852
|
when Hash
|
816
853
|
@data[src]
|
817
854
|
else
|
@@ -830,6 +867,7 @@ class Redis
|
|
830
867
|
|
831
868
|
def zremrangebyrank(key, start, stop)
|
832
869
|
sorted_elements = @data[key].sort { |(v_a, r_a), (v_b, r_b)| r_a <=> r_b }
|
870
|
+
start = sorted_elements.length if start > sorted_elements.length
|
833
871
|
elements_to_delete = sorted_elements[start..stop]
|
834
872
|
elements_to_delete.each { |elem, rank| @data[key].delete(elem) }
|
835
873
|
elements_to_delete.size
|
@@ -838,7 +876,15 @@ class Redis
|
|
838
876
|
private
|
839
877
|
|
840
878
|
def zrange_select_by_score(key, min, max)
|
841
|
-
|
879
|
+
if min == '-inf' && max == '+inf'
|
880
|
+
@data[key]
|
881
|
+
elsif max == '+inf'
|
882
|
+
@data[key].reject { |_,v| v < min }
|
883
|
+
elsif min == '-inf'
|
884
|
+
@data[key].reject { |_,v| v > max }
|
885
|
+
else
|
886
|
+
@data[key].reject {|_,v| v < min || v > max }
|
887
|
+
end
|
842
888
|
end
|
843
889
|
|
844
890
|
def remove_key_for_empty_collection(key)
|
data/spec/connection_spec.rb
CHANGED
@@ -7,9 +7,11 @@ module FakeRedis
|
|
7
7
|
@client = Redis.new
|
8
8
|
end
|
9
9
|
|
10
|
+
if fakeredis?
|
10
11
|
it "should authenticate to the server" do
|
11
12
|
@client.auth("pass").should == "OK"
|
12
13
|
end
|
14
|
+
end
|
13
15
|
|
14
16
|
it "should echo the given string" do
|
15
17
|
@client.echo("something").should == "something"
|
data/spec/hashes_spec.rb
CHANGED
@@ -95,17 +95,17 @@ module FakeRedis
|
|
95
95
|
end
|
96
96
|
|
97
97
|
it "throws an argument error when you don't ask for any keys" do
|
98
|
-
lambda { @client.hmget("key1") }.should raise_error(
|
98
|
+
lambda { @client.hmget("key1") }.should raise_error(Redis::CommandError)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should reject an empty list of values" do
|
102
|
-
lambda { @client.hmset("key") }.should raise_error(
|
102
|
+
lambda { @client.hmset("key") }.should raise_error(Redis::CommandError)
|
103
103
|
@client.exists("key").should be_false
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'rejects an insert with a key but no value' do
|
107
|
-
lambda { @client.hmset("key", 'foo') }.should raise_error(
|
108
|
-
lambda { @client.hmset("key", 'foo', 3, 'bar') }.should raise_error(
|
107
|
+
lambda { @client.hmset("key", 'foo') }.should raise_error(Redis::CommandError)
|
108
|
+
lambda { @client.hmset("key", 'foo', 3, 'bar') }.should raise_error(Redis::CommandError)
|
109
109
|
@client.exists("key").should be_false
|
110
110
|
end
|
111
111
|
|
data/spec/keys_spec.rb
CHANGED
@@ -15,6 +15,20 @@ module FakeRedis
|
|
15
15
|
@client.get("key1").should == nil
|
16
16
|
end
|
17
17
|
|
18
|
+
it "should delete multiple keys" do
|
19
|
+
@client.set("key1", "1")
|
20
|
+
@client.set("key2", "2")
|
21
|
+
@client.del(["key1", "key2"])
|
22
|
+
|
23
|
+
@client.get("key1").should be == nil
|
24
|
+
@client.get("key2").should be == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should error deleting no keys" do
|
28
|
+
lambda { @client.del }.should raise_error(Redis::CommandError, "ERR wrong number of arguments for 'del' command")
|
29
|
+
lambda { @client.del [] }.should raise_error(Redis::CommandError, "ERR wrong number of arguments for 'del' command")
|
30
|
+
end
|
31
|
+
|
18
32
|
it "should determine if a key exists" do
|
19
33
|
@client.set("key1", "1")
|
20
34
|
|
@@ -88,12 +102,12 @@ module FakeRedis
|
|
88
102
|
@client.set("akeyd", "4")
|
89
103
|
@client.set("key1", "5")
|
90
104
|
|
91
|
-
@client.keys("key
|
105
|
+
@client.keys("key:*").should =~ ["key:a", "key:b", "key:c"]
|
92
106
|
end
|
93
107
|
|
94
108
|
it "should remove the expiration from a key" do
|
95
109
|
@client.set("key1", "1")
|
96
|
-
@client.expireat("key1", Time.now.to_i)
|
110
|
+
@client.expireat("key1", Time.now.to_i + 1)
|
97
111
|
@client.persist("key1").should == true
|
98
112
|
@client.persist("key1").should == false
|
99
113
|
|
data/spec/lists_spec.rb
CHANGED
@@ -22,6 +22,22 @@ module FakeRedis
|
|
22
22
|
|
23
23
|
@client.lrange("key1", 0, -1).should == ["v1", "v2", "v3"]
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'should allow multiple values to be added to a list in a single rpush' do
|
27
|
+
@client.rpush('key1', [1, 2, 3])
|
28
|
+
@client.lrange('key1', 0, -1).should == ['1', '2', '3']
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should allow multiple values to be added to a list in a single lpush' do
|
32
|
+
@client.lpush('key1', [1, 2, 3])
|
33
|
+
@client.lrange('key1', 0, -1).should == ['3', '2', '1']
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should error if an invalid where argument is given" do
|
37
|
+
@client.rpush("key1", "v1")
|
38
|
+
@client.rpush("key1", "v3")
|
39
|
+
lambda { @client.linsert("key1", :invalid, "v3", "v2") }.should raise_error(Redis::CommandError, "ERR syntax error")
|
40
|
+
end
|
25
41
|
|
26
42
|
it "should get the length of a list" do
|
27
43
|
@client.rpush("key1", "v1")
|
@@ -137,7 +153,7 @@ module FakeRedis
|
|
137
153
|
@client.rpushx("key2", "two")
|
138
154
|
|
139
155
|
@client.lrange("key1", 0, -1).should == ["one", "two"]
|
140
|
-
@client.lrange("key2", 0, -1).should ==
|
156
|
+
@client.lrange("key2", 0, -1).should == []
|
141
157
|
end
|
142
158
|
end
|
143
159
|
end
|
data/spec/sets_spec.rb
CHANGED
@@ -13,6 +13,12 @@ module FakeRedis
|
|
13
13
|
@client.smembers("key").should == ["value"]
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should add multiple members to a set" do
|
17
|
+
@client.sadd("key", %w(value other something more)).should == 4
|
18
|
+
@client.sadd("key", %w(and additional values)).should == 3
|
19
|
+
@client.smembers("key").should =~ ["value", "other", "something", "more", "and", "additional", "values"]
|
20
|
+
end
|
21
|
+
|
16
22
|
it "should get the number of members in a set" do
|
17
23
|
@client.sadd("key", "val1")
|
18
24
|
@client.sadd("key", "val2")
|
data/spec/sorted_sets_spec.rb
CHANGED
@@ -14,6 +14,26 @@ module FakeRedis
|
|
14
14
|
@client.zscore("key", "val").should == 2.0
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should add multiple members to a sorted set, or update its score if it already exists" do
|
18
|
+
@client.zadd("key", [1, "val", 2, "val2"]).should be == 2
|
19
|
+
@client.zscore("key", "val").should be == 1
|
20
|
+
@client.zscore("key", "val2").should be == 2
|
21
|
+
|
22
|
+
@client.zadd("key", [[5, "val"], [3, "val3"], [4, "val4"]]).should be == 2
|
23
|
+
@client.zscore("key", "val").should be == 5
|
24
|
+
@client.zscore("key", "val2").should be == 2
|
25
|
+
@client.zscore("key", "val3").should be == 3
|
26
|
+
@client.zscore("key", "val4").should be == 4
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should error with wrong number of arguments when adding members" do
|
30
|
+
lambda { @client.zadd("key") }.should raise_error(ArgumentError, "wrong number of arguments")
|
31
|
+
lambda { @client.zadd("key", 1) }.should raise_error(ArgumentError, "wrong number of arguments")
|
32
|
+
lambda { @client.zadd("key", [1]) }.should raise_error(Redis::CommandError, "ERR wrong number of arguments for 'zadd' command")
|
33
|
+
lambda { @client.zadd("key", [1, "val", 2]) }.should raise_error(Redis::CommandError, "ERR syntax error")
|
34
|
+
lambda { @client.zadd("key", [[1, "val"], [2]]) }.should raise_error(Redis::CommandError, "ERR syntax error")
|
35
|
+
end
|
36
|
+
|
17
37
|
it "should allow floats as scores when adding or updating" do
|
18
38
|
@client.zadd("key", 4.321, "val").should be(true)
|
19
39
|
@client.zscore("key", "val").should == 4.321
|
@@ -100,6 +120,9 @@ module FakeRedis
|
|
100
120
|
@client.zrangebyscore("key", 0, 100, :limit => [0, 1]).should == ["one"]
|
101
121
|
@client.zrangebyscore("key", 0, 100, :limit => [0, -1]).should == ["one", "two", "three"]
|
102
122
|
@client.zrangebyscore("key", 0, 100, :limit => [1, -1], :with_scores => true).should == [["two", 2], ["three", 3]]
|
123
|
+
@client.zrangebyscore("key", '-inf', '+inf').should == ["one", "two", "three"]
|
124
|
+
@client.zrangebyscore("key", 2, '+inf').should == ["two", "three"]
|
125
|
+
@client.zrangebyscore("key", '-inf', 2).should == ['one', "two"]
|
103
126
|
end
|
104
127
|
|
105
128
|
it "should return a reversed range of members in a sorted set, by score" do
|
@@ -134,7 +157,7 @@ module FakeRedis
|
|
134
157
|
@client.zrevrank("key", "four").should be_nil
|
135
158
|
end
|
136
159
|
|
137
|
-
it "should create
|
160
|
+
it "should create intersections between multiple (sorted) sets and store the resulting sorted set in a new key" do
|
138
161
|
@client.zadd("key1", 1, "one")
|
139
162
|
@client.zadd("key1", 2, "two")
|
140
163
|
@client.zadd("key1", 3, "three")
|
@@ -147,10 +170,10 @@ module FakeRedis
|
|
147
170
|
@client.zrange("out", 0, 100, :with_scores => true).should == [['two', 7], ['three', 10]]
|
148
171
|
|
149
172
|
@client.zinterstore("out", ["key1", "key3"]).should == 2
|
150
|
-
@client.zrange("out", 0, 100, :with_scores => true).should == [['one',
|
173
|
+
@client.zrange("out", 0, 100, :with_scores => true).should == [['one', 2], ['two', 3]]
|
151
174
|
|
152
175
|
@client.zinterstore("out", ["key1", "key2", "key3"]).should == 1
|
153
|
-
@client.zrange("out", 0, 100, :with_scores => true).should == [['two',
|
176
|
+
@client.zrange("out", 0, 100, :with_scores => true).should == [['two', 8]]
|
154
177
|
|
155
178
|
@client.zinterstore("out", ["key1", "no_key"]).should == 0
|
156
179
|
@client.zrange("out", 0, 100, :with_scores => true).should == []
|
@@ -180,6 +203,15 @@ module FakeRedis
|
|
180
203
|
@client.zremrangebyrank("key", 0, 1).should == 2
|
181
204
|
@client.zcard('key').should == 1
|
182
205
|
end
|
206
|
+
|
207
|
+
it 'handles out of range requests' do
|
208
|
+
@client.zadd("key", 1, "one")
|
209
|
+
@client.zadd("key", 2, "two")
|
210
|
+
@client.zadd("key", 3, "three")
|
211
|
+
|
212
|
+
@client.zremrangebyrank("key", 25, -1).should == 0
|
213
|
+
@client.zcard('key').should == 3
|
214
|
+
end
|
183
215
|
end
|
184
216
|
|
185
217
|
#it "should remove all members in a sorted set within the given indexes"
|
data/spec/spec_helper.rb
CHANGED
data/spec/strings_spec.rb
CHANGED
@@ -75,6 +75,14 @@ module FakeRedis
|
|
75
75
|
@client.get("counter").should == "2"
|
76
76
|
end
|
77
77
|
|
78
|
+
it "should not change the expire value of the key during incr" do
|
79
|
+
@client.set("counter", "1")
|
80
|
+
@client.expire("counter", 600).should be_true
|
81
|
+
@client.ttl("counter").should == 600
|
82
|
+
@client.incr("counter").should == 2
|
83
|
+
@client.ttl("counter").should == 600
|
84
|
+
end
|
85
|
+
|
78
86
|
it "should decrement the integer value of a key by one" do
|
79
87
|
@client.set("counter", "1")
|
80
88
|
@client.decr("counter").should == 0
|
@@ -82,6 +90,14 @@ module FakeRedis
|
|
82
90
|
@client.get("counter").should == "0"
|
83
91
|
end
|
84
92
|
|
93
|
+
it "should not change the expire value of the key during decr" do
|
94
|
+
@client.set("counter", "2")
|
95
|
+
@client.expire("counter", 600).should be_true
|
96
|
+
@client.ttl("counter").should == 600
|
97
|
+
@client.decr("counter").should == 1
|
98
|
+
@client.ttl("counter").should == 600
|
99
|
+
end
|
100
|
+
|
85
101
|
it "should increment the integer value of a key by the given number" do
|
86
102
|
@client.set("counter", "10")
|
87
103
|
@client.incrby("counter", "5").should == 15
|
@@ -89,6 +105,14 @@ module FakeRedis
|
|
89
105
|
@client.get("counter").should == "17"
|
90
106
|
end
|
91
107
|
|
108
|
+
it "should not change the expire value of the key during incrby" do
|
109
|
+
@client.set("counter", "1")
|
110
|
+
@client.expire("counter", 600).should be_true
|
111
|
+
@client.ttl("counter").should == 600
|
112
|
+
@client.incrby("counter", "5").should == 6
|
113
|
+
@client.ttl("counter").should == 600
|
114
|
+
end
|
115
|
+
|
92
116
|
it "should decrement the integer value of a key by the given number" do
|
93
117
|
@client.set("counter", "10")
|
94
118
|
@client.decrby("counter", "5").should == 5
|
@@ -96,6 +120,14 @@ module FakeRedis
|
|
96
120
|
@client.get("counter").should == "3"
|
97
121
|
end
|
98
122
|
|
123
|
+
it "should not change the expire value of the key during decrby" do
|
124
|
+
@client.set("counter", "8")
|
125
|
+
@client.expire("counter", 600).should be_true
|
126
|
+
@client.ttl("counter").should == 600
|
127
|
+
@client.decrby("counter", "3").should == 5
|
128
|
+
@client.ttl("counter").should == 600
|
129
|
+
end
|
130
|
+
|
99
131
|
it "should get the values of all the given keys" do
|
100
132
|
@client.set("key1", "value1")
|
101
133
|
@client.set("key2", "value2")
|
@@ -107,7 +139,7 @@ module FakeRedis
|
|
107
139
|
it 'raises an argument error when not passed any fields' do
|
108
140
|
@client.set("key3", "value3")
|
109
141
|
|
110
|
-
lambda { @client.mget }.should raise_error(
|
142
|
+
lambda { @client.mget }.should raise_error(Redis::CommandError)
|
111
143
|
end
|
112
144
|
|
113
145
|
it "should set multiple keys to multiple values" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakeredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- spec/sets_spec.rb
|
73
73
|
- spec/sorted_sets_spec.rb
|
74
74
|
- spec/spec_helper.rb
|
75
|
+
- spec/spec_helper_live_redis.rb
|
75
76
|
- spec/strings_spec.rb
|
76
77
|
- spec/transactions_spec.rb
|
77
78
|
homepage: https://github.com/guilleiguaran/fakeredis
|
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
version: '0'
|
95
96
|
requirements: []
|
96
97
|
rubyforge_project: fakeredis
|
97
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.22
|
98
99
|
signing_key:
|
99
100
|
specification_version: 3
|
100
101
|
summary: Fake (In-memory) driver for redis-rb.
|
@@ -108,6 +109,7 @@ test_files:
|
|
108
109
|
- spec/sets_spec.rb
|
109
110
|
- spec/sorted_sets_spec.rb
|
110
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/spec_helper_live_redis.rb
|
111
113
|
- spec/strings_spec.rb
|
112
114
|
- spec/transactions_spec.rb
|
113
115
|
has_rdoc:
|