redis 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -1
- data/README.md +18 -0
- data/Rakefile +3 -5
- data/TODO.md +4 -0
- data/lib/redis.rb +135 -119
- data/lib/redis/client.rb +29 -6
- data/lib/redis/connection/command_helper.rb +2 -2
- data/lib/redis/connection/ruby.rb +6 -2
- data/lib/redis/connection/synchrony.rb +9 -5
- data/lib/redis/distributed.rb +9 -2
- data/lib/redis/pipeline.rb +16 -1
- data/lib/redis/subscribe.rb +19 -4
- data/lib/redis/version.rb +1 -1
- data/test/connection_handling_test.rb +2 -1
- data/test/distributed_internals_test.rb +10 -1
- data/test/distributed_remote_server_control_commands_test.rb +12 -0
- data/test/distributed_test.rb +0 -1
- data/test/error_replies_test.rb +1 -1
- data/test/internals_test.rb +4 -1
- data/test/lint/internals.rb +0 -4
- data/test/remote_server_control_commands_test.rb +19 -0
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
# 2.2.
|
1
|
+
# 2.2.2 (unreleased)
|
2
|
+
|
3
|
+
# 2.2.1
|
4
|
+
|
5
|
+
* Internal API: Client#call and family are now called with a single array
|
6
|
+
argument, since splatting a large number of arguments (100K+) results in a
|
7
|
+
stack overflow on 1.9.2.
|
8
|
+
|
9
|
+
* The `INFO` command can optionally take a subcommand. When the subcommand is
|
10
|
+
`COMMANDSTATS`, the client will properly format the returned statistics per
|
11
|
+
command. Subcommands for `INFO` are available since Redis v2.3.0 (unstable).
|
12
|
+
|
13
|
+
* Change `IO#syswrite` back to the buffered `IO#write` since some Rubies do
|
14
|
+
short writes for large (1MB+) buffers and some don't (see issue #108).
|
15
|
+
|
16
|
+
# 2.2.0
|
2
17
|
|
3
18
|
* Added method `Redis#without_reconnect` that ensures the client will not try
|
4
19
|
to reconnect when running the code inside the specified block.
|
data/README.md
CHANGED
@@ -185,6 +185,24 @@ This library (v2.2) is tested against the following interpreters:
|
|
185
185
|
|
186
186
|
Check the [Redis Command Reference](http://redis.io/commands) or check the tests to find out how to use this client.
|
187
187
|
|
188
|
+
## Contributors
|
189
|
+
|
190
|
+
(ordered chronologically with more than 5 commits, see `git shortlog -sn` for
|
191
|
+
all contributors)
|
192
|
+
|
193
|
+
* Ezra Zygmuntowicz
|
194
|
+
* Taylor Weibley
|
195
|
+
* Matthew Clark
|
196
|
+
* Brian McKinney
|
197
|
+
* Luca Guidi
|
198
|
+
* Salvatore Sanfillipo
|
199
|
+
* Chris Wanstrath
|
200
|
+
* Damian Janowski
|
201
|
+
* Michel Martens
|
202
|
+
* Nick Quaranto
|
203
|
+
* Pieter Noordhuis
|
204
|
+
* Ilya Grigorik
|
205
|
+
|
188
206
|
## Contributing
|
189
207
|
|
190
208
|
[Fork the project](http://github.com/ezmobius/redis-rb) and send pull requests. You can also ask for help at `#redis-rb` on Freenode.
|
data/Rakefile
CHANGED
@@ -65,7 +65,7 @@ namespace :test do
|
|
65
65
|
puts "Running tests against hiredis v#{Hiredis::VERSION}"
|
66
66
|
|
67
67
|
Cutest.run(Dir["./test/**/*_test.rb"])
|
68
|
-
rescue
|
68
|
+
rescue LoadError
|
69
69
|
puts "Skipping tests against hiredis"
|
70
70
|
end
|
71
71
|
end
|
@@ -87,9 +87,7 @@ namespace :test do
|
|
87
87
|
|
88
88
|
threaded_tests = ['./test/thread_safety_test.rb']
|
89
89
|
Cutest.run(Dir['./test/**/*_test.rb'] - threaded_tests)
|
90
|
-
rescue
|
91
|
-
puts e
|
92
|
-
puts e.backtrace.join("\n")
|
90
|
+
rescue LoadError
|
93
91
|
puts "Skipping tests against em-synchrony"
|
94
92
|
end
|
95
93
|
end
|
@@ -189,7 +187,7 @@ namespace :doc do
|
|
189
187
|
end
|
190
188
|
|
191
189
|
task :deploy do
|
192
|
-
system "rsync --del -avz doc
|
190
|
+
system "rsync --del -avz doc/ redis-rb.keyvalue.org:deploys/redis-rb.keyvalue.org/"
|
193
191
|
end
|
194
192
|
end
|
195
193
|
|
data/TODO.md
ADDED
data/lib/redis.rb
CHANGED
@@ -72,7 +72,7 @@ class Redis
|
|
72
72
|
# Authenticate to the server.
|
73
73
|
def auth(password)
|
74
74
|
synchronize do
|
75
|
-
@client.call
|
75
|
+
@client.call [:auth, password]
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -80,26 +80,33 @@ class Redis
|
|
80
80
|
def select(db)
|
81
81
|
synchronize do
|
82
82
|
@client.db = db
|
83
|
-
@client.call
|
83
|
+
@client.call [:select, db]
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
# Get information and statistics about the server.
|
88
|
-
def info
|
88
|
+
def info(cmd = nil)
|
89
89
|
synchronize do
|
90
|
-
reply = @client.call
|
90
|
+
reply = @client.call [:info, cmd].compact
|
91
91
|
|
92
92
|
if reply.kind_of?(String)
|
93
|
-
Hash[*reply.split(/:|\r\n/).grep(/^[^#]/)]
|
94
|
-
|
95
|
-
|
93
|
+
reply = Hash[*reply.split(/:|\r\n/).grep(/^[^#]/)]
|
94
|
+
|
95
|
+
if cmd && cmd.to_s == "commandstats"
|
96
|
+
# Extract nested hashes for INFO COMMANDSTATS
|
97
|
+
reply = Hash[reply.map do |k, v|
|
98
|
+
[k[/^cmdstat_(.*)$/, 1], Hash[*v.split(/,|=/)]]
|
99
|
+
end]
|
100
|
+
end
|
96
101
|
end
|
102
|
+
|
103
|
+
reply
|
97
104
|
end
|
98
105
|
end
|
99
106
|
|
100
107
|
def config(action, *args)
|
101
108
|
synchronize do
|
102
|
-
reply = @client.call
|
109
|
+
reply = @client.call [:config, action, *args]
|
103
110
|
|
104
111
|
if reply.kind_of?(Array) && action == :get
|
105
112
|
Hash[*reply]
|
@@ -112,97 +119,97 @@ class Redis
|
|
112
119
|
# Remove all keys from the current database.
|
113
120
|
def flushdb
|
114
121
|
synchronize do
|
115
|
-
@client.call
|
122
|
+
@client.call [:flushdb]
|
116
123
|
end
|
117
124
|
end
|
118
125
|
|
119
126
|
# Remove all keys from all databases.
|
120
127
|
def flushall
|
121
128
|
synchronize do
|
122
|
-
@client.call
|
129
|
+
@client.call [:flushall]
|
123
130
|
end
|
124
131
|
end
|
125
132
|
|
126
133
|
# Synchronously save the dataset to disk.
|
127
134
|
def save
|
128
135
|
synchronize do
|
129
|
-
@client.call
|
136
|
+
@client.call [:save]
|
130
137
|
end
|
131
138
|
end
|
132
139
|
|
133
140
|
# Asynchronously save the dataset to disk.
|
134
141
|
def bgsave
|
135
142
|
synchronize do
|
136
|
-
@client.call
|
143
|
+
@client.call [:bgsave]
|
137
144
|
end
|
138
145
|
end
|
139
146
|
|
140
147
|
# Asynchronously rewrite the append-only file.
|
141
148
|
def bgrewriteaof
|
142
149
|
synchronize do
|
143
|
-
@client.call
|
150
|
+
@client.call [:bgrewriteaof]
|
144
151
|
end
|
145
152
|
end
|
146
153
|
|
147
154
|
# Get the value of a key.
|
148
155
|
def get(key)
|
149
156
|
synchronize do
|
150
|
-
@client.call
|
157
|
+
@client.call [:get, key]
|
151
158
|
end
|
152
159
|
end
|
153
160
|
|
154
161
|
# Returns the bit value at offset in the string value stored at key.
|
155
162
|
def getbit(key, offset)
|
156
163
|
synchronize do
|
157
|
-
@client.call
|
164
|
+
@client.call [:getbit, key, offset]
|
158
165
|
end
|
159
166
|
end
|
160
167
|
|
161
168
|
# Get a substring of the string stored at a key.
|
162
169
|
def getrange(key, start, stop)
|
163
170
|
synchronize do
|
164
|
-
@client.call
|
171
|
+
@client.call [:getrange, key, start, stop]
|
165
172
|
end
|
166
173
|
end
|
167
174
|
|
168
175
|
# Set the string value of a key and return its old value.
|
169
176
|
def getset(key, value)
|
170
177
|
synchronize do
|
171
|
-
@client.call
|
178
|
+
@client.call [:getset, key, value]
|
172
179
|
end
|
173
180
|
end
|
174
181
|
|
175
182
|
# Get the values of all the given keys.
|
176
183
|
def mget(*keys)
|
177
184
|
synchronize do
|
178
|
-
@client.call
|
185
|
+
@client.call [:mget, *keys]
|
179
186
|
end
|
180
187
|
end
|
181
188
|
|
182
189
|
# Append a value to a key.
|
183
190
|
def append(key, value)
|
184
191
|
synchronize do
|
185
|
-
@client.call
|
192
|
+
@client.call [:append, key, value]
|
186
193
|
end
|
187
194
|
end
|
188
195
|
|
189
196
|
def substr(key, start, stop)
|
190
197
|
synchronize do
|
191
|
-
@client.call
|
198
|
+
@client.call [:substr, key, start, stop]
|
192
199
|
end
|
193
200
|
end
|
194
201
|
|
195
202
|
# Get the length of the value stored in a key.
|
196
203
|
def strlen(key)
|
197
204
|
synchronize do
|
198
|
-
@client.call
|
205
|
+
@client.call [:strlen, key]
|
199
206
|
end
|
200
207
|
end
|
201
208
|
|
202
209
|
# Get all the fields and values in a hash.
|
203
210
|
def hgetall(key)
|
204
211
|
synchronize do
|
205
|
-
reply = @client.call
|
212
|
+
reply = @client.call [:hgetall, key]
|
206
213
|
|
207
214
|
if reply.kind_of?(Array)
|
208
215
|
Hash[*reply]
|
@@ -215,28 +222,28 @@ class Redis
|
|
215
222
|
# Get the value of a hash field.
|
216
223
|
def hget(key, field)
|
217
224
|
synchronize do
|
218
|
-
@client.call
|
225
|
+
@client.call [:hget, key, field]
|
219
226
|
end
|
220
227
|
end
|
221
228
|
|
222
229
|
# Delete a hash field.
|
223
230
|
def hdel(key, field)
|
224
231
|
synchronize do
|
225
|
-
@client.call
|
232
|
+
@client.call [:hdel, key, field]
|
226
233
|
end
|
227
234
|
end
|
228
235
|
|
229
236
|
# Get all the fields in a hash.
|
230
237
|
def hkeys(key)
|
231
238
|
synchronize do
|
232
|
-
@client.call
|
239
|
+
@client.call [:hkeys, key]
|
233
240
|
end
|
234
241
|
end
|
235
242
|
|
236
243
|
# Find all keys matching the given pattern.
|
237
244
|
def keys(pattern = "*")
|
238
245
|
synchronize do
|
239
|
-
reply = @client.call
|
246
|
+
reply = @client.call [:keys, pattern]
|
240
247
|
|
241
248
|
if reply.kind_of?(String)
|
242
249
|
reply.split(" ")
|
@@ -249,126 +256,126 @@ class Redis
|
|
249
256
|
# Return a random key from the keyspace.
|
250
257
|
def randomkey
|
251
258
|
synchronize do
|
252
|
-
@client.call
|
259
|
+
@client.call [:randomkey]
|
253
260
|
end
|
254
261
|
end
|
255
262
|
|
256
263
|
# Echo the given string.
|
257
264
|
def echo(value)
|
258
265
|
synchronize do
|
259
|
-
@client.call
|
266
|
+
@client.call [:echo, value]
|
260
267
|
end
|
261
268
|
end
|
262
269
|
|
263
270
|
# Ping the server.
|
264
271
|
def ping
|
265
272
|
synchronize do
|
266
|
-
@client.call
|
273
|
+
@client.call [:ping]
|
267
274
|
end
|
268
275
|
end
|
269
276
|
|
270
277
|
# Get the UNIX time stamp of the last successful save to disk.
|
271
278
|
def lastsave
|
272
279
|
synchronize do
|
273
|
-
@client.call
|
280
|
+
@client.call [:lastsave]
|
274
281
|
end
|
275
282
|
end
|
276
283
|
|
277
284
|
# Return the number of keys in the selected database.
|
278
285
|
def dbsize
|
279
286
|
synchronize do
|
280
|
-
@client.call
|
287
|
+
@client.call [:dbsize]
|
281
288
|
end
|
282
289
|
end
|
283
290
|
|
284
291
|
# Determine if a key exists.
|
285
292
|
def exists(key)
|
286
293
|
synchronize do
|
287
|
-
_bool @client.call
|
294
|
+
_bool @client.call [:exists, key]
|
288
295
|
end
|
289
296
|
end
|
290
297
|
|
291
298
|
# Get the length of a list.
|
292
299
|
def llen(key)
|
293
300
|
synchronize do
|
294
|
-
@client.call
|
301
|
+
@client.call [:llen, key]
|
295
302
|
end
|
296
303
|
end
|
297
304
|
|
298
305
|
# Get a range of elements from a list.
|
299
306
|
def lrange(key, start, stop)
|
300
307
|
synchronize do
|
301
|
-
@client.call
|
308
|
+
@client.call [:lrange, key, start, stop]
|
302
309
|
end
|
303
310
|
end
|
304
311
|
|
305
312
|
# Trim a list to the specified range.
|
306
313
|
def ltrim(key, start, stop)
|
307
314
|
synchronize do
|
308
|
-
@client.call
|
315
|
+
@client.call [:ltrim, key, start, stop]
|
309
316
|
end
|
310
317
|
end
|
311
318
|
|
312
319
|
# Get an element from a list by its index.
|
313
320
|
def lindex(key, index)
|
314
321
|
synchronize do
|
315
|
-
@client.call
|
322
|
+
@client.call [:lindex, key, index]
|
316
323
|
end
|
317
324
|
end
|
318
325
|
|
319
326
|
# Insert an element before or after another element in a list.
|
320
327
|
def linsert(key, where, pivot, value)
|
321
328
|
synchronize do
|
322
|
-
@client.call
|
329
|
+
@client.call [:linsert, key, where, pivot, value]
|
323
330
|
end
|
324
331
|
end
|
325
332
|
|
326
333
|
# Set the value of an element in a list by its index.
|
327
334
|
def lset(key, index, value)
|
328
335
|
synchronize do
|
329
|
-
@client.call
|
336
|
+
@client.call [:lset, key, index, value]
|
330
337
|
end
|
331
338
|
end
|
332
339
|
|
333
340
|
# Remove elements from a list.
|
334
341
|
def lrem(key, count, value)
|
335
342
|
synchronize do
|
336
|
-
@client.call
|
343
|
+
@client.call [:lrem, key, count, value]
|
337
344
|
end
|
338
345
|
end
|
339
346
|
|
340
347
|
# Append a value to a list.
|
341
348
|
def rpush(key, value)
|
342
349
|
synchronize do
|
343
|
-
@client.call
|
350
|
+
@client.call [:rpush, key, value]
|
344
351
|
end
|
345
352
|
end
|
346
353
|
|
347
354
|
# Append a value to a list, only if the list exists.
|
348
355
|
def rpushx(key, value)
|
349
356
|
synchronize do
|
350
|
-
@client.call
|
357
|
+
@client.call [:rpushx, key, value]
|
351
358
|
end
|
352
359
|
end
|
353
360
|
|
354
361
|
# Prepend a value to a list.
|
355
362
|
def lpush(key, value)
|
356
363
|
synchronize do
|
357
|
-
@client.call
|
364
|
+
@client.call [:lpush, key, value]
|
358
365
|
end
|
359
366
|
end
|
360
367
|
|
361
368
|
# Prepend a value to a list, only if the list exists.
|
362
369
|
def lpushx(key, value)
|
363
370
|
synchronize do
|
364
|
-
@client.call
|
371
|
+
@client.call [:lpushx, key, value]
|
365
372
|
end
|
366
373
|
end
|
367
374
|
|
368
375
|
# Remove and get the last element in a list.
|
369
376
|
def rpop(key)
|
370
377
|
synchronize do
|
371
|
-
@client.call
|
378
|
+
@client.call [:rpop, key]
|
372
379
|
end
|
373
380
|
end
|
374
381
|
|
@@ -397,126 +404,126 @@ class Redis
|
|
397
404
|
# Remove the last element in a list, append it to another list and return it.
|
398
405
|
def rpoplpush(source, destination)
|
399
406
|
synchronize do
|
400
|
-
@client.call
|
407
|
+
@client.call [:rpoplpush, source, destination]
|
401
408
|
end
|
402
409
|
end
|
403
410
|
|
404
411
|
# Remove and get the first element in a list.
|
405
412
|
def lpop(key)
|
406
413
|
synchronize do
|
407
|
-
@client.call
|
414
|
+
@client.call [:lpop, key]
|
408
415
|
end
|
409
416
|
end
|
410
417
|
|
411
418
|
# Get all the members in a set.
|
412
419
|
def smembers(key)
|
413
420
|
synchronize do
|
414
|
-
@client.call
|
421
|
+
@client.call [:smembers, key]
|
415
422
|
end
|
416
423
|
end
|
417
424
|
|
418
425
|
# Determine if a given value is a member of a set.
|
419
426
|
def sismember(key, member)
|
420
427
|
synchronize do
|
421
|
-
_bool @client.call
|
428
|
+
_bool @client.call [:sismember, key, member]
|
422
429
|
end
|
423
430
|
end
|
424
431
|
|
425
432
|
# Add a member to a set.
|
426
433
|
def sadd(key, value)
|
427
434
|
synchronize do
|
428
|
-
_bool @client.call
|
435
|
+
_bool @client.call [:sadd, key, value]
|
429
436
|
end
|
430
437
|
end
|
431
438
|
|
432
439
|
# Remove a member from a set.
|
433
440
|
def srem(key, value)
|
434
441
|
synchronize do
|
435
|
-
_bool @client.call
|
442
|
+
_bool @client.call [:srem, key, value]
|
436
443
|
end
|
437
444
|
end
|
438
445
|
|
439
446
|
# Move a member from one set to another.
|
440
447
|
def smove(source, destination, member)
|
441
448
|
synchronize do
|
442
|
-
_bool @client.call
|
449
|
+
_bool @client.call [:smove, source, destination, member]
|
443
450
|
end
|
444
451
|
end
|
445
452
|
|
446
453
|
# Remove and return a random member from a set.
|
447
454
|
def spop(key)
|
448
455
|
synchronize do
|
449
|
-
@client.call
|
456
|
+
@client.call [:spop, key]
|
450
457
|
end
|
451
458
|
end
|
452
459
|
|
453
460
|
# Get the number of members in a set.
|
454
461
|
def scard(key)
|
455
462
|
synchronize do
|
456
|
-
@client.call
|
463
|
+
@client.call [:scard, key]
|
457
464
|
end
|
458
465
|
end
|
459
466
|
|
460
467
|
# Intersect multiple sets.
|
461
468
|
def sinter(*keys)
|
462
469
|
synchronize do
|
463
|
-
@client.call
|
470
|
+
@client.call [:sinter, *keys]
|
464
471
|
end
|
465
472
|
end
|
466
473
|
|
467
474
|
# Intersect multiple sets and store the resulting set in a key.
|
468
475
|
def sinterstore(destination, *keys)
|
469
476
|
synchronize do
|
470
|
-
@client.call
|
477
|
+
@client.call [:sinterstore, destination, *keys]
|
471
478
|
end
|
472
479
|
end
|
473
480
|
|
474
481
|
# Add multiple sets.
|
475
482
|
def sunion(*keys)
|
476
483
|
synchronize do
|
477
|
-
@client.call
|
484
|
+
@client.call [:sunion, *keys]
|
478
485
|
end
|
479
486
|
end
|
480
487
|
|
481
488
|
# Add multiple sets and store the resulting set in a key.
|
482
489
|
def sunionstore(destination, *keys)
|
483
490
|
synchronize do
|
484
|
-
@client.call
|
491
|
+
@client.call [:sunionstore, destination, *keys]
|
485
492
|
end
|
486
493
|
end
|
487
494
|
|
488
495
|
# Subtract multiple sets.
|
489
496
|
def sdiff(*keys)
|
490
497
|
synchronize do
|
491
|
-
@client.call
|
498
|
+
@client.call [:sdiff, *keys]
|
492
499
|
end
|
493
500
|
end
|
494
501
|
|
495
502
|
# Subtract multiple sets and store the resulting set in a key.
|
496
503
|
def sdiffstore(destination, *keys)
|
497
504
|
synchronize do
|
498
|
-
@client.call
|
505
|
+
@client.call [:sdiffstore, destination, *keys]
|
499
506
|
end
|
500
507
|
end
|
501
508
|
|
502
509
|
# Get a random member from a set.
|
503
510
|
def srandmember(key)
|
504
511
|
synchronize do
|
505
|
-
@client.call
|
512
|
+
@client.call [:srandmember, key]
|
506
513
|
end
|
507
514
|
end
|
508
515
|
|
509
516
|
# Add a member to a sorted set, or update its score if it already exists.
|
510
517
|
def zadd(key, score, member)
|
511
518
|
synchronize do
|
512
|
-
_bool @client.call
|
519
|
+
_bool @client.call [:zadd, key, score, member]
|
513
520
|
end
|
514
521
|
end
|
515
522
|
|
516
523
|
# Determine the index of a member in a sorted set.
|
517
524
|
def zrank(key, member)
|
518
525
|
synchronize do
|
519
|
-
@client.call
|
526
|
+
@client.call [:zrank, key, member]
|
520
527
|
end
|
521
528
|
end
|
522
529
|
|
@@ -524,21 +531,21 @@ class Redis
|
|
524
531
|
# high to low.
|
525
532
|
def zrevrank(key, member)
|
526
533
|
synchronize do
|
527
|
-
@client.call
|
534
|
+
@client.call [:zrevrank, key, member]
|
528
535
|
end
|
529
536
|
end
|
530
537
|
|
531
538
|
# Increment the score of a member in a sorted set.
|
532
539
|
def zincrby(key, increment, member)
|
533
540
|
synchronize do
|
534
|
-
@client.call
|
541
|
+
@client.call [:zincrby, key, increment, member]
|
535
542
|
end
|
536
543
|
end
|
537
544
|
|
538
545
|
# Get the number of members in a sorted set.
|
539
546
|
def zcard(key)
|
540
547
|
synchronize do
|
541
|
-
@client.call
|
548
|
+
@client.call [:zcard, key]
|
542
549
|
end
|
543
550
|
end
|
544
551
|
|
@@ -550,7 +557,7 @@ class Redis
|
|
550
557
|
end
|
551
558
|
|
552
559
|
synchronize do
|
553
|
-
@client.call
|
560
|
+
@client.call [:zrange, key, start, stop, *command.to_a]
|
554
561
|
end
|
555
562
|
end
|
556
563
|
|
@@ -563,14 +570,14 @@ class Redis
|
|
563
570
|
end
|
564
571
|
|
565
572
|
synchronize do
|
566
|
-
@client.call
|
573
|
+
@client.call [:zrangebyscore, key, min, max, *command.to_a]
|
567
574
|
end
|
568
575
|
end
|
569
576
|
|
570
577
|
# Count the members in a sorted set with scores within the given values.
|
571
578
|
def zcount(key, start, stop)
|
572
579
|
synchronize do
|
573
|
-
@client.call
|
580
|
+
@client.call [:zcount, key, start, stop]
|
574
581
|
end
|
575
582
|
end
|
576
583
|
|
@@ -583,7 +590,7 @@ class Redis
|
|
583
590
|
end
|
584
591
|
|
585
592
|
synchronize do
|
586
|
-
@client.call
|
593
|
+
@client.call [:zrevrange, key, start, stop, *command.to_a]
|
587
594
|
end
|
588
595
|
end
|
589
596
|
|
@@ -597,35 +604,35 @@ class Redis
|
|
597
604
|
end
|
598
605
|
|
599
606
|
synchronize do
|
600
|
-
@client.call
|
607
|
+
@client.call [:zrevrangebyscore, key, max, min, *command.to_a]
|
601
608
|
end
|
602
609
|
end
|
603
610
|
|
604
611
|
# Remove all members in a sorted set within the given scores.
|
605
612
|
def zremrangebyscore(key, min, max)
|
606
613
|
synchronize do
|
607
|
-
@client.call
|
614
|
+
@client.call [:zremrangebyscore, key, min, max]
|
608
615
|
end
|
609
616
|
end
|
610
617
|
|
611
618
|
# Remove all members in a sorted set within the given indexes.
|
612
619
|
def zremrangebyrank(key, start, stop)
|
613
620
|
synchronize do
|
614
|
-
@client.call
|
621
|
+
@client.call [:zremrangebyrank, key, start, stop]
|
615
622
|
end
|
616
623
|
end
|
617
624
|
|
618
625
|
# Get the score associated with the given member in a sorted set.
|
619
626
|
def zscore(key, member)
|
620
627
|
synchronize do
|
621
|
-
@client.call
|
628
|
+
@client.call [:zscore, key, member]
|
622
629
|
end
|
623
630
|
end
|
624
631
|
|
625
632
|
# Remove a member from a sorted set.
|
626
633
|
def zrem(key, member)
|
627
634
|
synchronize do
|
628
|
-
_bool @client.call
|
635
|
+
_bool @client.call [:zrem, key, member]
|
629
636
|
end
|
630
637
|
end
|
631
638
|
|
@@ -638,7 +645,7 @@ class Redis
|
|
638
645
|
end
|
639
646
|
|
640
647
|
synchronize do
|
641
|
-
@client.call
|
648
|
+
@client.call [:zinterstore, destination, keys.size, *(keys + command.to_a)]
|
642
649
|
end
|
643
650
|
end
|
644
651
|
|
@@ -650,91 +657,91 @@ class Redis
|
|
650
657
|
end
|
651
658
|
|
652
659
|
synchronize do
|
653
|
-
@client.call
|
660
|
+
@client.call [:zunionstore, destination, keys.size, *(keys + command.to_a)]
|
654
661
|
end
|
655
662
|
end
|
656
663
|
|
657
664
|
# Move a key to another database.
|
658
665
|
def move(key, db)
|
659
666
|
synchronize do
|
660
|
-
_bool @client.call
|
667
|
+
_bool @client.call [:move, key, db]
|
661
668
|
end
|
662
669
|
end
|
663
670
|
|
664
671
|
# Set the value of a key, only if the key does not exist.
|
665
672
|
def setnx(key, value)
|
666
673
|
synchronize do
|
667
|
-
_bool @client.call
|
674
|
+
_bool @client.call [:setnx, key, value]
|
668
675
|
end
|
669
676
|
end
|
670
677
|
|
671
678
|
# Delete a key.
|
672
679
|
def del(*keys)
|
673
680
|
synchronize do
|
674
|
-
@client.call
|
681
|
+
@client.call [:del, *keys]
|
675
682
|
end
|
676
683
|
end
|
677
684
|
|
678
685
|
# Rename a key.
|
679
686
|
def rename(old_name, new_name)
|
680
687
|
synchronize do
|
681
|
-
@client.call
|
688
|
+
@client.call [:rename, old_name, new_name]
|
682
689
|
end
|
683
690
|
end
|
684
691
|
|
685
692
|
# Rename a key, only if the new key does not exist.
|
686
693
|
def renamenx(old_name, new_name)
|
687
694
|
synchronize do
|
688
|
-
_bool @client.call
|
695
|
+
_bool @client.call [:renamenx, old_name, new_name]
|
689
696
|
end
|
690
697
|
end
|
691
698
|
|
692
699
|
# Set a key's time to live in seconds.
|
693
700
|
def expire(key, seconds)
|
694
701
|
synchronize do
|
695
|
-
_bool @client.call
|
702
|
+
_bool @client.call [:expire, key, seconds]
|
696
703
|
end
|
697
704
|
end
|
698
705
|
|
699
706
|
# Remove the expiration from a key.
|
700
707
|
def persist(key)
|
701
708
|
synchronize do
|
702
|
-
_bool @client.call
|
709
|
+
_bool @client.call [:persist, key]
|
703
710
|
end
|
704
711
|
end
|
705
712
|
|
706
713
|
# Get the time to live for a key.
|
707
714
|
def ttl(key)
|
708
715
|
synchronize do
|
709
|
-
@client.call
|
716
|
+
@client.call [:ttl, key]
|
710
717
|
end
|
711
718
|
end
|
712
719
|
|
713
720
|
# Set the expiration for a key as a UNIX timestamp.
|
714
721
|
def expireat(key, unix_time)
|
715
722
|
synchronize do
|
716
|
-
_bool @client.call
|
723
|
+
_bool @client.call [:expireat, key, unix_time]
|
717
724
|
end
|
718
725
|
end
|
719
726
|
|
720
727
|
# Set the string value of a hash field.
|
721
728
|
def hset(key, field, value)
|
722
729
|
synchronize do
|
723
|
-
_bool @client.call
|
730
|
+
_bool @client.call [:hset, key, field, value]
|
724
731
|
end
|
725
732
|
end
|
726
733
|
|
727
734
|
# Set the value of a hash field, only if the field does not exist.
|
728
735
|
def hsetnx(key, field, value)
|
729
736
|
synchronize do
|
730
|
-
_bool @client.call
|
737
|
+
_bool @client.call [:hsetnx, key, field, value]
|
731
738
|
end
|
732
739
|
end
|
733
740
|
|
734
741
|
# Set multiple hash fields to multiple values.
|
735
742
|
def hmset(key, *attrs)
|
736
743
|
synchronize do
|
737
|
-
@client.call
|
744
|
+
@client.call [:hmset, key, *attrs]
|
738
745
|
end
|
739
746
|
end
|
740
747
|
|
@@ -745,7 +752,7 @@ class Redis
|
|
745
752
|
# Get the values of all the given hash fields.
|
746
753
|
def hmget(key, *fields)
|
747
754
|
synchronize do
|
748
|
-
@client.call
|
755
|
+
@client.call [:hmget, key, *fields]
|
749
756
|
end
|
750
757
|
end
|
751
758
|
|
@@ -762,55 +769,61 @@ class Redis
|
|
762
769
|
# Get the number of fields in a hash.
|
763
770
|
def hlen(key)
|
764
771
|
synchronize do
|
765
|
-
@client.call
|
772
|
+
@client.call [:hlen, key]
|
766
773
|
end
|
767
774
|
end
|
768
775
|
|
769
776
|
# Get all the values in a hash.
|
770
777
|
def hvals(key)
|
771
778
|
synchronize do
|
772
|
-
@client.call
|
779
|
+
@client.call [:hvals, key]
|
773
780
|
end
|
774
781
|
end
|
775
782
|
|
776
783
|
# Increment the integer value of a hash field by the given number.
|
777
784
|
def hincrby(key, field, increment)
|
778
785
|
synchronize do
|
779
|
-
@client.call
|
786
|
+
@client.call [:hincrby, key, field, increment]
|
780
787
|
end
|
781
788
|
end
|
782
789
|
|
783
790
|
# Discard all commands issued after MULTI.
|
784
791
|
def discard
|
785
792
|
synchronize do
|
786
|
-
@client.call
|
793
|
+
@client.call [:discard]
|
787
794
|
end
|
788
795
|
end
|
789
796
|
|
790
797
|
# Determine if a hash field exists.
|
791
798
|
def hexists(key, field)
|
792
799
|
synchronize do
|
793
|
-
_bool @client.call
|
800
|
+
_bool @client.call [:hexists, key, field]
|
794
801
|
end
|
795
802
|
end
|
796
803
|
|
797
804
|
# Listen for all requests received by the server in real time.
|
798
805
|
def monitor(&block)
|
799
806
|
synchronize do
|
800
|
-
@client.call_loop(:monitor, &block)
|
807
|
+
@client.call_loop([:monitor], &block)
|
801
808
|
end
|
802
809
|
end
|
803
810
|
|
804
811
|
def debug(*args)
|
805
812
|
synchronize do
|
806
|
-
@client.call
|
813
|
+
@client.call [:debug, *args]
|
814
|
+
end
|
815
|
+
end
|
816
|
+
|
817
|
+
def object(*args)
|
818
|
+
synchronize do
|
819
|
+
@client.call [:object, *args]
|
807
820
|
end
|
808
821
|
end
|
809
822
|
|
810
823
|
# Internal command used for replication.
|
811
824
|
def sync
|
812
825
|
synchronize do
|
813
|
-
@client.call
|
826
|
+
@client.call [:sync]
|
814
827
|
end
|
815
828
|
end
|
816
829
|
|
@@ -825,35 +838,35 @@ class Redis
|
|
825
838
|
# Set the string value of a key.
|
826
839
|
def set(key, value)
|
827
840
|
synchronize do
|
828
|
-
@client.call
|
841
|
+
@client.call [:set, key, value]
|
829
842
|
end
|
830
843
|
end
|
831
844
|
|
832
845
|
# Sets or clears the bit at offset in the string value stored at key.
|
833
846
|
def setbit(key, offset, value)
|
834
847
|
synchronize do
|
835
|
-
@client.call
|
848
|
+
@client.call [:setbit, key, offset, value]
|
836
849
|
end
|
837
850
|
end
|
838
851
|
|
839
852
|
# Set the value and expiration of a key.
|
840
853
|
def setex(key, ttl, value)
|
841
854
|
synchronize do
|
842
|
-
@client.call
|
855
|
+
@client.call [:setex, key, ttl, value]
|
843
856
|
end
|
844
857
|
end
|
845
858
|
|
846
859
|
# Overwrite part of a string at key starting at the specified offset.
|
847
860
|
def setrange(key, offset, value)
|
848
861
|
synchronize do
|
849
|
-
@client.call
|
862
|
+
@client.call [:setrange, key, offset, value]
|
850
863
|
end
|
851
864
|
end
|
852
865
|
|
853
866
|
# Set multiple keys to multiple values.
|
854
867
|
def mset(*args)
|
855
868
|
synchronize do
|
856
|
-
@client.call
|
869
|
+
@client.call [:mset, *args]
|
857
870
|
end
|
858
871
|
end
|
859
872
|
|
@@ -864,7 +877,7 @@ class Redis
|
|
864
877
|
# Set multiple keys to multiple values, only if none of the keys exist.
|
865
878
|
def msetnx(*args)
|
866
879
|
synchronize do
|
867
|
-
@client.call
|
880
|
+
@client.call [:msetnx, *args]
|
868
881
|
end
|
869
882
|
end
|
870
883
|
|
@@ -893,42 +906,42 @@ class Redis
|
|
893
906
|
end
|
894
907
|
|
895
908
|
synchronize do
|
896
|
-
@client.call
|
909
|
+
@client.call [:sort, key, *command.to_a]
|
897
910
|
end
|
898
911
|
end
|
899
912
|
|
900
913
|
# Increment the integer value of a key by one.
|
901
914
|
def incr(key)
|
902
915
|
synchronize do
|
903
|
-
@client.call
|
916
|
+
@client.call [:incr, key]
|
904
917
|
end
|
905
918
|
end
|
906
919
|
|
907
920
|
# Increment the integer value of a key by the given number.
|
908
921
|
def incrby(key, increment)
|
909
922
|
synchronize do
|
910
|
-
@client.call
|
923
|
+
@client.call [:incrby, key, increment]
|
911
924
|
end
|
912
925
|
end
|
913
926
|
|
914
927
|
# Decrement the integer value of a key by one.
|
915
928
|
def decr(key)
|
916
929
|
synchronize do
|
917
|
-
@client.call
|
930
|
+
@client.call [:decr, key]
|
918
931
|
end
|
919
932
|
end
|
920
933
|
|
921
934
|
# Decrement the integer value of a key by the given number.
|
922
935
|
def decrby(key, decrement)
|
923
936
|
synchronize do
|
924
|
-
@client.call
|
937
|
+
@client.call [:decrby, key, decrement]
|
925
938
|
end
|
926
939
|
end
|
927
940
|
|
928
941
|
# Determine the type stored at key.
|
929
942
|
def type(key)
|
930
943
|
synchronize do
|
931
|
-
@client.call
|
944
|
+
@client.call [:type, key]
|
932
945
|
end
|
933
946
|
end
|
934
947
|
|
@@ -936,7 +949,7 @@ class Redis
|
|
936
949
|
def quit
|
937
950
|
synchronize do
|
938
951
|
begin
|
939
|
-
@client.call
|
952
|
+
@client.call [:quit]
|
940
953
|
rescue Errno::ECONNRESET
|
941
954
|
ensure
|
942
955
|
@client.disconnect
|
@@ -947,14 +960,14 @@ class Redis
|
|
947
960
|
# Synchronously save the dataset to disk and then shut down the server.
|
948
961
|
def shutdown
|
949
962
|
synchronize do
|
950
|
-
@client.
|
963
|
+
@client.call_without_reply [:shutdown]
|
951
964
|
end
|
952
965
|
end
|
953
966
|
|
954
967
|
# Make the server a slave of another instance, or promote it as master.
|
955
968
|
def slaveof(host, port)
|
956
969
|
synchronize do
|
957
|
-
@client.call
|
970
|
+
@client.call [:slaveof, host, port]
|
958
971
|
end
|
959
972
|
end
|
960
973
|
|
@@ -973,21 +986,21 @@ class Redis
|
|
973
986
|
# Watch the given keys to determine execution of the MULTI/EXEC block.
|
974
987
|
def watch(*keys)
|
975
988
|
synchronize do
|
976
|
-
@client.call
|
989
|
+
@client.call [:watch, *keys]
|
977
990
|
end
|
978
991
|
end
|
979
992
|
|
980
993
|
# Forget about all watched keys.
|
981
994
|
def unwatch
|
982
995
|
synchronize do
|
983
|
-
@client.call
|
996
|
+
@client.call [:unwatch]
|
984
997
|
end
|
985
998
|
end
|
986
999
|
|
987
1000
|
# Execute all commands issued after MULTI.
|
988
1001
|
def exec
|
989
1002
|
synchronize do
|
990
|
-
@client.call
|
1003
|
+
@client.call [:exec]
|
991
1004
|
end
|
992
1005
|
end
|
993
1006
|
|
@@ -1011,7 +1024,7 @@ class Redis
|
|
1011
1024
|
# Post a message to a channel.
|
1012
1025
|
def publish(channel, message)
|
1013
1026
|
synchronize do
|
1014
|
-
@client.call
|
1027
|
+
@client.call [:publish, channel, message]
|
1015
1028
|
end
|
1016
1029
|
end
|
1017
1030
|
|
@@ -1065,7 +1078,7 @@ class Redis
|
|
1065
1078
|
|
1066
1079
|
def method_missing(command, *args)
|
1067
1080
|
synchronize do
|
1068
|
-
@client.call
|
1081
|
+
@client.call [command, *args]
|
1069
1082
|
end
|
1070
1083
|
end
|
1071
1084
|
|
@@ -1107,12 +1120,15 @@ class Redis
|
|
1107
1120
|
|
1108
1121
|
private
|
1109
1122
|
|
1123
|
+
# Commands returning 1 for true and 0 for false may be executed in a pipeline
|
1124
|
+
# where the method call will return nil. Propagate the nil instead of falsely
|
1125
|
+
# returning false.
|
1110
1126
|
def _bool(value)
|
1111
|
-
value == 1
|
1127
|
+
value == 1 if value
|
1112
1128
|
end
|
1113
1129
|
|
1114
1130
|
def subscription(method, channels, block)
|
1115
|
-
return @client.call
|
1131
|
+
return @client.call [method, *channels] if subscribed?
|
1116
1132
|
|
1117
1133
|
begin
|
1118
1134
|
original, @client = @client, SubscribedClient.new(@client)
|