fakeredis 0.4.1 → 0.4.2
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/.travis.yml +2 -2
- data/LICENSE +1 -1
- data/README.md +3 -2
- data/fakeredis.gemspec +2 -3
- data/lib/fake_redis.rb +1 -0
- data/lib/fakeredis/expiring_hash.rb +70 -0
- data/lib/fakeredis/rspec.rb +1 -1
- data/lib/fakeredis/sorted_set_argument_handler.rb +74 -0
- data/lib/fakeredis/sorted_set_store.rb +80 -0
- data/lib/fakeredis/version.rb +1 -1
- data/lib/fakeredis/zset.rb +29 -0
- data/lib/redis/connection/memory.rb +280 -279
- data/spec/compatibility_spec.rb +2 -2
- data/spec/connection_spec.rb +62 -1
- data/spec/hashes_spec.rb +40 -29
- data/spec/keys_spec.rb +105 -25
- data/spec/lists_spec.rb +34 -31
- data/spec/server_spec.rb +80 -2
- data/spec/sets_spec.rb +18 -18
- data/spec/sorted_sets_spec.rb +246 -62
- data/spec/spec_helper_live_redis.rb +1 -1
- data/spec/strings_spec.rb +79 -55
- data/spec/transactions_spec.rb +1 -1
- metadata +12 -7
data/spec/strings_spec.rb
CHANGED
@@ -11,121 +11,121 @@ module FakeRedis
|
|
11
11
|
@client.set("key1", "Hello")
|
12
12
|
@client.append("key1", " World")
|
13
13
|
|
14
|
-
@client.get("key1").should == "Hello World"
|
14
|
+
@client.get("key1").should be == "Hello World"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should decrement the integer value of a key by one" do
|
18
18
|
@client.set("counter", "1")
|
19
19
|
@client.decr("counter")
|
20
20
|
|
21
|
-
@client.get("counter").should == "0"
|
21
|
+
@client.get("counter").should be == "0"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should decrement the integer value of a key by the given number" do
|
25
25
|
@client.set("counter", "10")
|
26
26
|
@client.decrby("counter", "5")
|
27
27
|
|
28
|
-
@client.get("counter").should == "5"
|
28
|
+
@client.get("counter").should be == "5"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should get the value of a key" do
|
32
|
-
@client.get("key2").should == nil
|
32
|
+
@client.get("key2").should be == nil
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should returns the bit value at offset in the string value stored at key" do
|
36
36
|
@client.set("key1", "a")
|
37
37
|
|
38
|
-
@client.getbit("key1", 1).should == 1
|
39
|
-
@client.getbit("key1", 2).should == 1
|
40
|
-
@client.getbit("key1", 3).should == 0
|
41
|
-
@client.getbit("key1", 4).should == 0
|
42
|
-
@client.getbit("key1", 5).should == 0
|
43
|
-
@client.getbit("key1", 6).should == 0
|
44
|
-
@client.getbit("key1", 7).should == 1
|
38
|
+
@client.getbit("key1", 1).should be == 1
|
39
|
+
@client.getbit("key1", 2).should be == 1
|
40
|
+
@client.getbit("key1", 3).should be == 0
|
41
|
+
@client.getbit("key1", 4).should be == 0
|
42
|
+
@client.getbit("key1", 5).should be == 0
|
43
|
+
@client.getbit("key1", 6).should be == 0
|
44
|
+
@client.getbit("key1", 7).should be == 1
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should allow direct bit manipulation even if the string isn't set" do
|
48
48
|
@client.setbit("key1", 10, 1)
|
49
|
-
@client.getbit("key1", 10).should == 1
|
49
|
+
@client.getbit("key1", 10).should be == 1
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should get a substring of the string stored at a key" do
|
53
53
|
@client.set("key1", "This a message")
|
54
54
|
|
55
|
-
@client.getrange("key1", 0, 3).should == "This"
|
56
|
-
@client.substr("key1", 0, 3).should == "This"
|
55
|
+
@client.getrange("key1", 0, 3).should be == "This"
|
56
|
+
@client.substr("key1", 0, 3).should be == "This"
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should set the string value of a key and return its old value" do
|
60
60
|
@client.set("key1","value1")
|
61
61
|
|
62
|
-
@client.getset("key1", "value2").should == "value1"
|
63
|
-
@client.get("key1").should == "value2"
|
62
|
+
@client.getset("key1", "value2").should be == "value1"
|
63
|
+
@client.get("key1").should be == "value2"
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should return nil for #getset if the key does not exist when setting" do
|
67
|
-
@client.getset("key1", "value1").should == nil
|
68
|
-
@client.get("key1").should == "value1"
|
67
|
+
@client.getset("key1", "value1").should be == nil
|
68
|
+
@client.get("key1").should be == "value1"
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should increment the integer value of a key by one" do
|
72
72
|
@client.set("counter", "1")
|
73
|
-
@client.incr("counter").should == 2
|
73
|
+
@client.incr("counter").should be == 2
|
74
74
|
|
75
|
-
@client.get("counter").should == "2"
|
75
|
+
@client.get("counter").should be == "2"
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should not change the expire value of the key during incr" do
|
79
79
|
@client.set("counter", "1")
|
80
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
|
81
|
+
@client.ttl("counter").should be == 600
|
82
|
+
@client.incr("counter").should be == 2
|
83
|
+
@client.ttl("counter").should be == 600
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should decrement the integer value of a key by one" do
|
87
87
|
@client.set("counter", "1")
|
88
|
-
@client.decr("counter").should == 0
|
88
|
+
@client.decr("counter").should be == 0
|
89
89
|
|
90
|
-
@client.get("counter").should == "0"
|
90
|
+
@client.get("counter").should be == "0"
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should not change the expire value of the key during decr" do
|
94
94
|
@client.set("counter", "2")
|
95
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
|
96
|
+
@client.ttl("counter").should be == 600
|
97
|
+
@client.decr("counter").should be == 1
|
98
|
+
@client.ttl("counter").should be == 600
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should increment the integer value of a key by the given number" do
|
102
102
|
@client.set("counter", "10")
|
103
|
-
@client.incrby("counter", "5").should == 15
|
104
|
-
@client.incrby("counter", 2).should == 17
|
105
|
-
@client.get("counter").should == "17"
|
103
|
+
@client.incrby("counter", "5").should be == 15
|
104
|
+
@client.incrby("counter", 2).should be == 17
|
105
|
+
@client.get("counter").should be == "17"
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should not change the expire value of the key during incrby" do
|
109
109
|
@client.set("counter", "1")
|
110
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
|
111
|
+
@client.ttl("counter").should be == 600
|
112
|
+
@client.incrby("counter", "5").should be == 6
|
113
|
+
@client.ttl("counter").should be == 600
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should decrement the integer value of a key by the given number" do
|
117
117
|
@client.set("counter", "10")
|
118
|
-
@client.decrby("counter", "5").should == 5
|
119
|
-
@client.decrby("counter", 2).should == 3
|
120
|
-
@client.get("counter").should == "3"
|
118
|
+
@client.decrby("counter", "5").should be == 5
|
119
|
+
@client.decrby("counter", 2).should be == 3
|
120
|
+
@client.get("counter").should be == "3"
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should not change the expire value of the key during decrby" do
|
124
124
|
@client.set("counter", "8")
|
125
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
|
126
|
+
@client.ttl("counter").should be == 600
|
127
|
+
@client.decrby("counter", "3").should be == 5
|
128
|
+
@client.ttl("counter").should be == 600
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should get the values of all the given keys" do
|
@@ -133,7 +133,16 @@ module FakeRedis
|
|
133
133
|
@client.set("key2", "value2")
|
134
134
|
@client.set("key3", "value3")
|
135
135
|
|
136
|
-
@client.mget("key1", "key2", "key3").should == ["value1", "value2", "value3"]
|
136
|
+
@client.mget("key1", "key2", "key3").should be == ["value1", "value2", "value3"]
|
137
|
+
@client.mget(["key1", "key2", "key3"]).should be == ["value1", "value2", "value3"]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns nil for non existent keys" do
|
141
|
+
@client.set("key1", "value1")
|
142
|
+
@client.set("key3", "value3")
|
143
|
+
|
144
|
+
@client.mget("key1", "key2", "key3", "key4").should be == ["value1", nil, "value3", nil]
|
145
|
+
@client.mget(["key1", "key2", "key3", "key4"]).should be == ["value1", nil, "value3", nil]
|
137
146
|
end
|
138
147
|
|
139
148
|
it 'raises an argument error when not passed any fields' do
|
@@ -145,36 +154,51 @@ module FakeRedis
|
|
145
154
|
it "should set multiple keys to multiple values" do
|
146
155
|
@client.mset(:key1, "value1", :key2, "value2")
|
147
156
|
|
148
|
-
@client.get("key1").should == "value1"
|
149
|
-
@client.get("key2").should == "value2"
|
157
|
+
@client.get("key1").should be == "value1"
|
158
|
+
@client.get("key2").should be == "value2"
|
150
159
|
end
|
151
160
|
|
152
161
|
it "should set multiple keys to multiple values, only if none of the keys exist" do
|
153
|
-
@client.msetnx(:key1, "value1", :key2, "value2")
|
154
|
-
@client.msetnx(:key1, "value3", :key2, "value4")
|
162
|
+
@client.msetnx(:key1, "value1", :key2, "value2").should be == true
|
163
|
+
@client.msetnx(:key1, "value3", :key2, "value4").should be == false
|
164
|
+
|
165
|
+
@client.get("key1").should be == "value1"
|
166
|
+
@client.get("key2").should be == "value2"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should set multiple keys to multiple values with a hash" do
|
170
|
+
@client.mapped_mset(:key1 => "value1", :key2 => "value2")
|
171
|
+
|
172
|
+
@client.get("key1").should be == "value1"
|
173
|
+
@client.get("key2").should be == "value2"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should set multiple keys to multiple values with a hash, only if none of the keys exist" do
|
177
|
+
@client.mapped_msetnx(:key1 => "value1", :key2 => "value2").should be == true
|
178
|
+
@client.mapped_msetnx(:key1 => "value3", :key2 => "value4").should be == false
|
155
179
|
|
156
|
-
@client.get("key1").should == "value1"
|
157
|
-
@client.get("key2").should == "value2"
|
180
|
+
@client.get("key1").should be == "value1"
|
181
|
+
@client.get("key2").should be == "value2"
|
158
182
|
end
|
159
183
|
|
160
184
|
it "should set the string value of a key" do
|
161
185
|
@client.set("key1", "1")
|
162
186
|
|
163
|
-
@client.get("key1").should == "1"
|
187
|
+
@client.get("key1").should be == "1"
|
164
188
|
end
|
165
189
|
|
166
190
|
it "should sets or clears the bit at offset in the string value stored at key" do
|
167
191
|
@client.set("key1", "abc")
|
168
192
|
@client.setbit("key1", 11, 1)
|
169
193
|
|
170
|
-
@client.get("key1").should == "arc"
|
194
|
+
@client.get("key1").should be == "arc"
|
171
195
|
end
|
172
196
|
|
173
197
|
it "should set the value and expiration of a key" do
|
174
198
|
@client.setex("key1", 30, "value1")
|
175
199
|
|
176
|
-
@client.get("key1").should == "value1"
|
177
|
-
@client.ttl("key1").should == 30
|
200
|
+
@client.get("key1").should be == "value1"
|
201
|
+
@client.ttl("key1").should be == 30
|
178
202
|
end
|
179
203
|
|
180
204
|
it "should set the value of a key, only if the key does not exist" do
|
@@ -182,21 +206,21 @@ module FakeRedis
|
|
182
206
|
@client.setnx("key1", "new value")
|
183
207
|
@client.setnx("key2", "another value")
|
184
208
|
|
185
|
-
@client.get("key1").should == "test value"
|
186
|
-
@client.get("key2").should == "another value"
|
209
|
+
@client.get("key1").should be == "test value"
|
210
|
+
@client.get("key2").should be == "another value"
|
187
211
|
end
|
188
212
|
|
189
213
|
it "should overwrite part of a string at key starting at the specified offset" do
|
190
214
|
@client.set("key1", "Hello World")
|
191
215
|
@client.setrange("key1", 6, "Redis")
|
192
216
|
|
193
|
-
@client.get("key1").should == "Hello Redis"
|
217
|
+
@client.get("key1").should be == "Hello Redis"
|
194
218
|
end
|
195
219
|
|
196
220
|
it "should get the length of the value stored in a key" do
|
197
221
|
@client.set("key1", "abc")
|
198
222
|
|
199
|
-
@client.strlen("key1").should == 3
|
223
|
+
@client.strlen("key1").should be == 3
|
200
224
|
end
|
201
225
|
|
202
226
|
end
|
data/spec/transactions_spec.rb
CHANGED
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.2
|
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:
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -59,9 +59,14 @@ files:
|
|
59
59
|
- README.md
|
60
60
|
- Rakefile
|
61
61
|
- fakeredis.gemspec
|
62
|
+
- lib/fake_redis.rb
|
62
63
|
- lib/fakeredis.rb
|
64
|
+
- lib/fakeredis/expiring_hash.rb
|
63
65
|
- lib/fakeredis/rspec.rb
|
66
|
+
- lib/fakeredis/sorted_set_argument_handler.rb
|
67
|
+
- lib/fakeredis/sorted_set_store.rb
|
64
68
|
- lib/fakeredis/version.rb
|
69
|
+
- lib/fakeredis/zset.rb
|
65
70
|
- lib/redis/connection/memory.rb
|
66
71
|
- spec/compatibility_spec.rb
|
67
72
|
- spec/connection_spec.rb
|
@@ -75,8 +80,9 @@ files:
|
|
75
80
|
- spec/spec_helper_live_redis.rb
|
76
81
|
- spec/strings_spec.rb
|
77
82
|
- spec/transactions_spec.rb
|
78
|
-
homepage: https://github.com/
|
79
|
-
licenses:
|
83
|
+
homepage: https://guilleiguaran.github.com/fakeredis
|
84
|
+
licenses:
|
85
|
+
- MIT
|
80
86
|
post_install_message:
|
81
87
|
rdoc_options: []
|
82
88
|
require_paths:
|
@@ -94,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
100
|
- !ruby/object:Gem::Version
|
95
101
|
version: '0'
|
96
102
|
requirements: []
|
97
|
-
rubyforge_project:
|
98
|
-
rubygems_version: 1.8.
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.23
|
99
105
|
signing_key:
|
100
106
|
specification_version: 3
|
101
107
|
summary: Fake (In-memory) driver for redis-rb.
|
@@ -112,4 +118,3 @@ test_files:
|
|
112
118
|
- spec/spec_helper_live_redis.rb
|
113
119
|
- spec/strings_spec.rb
|
114
120
|
- spec/transactions_spec.rb
|
115
|
-
has_rdoc:
|