ezmobius-redis 0.0.3.4 → 0.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.markdown +5 -2
- data/Rakefile +13 -10
- data/lib/dist_redis.rb +13 -6
- data/lib/pipeline.rb +7 -16
- data/lib/redis.rb +240 -468
- data/spec/redis_spec.rb +262 -218
- data/spec/spec_helper.rb +1 -1
- metadata +7 -5
- data/lib/server.rb +0 -160
data/spec/redis_spec.rb
CHANGED
@@ -13,8 +13,8 @@ end
|
|
13
13
|
|
14
14
|
describe "redis" do
|
15
15
|
before(:all) do
|
16
|
-
|
17
|
-
@r.
|
16
|
+
# use database 15 for testing so we dont accidentally step on you real data
|
17
|
+
@r = Redis.new :db => 15
|
18
18
|
end
|
19
19
|
|
20
20
|
before(:each) do
|
@@ -22,13 +22,20 @@ describe "redis" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
after(:each) do
|
25
|
-
@r.keys('*').each {|k| @r.
|
25
|
+
@r.keys('*').each {|k| @r.del k}
|
26
26
|
end
|
27
27
|
|
28
28
|
after(:all) do
|
29
29
|
@r.quit
|
30
30
|
end
|
31
31
|
|
32
|
+
it "should be able connect without a timeout" do
|
33
|
+
lambda { Redis.new :timeout => 0 }.should_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to PING" do
|
37
|
+
@r.ping.should == 'PONG'
|
38
|
+
end
|
32
39
|
|
33
40
|
it "should be able to GET a key" do
|
34
41
|
@r['foo'].should == 'bar'
|
@@ -58,23 +65,40 @@ describe "redis" do
|
|
58
65
|
sleep 2
|
59
66
|
@r['foo'].should == nil
|
60
67
|
end
|
61
|
-
|
62
|
-
it "should be able to
|
68
|
+
|
69
|
+
it "should be able to return a TTL for a key" do
|
70
|
+
@r.set('foo', 'bar', 1)
|
71
|
+
@r.ttl('foo').should == 1
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be able to SETNX" do
|
63
75
|
@r['foo'] = 'nik'
|
64
76
|
@r['foo'].should == 'nik'
|
65
|
-
@r.
|
77
|
+
@r.setnx 'foo', 'bar'
|
66
78
|
@r['foo'].should == 'nik'
|
67
79
|
end
|
80
|
+
#
|
81
|
+
it "should be able to GETSET" do
|
82
|
+
@r.getset('foo', 'baz').should == 'bar'
|
83
|
+
@r['foo'].should == 'baz'
|
84
|
+
end
|
68
85
|
#
|
69
|
-
it "should be able to INCR
|
70
|
-
@r.
|
86
|
+
it "should be able to INCR a key" do
|
87
|
+
@r.del('counter')
|
71
88
|
@r.incr('counter').should == 1
|
72
89
|
@r.incr('counter').should == 2
|
73
90
|
@r.incr('counter').should == 3
|
74
91
|
end
|
75
|
-
#
|
76
|
-
it "should be able to
|
77
|
-
@r.
|
92
|
+
#
|
93
|
+
it "should be able to INCRBY a key" do
|
94
|
+
@r.del('counter')
|
95
|
+
@r.incrby('counter', 1).should == 1
|
96
|
+
@r.incrby('counter', 2).should == 3
|
97
|
+
@r.incrby('counter', 3).should == 6
|
98
|
+
end
|
99
|
+
#
|
100
|
+
it "should be able to DECR a key" do
|
101
|
+
@r.del('counter')
|
78
102
|
@r.incr('counter').should == 1
|
79
103
|
@r.incr('counter').should == 2
|
80
104
|
@r.incr('counter').should == 3
|
@@ -82,24 +106,24 @@ describe "redis" do
|
|
82
106
|
@r.decr('counter', 2).should == 0
|
83
107
|
end
|
84
108
|
#
|
85
|
-
it "should be able to RANDKEY
|
109
|
+
it "should be able to RANDKEY" do
|
86
110
|
@r.randkey.should_not be_nil
|
87
111
|
end
|
88
112
|
#
|
89
113
|
it "should be able to RENAME a key" do
|
90
|
-
@r.
|
91
|
-
@r.
|
114
|
+
@r.del 'foo'
|
115
|
+
@r.del'bar'
|
92
116
|
@r['foo'] = 'hi'
|
93
|
-
@r.rename
|
117
|
+
@r.rename 'foo', 'bar'
|
94
118
|
@r['bar'].should == 'hi'
|
95
119
|
end
|
96
120
|
#
|
97
|
-
it "should be able to RENAMENX
|
98
|
-
@r.
|
99
|
-
@r.
|
121
|
+
it "should be able to RENAMENX a key" do
|
122
|
+
@r.del 'foo'
|
123
|
+
@r.del 'bar'
|
100
124
|
@r['foo'] = 'hi'
|
101
125
|
@r['bar'] = 'ohai'
|
102
|
-
|
126
|
+
@r.renamenx 'foo', 'bar'
|
103
127
|
@r['bar'].should == 'ohai'
|
104
128
|
end
|
105
129
|
#
|
@@ -114,268 +138,270 @@ describe "redis" do
|
|
114
138
|
#
|
115
139
|
it "should be able to EXPIRE a key" do
|
116
140
|
@r['foo'] = 'bar'
|
117
|
-
@r.expire
|
141
|
+
@r.expire 'foo', 1
|
118
142
|
@r['foo'].should == "bar"
|
119
143
|
sleep 2
|
120
144
|
@r['foo'].should == nil
|
121
145
|
end
|
122
146
|
#
|
123
|
-
it "should be able to EXISTS
|
147
|
+
it "should be able to EXISTS" do
|
124
148
|
@r['foo'] = 'nik'
|
125
|
-
@r.
|
126
|
-
@r.
|
127
|
-
@r.
|
149
|
+
@r.exists('foo').should be_true
|
150
|
+
@r.del 'foo'
|
151
|
+
@r.exists('foo').should be_false
|
128
152
|
end
|
129
153
|
#
|
130
|
-
it "should be able to KEYS
|
131
|
-
@r.keys("f*").each
|
132
|
-
@r.delete key
|
133
|
-
end
|
154
|
+
it "should be able to KEYS" do
|
155
|
+
@r.keys("f*").each { |key| @r.del key }
|
134
156
|
@r['f'] = 'nik'
|
135
157
|
@r['fo'] = 'nak'
|
136
158
|
@r['foo'] = 'qux'
|
137
159
|
@r.keys("f*").sort.should == ['f','fo', 'foo'].sort
|
138
160
|
end
|
139
|
-
#
|
161
|
+
#
|
162
|
+
it "should be able to return a random key (RANDOMKEY)" do
|
163
|
+
3.times { @r.exists(@r.randomkey).should be_true }
|
164
|
+
end
|
165
|
+
#
|
140
166
|
it "should be able to check the TYPE of a key" do
|
141
167
|
@r['foo'] = 'nik'
|
142
|
-
@r.type
|
143
|
-
@r.
|
144
|
-
@r.type
|
168
|
+
@r.type('foo').should == "string"
|
169
|
+
@r.del 'foo'
|
170
|
+
@r.type('foo').should == "none"
|
145
171
|
end
|
146
172
|
#
|
147
|
-
it "should be able to push to the head of a list" do
|
148
|
-
@r.
|
149
|
-
@r.
|
150
|
-
@r.type
|
151
|
-
@r.
|
152
|
-
@r.
|
153
|
-
@r.delete('list')
|
173
|
+
it "should be able to push to the head of a list (LPUSH)" do
|
174
|
+
@r.lpush "list", 'hello'
|
175
|
+
@r.lpush "list", 42
|
176
|
+
@r.type('list').should == "list"
|
177
|
+
@r.llen('list').should == 2
|
178
|
+
@r.lpop('list').should == '42'
|
154
179
|
end
|
155
180
|
#
|
156
|
-
it "should be able to push to the tail of a list" do
|
157
|
-
@r.
|
158
|
-
@r.type
|
159
|
-
@r.
|
160
|
-
@r.delete('list')
|
181
|
+
it "should be able to push to the tail of a list (RPUSH)" do
|
182
|
+
@r.rpush "list", 'hello'
|
183
|
+
@r.type('list').should == "list"
|
184
|
+
@r.llen('list').should == 1
|
161
185
|
end
|
162
186
|
#
|
163
|
-
it "should be able to pop the tail of a list" do
|
164
|
-
@r.
|
165
|
-
@r.
|
166
|
-
@r.type
|
167
|
-
@r.
|
168
|
-
@r.
|
169
|
-
@r.delete('list')
|
187
|
+
it "should be able to pop the tail of a list (RPOP)" do
|
188
|
+
@r.rpush "list", 'hello'
|
189
|
+
@r.rpush"list", 'goodbye'
|
190
|
+
@r.type('list').should == "list"
|
191
|
+
@r.llen('list').should == 2
|
192
|
+
@r.rpop('list').should == 'goodbye'
|
170
193
|
end
|
171
194
|
#
|
172
|
-
it "should be able to pop the head of a list" do
|
173
|
-
@r.
|
174
|
-
@r.
|
175
|
-
@r.type
|
176
|
-
@r.
|
177
|
-
@r.
|
178
|
-
@r.delete('list')
|
195
|
+
it "should be able to pop the head of a list (LPOP)" do
|
196
|
+
@r.rpush "list", 'hello'
|
197
|
+
@r.rpush "list", 'goodbye'
|
198
|
+
@r.type('list').should == "list"
|
199
|
+
@r.llen('list').should == 2
|
200
|
+
@r.lpop('list').should == 'hello'
|
179
201
|
end
|
180
202
|
#
|
181
|
-
it "should be able to get the length of a list" do
|
182
|
-
@r.
|
183
|
-
@r.
|
184
|
-
@r.type
|
185
|
-
@r.
|
186
|
-
@r.delete('list')
|
203
|
+
it "should be able to get the length of a list (LLEN)" do
|
204
|
+
@r.rpush "list", 'hello'
|
205
|
+
@r.rpush "list", 'goodbye'
|
206
|
+
@r.type('list').should == "list"
|
207
|
+
@r.llen('list').should == 2
|
187
208
|
end
|
188
209
|
#
|
189
|
-
it "should be able to get a range of values from a list" do
|
190
|
-
@r.
|
191
|
-
@r.
|
192
|
-
@r.
|
193
|
-
@r.
|
194
|
-
@r.
|
195
|
-
@r.type
|
196
|
-
@r.
|
197
|
-
@r.
|
198
|
-
@r.delete('list')
|
210
|
+
it "should be able to get a range of values from a list (LRANGE)" do
|
211
|
+
@r.rpush "list", 'hello'
|
212
|
+
@r.rpush "list", 'goodbye'
|
213
|
+
@r.rpush "list", '1'
|
214
|
+
@r.rpush "list", '2'
|
215
|
+
@r.rpush "list", '3'
|
216
|
+
@r.type('list').should == "list"
|
217
|
+
@r.llen('list').should == 5
|
218
|
+
@r.lrange('list', 2, -1).should == ['1', '2', '3']
|
199
219
|
end
|
200
220
|
#
|
201
|
-
it "should be able to trim a list" do
|
202
|
-
@r.
|
203
|
-
@r.
|
204
|
-
@r.
|
205
|
-
@r.
|
206
|
-
@r.
|
207
|
-
@r.type
|
208
|
-
@r.
|
209
|
-
@r.
|
210
|
-
@r.
|
211
|
-
@r.
|
212
|
-
@r.delete('list')
|
221
|
+
it "should be able to trim a list (LTRIM)" do
|
222
|
+
@r.rpush "list", 'hello'
|
223
|
+
@r.rpush "list", 'goodbye'
|
224
|
+
@r.rpush "list", '1'
|
225
|
+
@r.rpush "list", '2'
|
226
|
+
@r.rpush "list", '3'
|
227
|
+
@r.type('list').should == "list"
|
228
|
+
@r.llen('list').should == 5
|
229
|
+
@r.ltrim 'list', 0, 1
|
230
|
+
@r.llen('list').should == 2
|
231
|
+
@r.lrange('list', 0, -1).should == ['hello', 'goodbye']
|
213
232
|
end
|
214
233
|
#
|
215
|
-
it "should be able to get a value by indexing into a list" do
|
216
|
-
@r.
|
217
|
-
@r.
|
218
|
-
@r.type
|
219
|
-
@r.
|
220
|
-
@r.
|
221
|
-
@r.delete('list')
|
234
|
+
it "should be able to get a value by indexing into a list (LINDEX)" do
|
235
|
+
@r.rpush "list", 'hello'
|
236
|
+
@r.rpush "list", 'goodbye'
|
237
|
+
@r.type('list').should == "list"
|
238
|
+
@r.llen('list').should == 2
|
239
|
+
@r.lindex('list', 1).should == 'goodbye'
|
222
240
|
end
|
223
241
|
#
|
224
|
-
it "should be able to set a value by indexing into a list" do
|
225
|
-
@r.
|
226
|
-
@r.
|
227
|
-
@r.type
|
228
|
-
@r.
|
229
|
-
@r.
|
230
|
-
@r.
|
231
|
-
@r.delete('list')
|
242
|
+
it "should be able to set a value by indexing into a list (LSET)" do
|
243
|
+
@r.rpush "list", 'hello'
|
244
|
+
@r.rpush "list", 'hello'
|
245
|
+
@r.type('list').should == "list"
|
246
|
+
@r.llen('list').should == 2
|
247
|
+
@r.lset('list', 1, 'goodbye').should == 'OK'
|
248
|
+
@r.lindex('list', 1).should == 'goodbye'
|
232
249
|
end
|
233
250
|
#
|
234
|
-
it "should be able to remove values from a list LREM" do
|
235
|
-
@r.
|
236
|
-
@r.
|
237
|
-
@r.type
|
238
|
-
@r.
|
239
|
-
@r.
|
240
|
-
@r.
|
241
|
-
@r.delete('list')
|
251
|
+
it "should be able to remove values from a list (LREM)" do
|
252
|
+
@r.rpush "list", 'hello'
|
253
|
+
@r.rpush "list", 'goodbye'
|
254
|
+
@r.type('list').should == "list"
|
255
|
+
@r.llen('list').should == 2
|
256
|
+
@r.lrem('list', 1, 'hello').should == 1
|
257
|
+
@r.lrange('list', 0, -1).should == ['goodbye']
|
242
258
|
end
|
243
259
|
#
|
244
|
-
it "should be able add members to a set" do
|
245
|
-
@r.
|
246
|
-
@r.
|
247
|
-
@r.type
|
248
|
-
@r.
|
249
|
-
@r.
|
250
|
-
@r.delete('set')
|
260
|
+
it "should be able add members to a set (SADD)" do
|
261
|
+
@r.sadd "set", 'key1'
|
262
|
+
@r.sadd "set", 'key2'
|
263
|
+
@r.type('set').should == "set"
|
264
|
+
@r.scard('set').should == 2
|
265
|
+
@r.smembers('set').sort.should == ['key1', 'key2'].sort
|
251
266
|
end
|
252
267
|
#
|
253
|
-
it "should be able delete members to a set" do
|
254
|
-
@r.
|
255
|
-
@r.
|
256
|
-
@r.type
|
257
|
-
@r.
|
258
|
-
@r.
|
259
|
-
@r.
|
260
|
-
@r.
|
261
|
-
@r.
|
262
|
-
@r.delete('set')
|
268
|
+
it "should be able delete members to a set (SREM)" do
|
269
|
+
@r.sadd "set", 'key1'
|
270
|
+
@r.sadd "set", 'key2'
|
271
|
+
@r.type('set').should == "set"
|
272
|
+
@r.scard('set').should == 2
|
273
|
+
@r.smembers('set').sort.should == ['key1', 'key2'].sort
|
274
|
+
@r.srem('set', 'key1')
|
275
|
+
@r.scard('set').should == 1
|
276
|
+
@r.smembers('set').should == ['key2']
|
263
277
|
end
|
264
278
|
#
|
265
|
-
it "should be able count the members of a set" do
|
266
|
-
@r.
|
267
|
-
@r.
|
268
|
-
@r.type
|
269
|
-
@r.
|
270
|
-
@r.delete('set')
|
279
|
+
it "should be able count the members of a set (SCARD)" do
|
280
|
+
@r.sadd "set", 'key1'
|
281
|
+
@r.sadd "set", 'key2'
|
282
|
+
@r.type('set').should == "set"
|
283
|
+
@r.scard('set').should == 2
|
271
284
|
end
|
272
285
|
#
|
273
|
-
it "should be able test for set membership" do
|
274
|
-
@r.
|
275
|
-
@r.
|
276
|
-
@r.type
|
277
|
-
@r.
|
278
|
-
@r.
|
279
|
-
@r.
|
280
|
-
@r.
|
281
|
-
@r.delete('set')
|
286
|
+
it "should be able test for set membership (SISMEMBER)" do
|
287
|
+
@r.sadd "set", 'key1'
|
288
|
+
@r.sadd "set", 'key2'
|
289
|
+
@r.type('set').should == "set"
|
290
|
+
@r.scard('set').should == 2
|
291
|
+
@r.sismember('set', 'key1').should be_true
|
292
|
+
@r.sismember('set', 'key2').should be_true
|
293
|
+
@r.sismember('set', 'notthere').should be_false
|
282
294
|
end
|
283
295
|
#
|
284
|
-
it "should be able to do set intersection" do
|
285
|
-
@r.
|
286
|
-
@r.
|
287
|
-
@r.
|
288
|
-
@r.
|
289
|
-
@r.delete('set')
|
296
|
+
it "should be able to do set intersection (SINTER)" do
|
297
|
+
@r.sadd "set", 'key1'
|
298
|
+
@r.sadd "set", 'key2'
|
299
|
+
@r.sadd "set2", 'key2'
|
300
|
+
@r.sinter('set', 'set2').should == ['key2']
|
290
301
|
end
|
291
302
|
#
|
292
|
-
it "should be able to do set intersection and store the results in a key" do
|
293
|
-
@r.
|
294
|
-
@r.
|
295
|
-
@r.
|
296
|
-
@r.
|
297
|
-
@r.
|
298
|
-
@r.delete('set')
|
303
|
+
it "should be able to do set intersection and store the results in a key (SINTERSTORE)" do
|
304
|
+
@r.sadd "set", 'key1'
|
305
|
+
@r.sadd "set", 'key2'
|
306
|
+
@r.sadd "set2", 'key2'
|
307
|
+
@r.sinterstore('newone', 'set', 'set2').should == 1
|
308
|
+
@r.smembers('newone').should == ['key2']
|
299
309
|
end
|
300
310
|
#
|
301
|
-
it "should be able to do set union" do
|
302
|
-
@r.
|
303
|
-
@r.
|
304
|
-
@r.
|
305
|
-
@r.
|
306
|
-
@r.
|
307
|
-
@r.delete('set')
|
311
|
+
it "should be able to do set union (SUNION)" do
|
312
|
+
@r.sadd "set", 'key1'
|
313
|
+
@r.sadd "set", 'key2'
|
314
|
+
@r.sadd "set2", 'key2'
|
315
|
+
@r.sadd "set2", 'key3'
|
316
|
+
@r.sunion('set', 'set2').sort.should == ['key1','key2','key3'].sort
|
308
317
|
end
|
309
318
|
#
|
310
|
-
it "should be able to do set union and store the results in a key" do
|
311
|
-
@r.
|
312
|
-
@r.
|
313
|
-
@r.
|
314
|
-
@r.
|
315
|
-
@r.
|
316
|
-
@r.
|
317
|
-
@r.delete('set')
|
319
|
+
it "should be able to do set union and store the results in a key (SUNIONSTORE)" do
|
320
|
+
@r.sadd "set", 'key1'
|
321
|
+
@r.sadd "set", 'key2'
|
322
|
+
@r.sadd "set2", 'key2'
|
323
|
+
@r.sadd "set2", 'key3'
|
324
|
+
@r.sunionstore('newone', 'set', 'set2').should == 3
|
325
|
+
@r.smembers('newone').sort.should == ['key1','key2','key3'].sort
|
318
326
|
end
|
319
|
-
|
320
|
-
# these don't seem to be implemented in redis head?
|
321
|
-
# it "should be able to do set difference" do
|
322
|
-
# @r.set_add "set", 'key1'
|
323
|
-
# @r.set_add "set", 'key2'
|
324
|
-
# @r.set_add "set2", 'key2'
|
325
|
-
# @r.set_add "set2", 'key3'
|
326
|
-
# @r.set_diff('set', 'set2').should == Set.new(['key1','key3'])
|
327
|
-
# @r.delete('set')
|
328
|
-
# end
|
329
|
-
# #
|
330
|
-
# it "should be able to do set difference and store the results in a key" do
|
331
|
-
# @r.set_add "set", 'key1'
|
332
|
-
# @r.set_add "set", 'key2'
|
333
|
-
# @r.set_add "set2", 'key2'
|
334
|
-
# @r.set_add "set2", 'key3'
|
335
|
-
# count = @r.set_diff_store('newone', 'set', 'set2')
|
336
|
-
# count.should == 3
|
337
|
-
# @r.set_members('newone').should == Set.new(['key1','key3'])
|
338
|
-
# @r.delete('set')
|
339
|
-
# end
|
340
327
|
#
|
341
|
-
it "should be able
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
328
|
+
it "should be able to do set difference (SDIFF)" do
|
329
|
+
@r.sadd "set", 'a'
|
330
|
+
@r.sadd "set", 'b'
|
331
|
+
@r.sadd "set2", 'b'
|
332
|
+
@r.sadd "set2", 'c'
|
333
|
+
@r.sdiff('set', 'set2').should == ['a']
|
334
|
+
end
|
335
|
+
#
|
336
|
+
it "should be able to do set difference and store the results in a key (SDIFFSTORE)" do
|
337
|
+
@r.sadd "set", 'a'
|
338
|
+
@r.sadd "set", 'b'
|
339
|
+
@r.sadd "set2", 'b'
|
340
|
+
@r.sadd "set2", 'c'
|
341
|
+
@r.sdiffstore('newone', 'set', 'set2')
|
342
|
+
@r.smembers('newone').should == ['a']
|
343
|
+
end
|
344
|
+
#
|
345
|
+
it "should be able move elements from one set to another (SMOVE)" do
|
346
|
+
@r.sadd 'set1', 'a'
|
347
|
+
@r.sadd 'set1', 'b'
|
348
|
+
@r.sadd 'set2', 'x'
|
349
|
+
@r.smove('set1', 'set2', 'a').should be_true
|
350
|
+
@r.sismember('set2', 'a').should be_true
|
347
351
|
@r.delete('set1')
|
348
352
|
end
|
349
353
|
#
|
350
354
|
it "should be able to do crazy SORT queries" do
|
355
|
+
# The 'Dogs' is capitialized on purpose
|
351
356
|
@r['dog_1'] = 'louie'
|
352
|
-
@r.
|
357
|
+
@r.rpush 'Dogs', 1
|
353
358
|
@r['dog_2'] = 'lucy'
|
354
|
-
@r.
|
359
|
+
@r.rpush 'Dogs', 2
|
355
360
|
@r['dog_3'] = 'max'
|
356
|
-
@r.
|
361
|
+
@r.rpush 'Dogs', 3
|
357
362
|
@r['dog_4'] = 'taj'
|
358
|
-
@r.
|
359
|
-
@r.sort('
|
360
|
-
@r.sort('
|
363
|
+
@r.rpush 'Dogs', 4
|
364
|
+
@r.sort('Dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
|
365
|
+
@r.sort('Dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should be able to handle array of :get using SORT" do
|
369
|
+
@r['dog:1:name'] = 'louie'
|
370
|
+
@r['dog:1:breed'] = 'mutt'
|
371
|
+
@r.rpush 'dogs', 1
|
372
|
+
@r['dog:2:name'] = 'lucy'
|
373
|
+
@r['dog:2:breed'] = 'poodle'
|
374
|
+
@r.rpush 'dogs', 2
|
375
|
+
@r['dog:3:name'] = 'max'
|
376
|
+
@r['dog:3:breed'] = 'hound'
|
377
|
+
@r.rpush 'dogs', 3
|
378
|
+
@r['dog:4:name'] = 'taj'
|
379
|
+
@r['dog:4:breed'] = 'terrier'
|
380
|
+
@r.rpush 'dogs', 4
|
381
|
+
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1]).should == ['louie', 'mutt']
|
382
|
+
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha').should == ['taj', 'terrier']
|
361
383
|
end
|
362
384
|
#
|
363
|
-
it "should provide info" do
|
385
|
+
it "should provide info (INFO)" do
|
364
386
|
[:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
|
365
387
|
@r.info.keys.should include(x)
|
366
388
|
end
|
367
389
|
end
|
368
390
|
#
|
369
|
-
it "should be able to flush the database" do
|
391
|
+
it "should be able to flush the database (FLUSHDB)" do
|
370
392
|
@r['key1'] = 'keyone'
|
371
393
|
@r['key2'] = 'keytwo'
|
372
|
-
@r.keys('*').sort.should == ['foo', 'key1', 'key2'] #foo from before
|
373
|
-
@r.
|
394
|
+
@r.keys('*').sort.should == ['foo', 'key1', 'key2'].sort #foo from before
|
395
|
+
@r.flushdb
|
374
396
|
@r.keys('*').should == []
|
375
397
|
end
|
376
|
-
#
|
377
|
-
it "should
|
378
|
-
|
398
|
+
#
|
399
|
+
it "should raise exception when manually try to change the database" do
|
400
|
+
lambda { @r.select(0) }.should raise_error
|
401
|
+
end
|
402
|
+
#
|
403
|
+
it "should be able to provide the last save time (LASTSAVE)" do
|
404
|
+
savetime = @r.lastsave
|
379
405
|
Time.at(savetime).class.should == Time
|
380
406
|
Time.at(savetime).should <= Time.now
|
381
407
|
end
|
@@ -388,13 +414,24 @@ describe "redis" do
|
|
388
414
|
end
|
389
415
|
|
390
416
|
it "should bgsave" do
|
391
|
-
|
417
|
+
@r.bgsave.should == 'OK'
|
392
418
|
end
|
393
419
|
|
420
|
+
it "should be able to ECHO" do
|
421
|
+
@r.echo("message in a bottle\n").should == "message in a bottle\n"
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should raise error when invoke MONITOR" do
|
425
|
+
lambda { @r.monitor }.should raise_error
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should raise error when invoke SYNC" do
|
429
|
+
lambda { @r.sync }.should raise_error
|
430
|
+
end
|
431
|
+
|
394
432
|
it "should handle multiple servers" do
|
395
433
|
require 'dist_redis'
|
396
|
-
@r = DistRedis.new('localhost:6379', '127.0.0.1:6379')
|
397
|
-
@r.select_db(15) # use database 15 for testing so we dont accidentally step on you real data
|
434
|
+
@r = DistRedis.new(:hosts=> ['localhost:6379', '127.0.0.1:6379'], :db => 15)
|
398
435
|
|
399
436
|
100.times do |idx|
|
400
437
|
@r[idx] = "foo#{idx}"
|
@@ -407,13 +444,20 @@ describe "redis" do
|
|
407
444
|
|
408
445
|
it "should be able to pipeline writes" do
|
409
446
|
@r.pipelined do |pipeline|
|
410
|
-
pipeline.
|
411
|
-
pipeline.
|
447
|
+
pipeline.lpush 'list', "hello"
|
448
|
+
pipeline.lpush 'list', 42
|
412
449
|
end
|
413
450
|
|
414
|
-
@r.type
|
415
|
-
@r.
|
416
|
-
@r.
|
417
|
-
@r.delete('list')
|
451
|
+
@r.type('list').should == "list"
|
452
|
+
@r.llen('list').should == 2
|
453
|
+
@r.lpop('list').should == '42'
|
418
454
|
end
|
455
|
+
|
456
|
+
it "should AUTH when connecting with a password" do
|
457
|
+
r = Redis.new(:password => 'secret')
|
458
|
+
r.stub!(:connect_to)
|
459
|
+
r.should_receive(:call_command).with(['auth', 'secret'])
|
460
|
+
r.connect_to_server
|
461
|
+
end
|
462
|
+
|
419
463
|
end
|