Class: Redis::Distributed

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/distributed.rb

Defined Under Namespace

Classes: CannotDistribute

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Distributed) initialize(node_configs, options = {})

Returns a new instance of Distributed



18
19
20
21
22
23
24
# File 'lib/redis/distributed.rb', line 18

def initialize(node_configs, options = {})
  @tag = options.delete(:tag) || /^\{(.+?)\}/
  @ring = options.delete(:ring) || HashRing.new
  @default_options = options
  node_configs.each { |node_config| add_node(node_config) }
  @subscribed_node = nil
end

Instance Attribute Details

- (Object) ring (readonly)

Returns the value of attribute ring



16
17
18
# File 'lib/redis/distributed.rb', line 16

def ring
  @ring
end

Instance Method Details

- (Object) [](key)



335
336
337
# File 'lib/redis/distributed.rb', line 335

def [](key)
  get(key)
end

- (Object) []=(key, value)



339
340
341
# File 'lib/redis/distributed.rb', line 339

def []=(key,value)
  set(key, value)
end

- (Object) _bpop(cmd, args)



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/redis/distributed.rb', line 386

def _bpop(cmd, args)
  options = {}

  case args.last
  when Hash
    options = args.pop
  when Integer
    # Issue deprecation notice in obnoxious mode...
    options[:timeout] = args.pop
  end

  if args.size > 1
    # Issue deprecation notice in obnoxious mode...
  end

  keys = args.flatten

  ensure_same_node(cmd, keys) do |node|
    node.__send__(cmd, keys, options)
  end
end

- (Object) _eval(cmd, args)



783
784
785
786
787
788
789
790
791
792
793
794
# File 'lib/redis/distributed.rb', line 783

def _eval(cmd, args)
  script = args.shift
  options = args.pop if args.last.is_a?(Hash)
  options ||= {}

  keys = args.shift || options[:keys] || []
  argv = args.shift || options[:argv] || []

  ensure_same_node(cmd, keys) do |node|
    node.send(cmd, script, keys, argv)
  end
end

- (Object) add_node(options)



34
35
36
37
38
# File 'lib/redis/distributed.rb', line 34

def add_node(options)
  options = { :url => options } if options.is_a?(String)
  options = @default_options.merge(options)
  @ring.add_node Redis.new( options )
end

- (Object) append(key, value)

Append a value to a key.



309
310
311
# File 'lib/redis/distributed.rb', line 309

def append(key, value)
  node_for(key).append(key, value)
end

- (Object) bgsave

Asynchronously save the dataset to disk.



61
62
63
# File 'lib/redis/distributed.rb', line 61

def bgsave
  on_each_node :bgsave
end

- (Object) bitcount(key, start = 0, stop = -1))

Count the number of set bits in a range of the string value stored at key.



314
315
316
# File 'lib/redis/distributed.rb', line 314

def bitcount(key, start = 0, stop = -1)
  node_for(key).bitcount(key, start, stop)
end

- (Object) bitop(operation, destkey, *keys)

Perform a bitwise operation between strings and store the resulting string in a key.



319
320
321
322
323
# File 'lib/redis/distributed.rb', line 319

def bitop(operation, destkey, *keys)
  ensure_same_node(:bitop, [destkey] + keys) do |node|
    node.bitop(operation, destkey, *keys)
  end
end

- (Object) blpop(*args)

Remove and get the first element in a list, or block until one is available.



410
411
412
# File 'lib/redis/distributed.rb', line 410

def blpop(*args)
  _bpop(:blpop, args)
end

- (Object) brpop(*args)

Remove and get the last element in a list, or block until one is available.



416
417
418
# File 'lib/redis/distributed.rb', line 416

def brpop(*args)
  _bpop(:brpop, args)
end

- (Object) brpoplpush(source, destination, options = {})

Pop a value from a list, push it to another list and return it; or block until one is available.



422
423
424
425
426
427
428
429
430
431
432
# File 'lib/redis/distributed.rb', line 422

def brpoplpush(source, destination, options = {})
  case options
  when Integer
    # Issue deprecation notice in obnoxious mode...
    options = { :timeout => options }
  end

  ensure_same_node(:brpoplpush, [source, destination]) do |node|
    node.brpoplpush(source, destination, options)
  end
end

- (Object) dbsize

Return the number of keys in the selected database.



66
67
68
# File 'lib/redis/distributed.rb', line 66

def dbsize
  on_each_node :dbsize
end

- (Object) decr(key)

Decrement the integer value of a key by one.



212
213
214
# File 'lib/redis/distributed.rb', line 212

def decr(key)
  node_for(key).decr(key)
end

- (Object) decrby(key, decrement)

Decrement the integer value of a key by the given number.



217
218
219
# File 'lib/redis/distributed.rb', line 217

def decrby(key, decrement)
  node_for(key).decrby(key, decrement)
end

- (Object) del(*args)

Delete a key.



156
157
158
159
160
161
# File 'lib/redis/distributed.rb', line 156

def del(*args)
  keys_per_node = args.group_by { |key| node_for(key) }
  keys_per_node.inject(0) do |sum, (node, keys)|
    sum + node.del(*keys)
  end
end

- (Object) discard

Discard all commands issued after MULTI.

Raises:



774
775
776
# File 'lib/redis/distributed.rb', line 774

def discard
  raise CannotDistribute, :discard
end

- (Object) dump(key)

Return a serialized version of the value stored at a key.



141
142
143
# File 'lib/redis/distributed.rb', line 141

def dump(key)
  node_for(key).dump(key)
end

- (Object) echo(value)

Echo the given string.



51
52
53
# File 'lib/redis/distributed.rb', line 51

def echo(value)
  on_each_node :echo, value
end

- (Object) eval(*args)

Evaluate Lua script.



797
798
799
# File 'lib/redis/distributed.rb', line 797

def eval(*args)
  _eval(:eval, args)
end

- (Object) evalsha(*args)

Evaluate Lua script by its SHA.



802
803
804
# File 'lib/redis/distributed.rb', line 802

def evalsha(*args)
  _eval(:evalsha, args)
end

- (Object) exec

Execute all commands issued after MULTI.

Raises:



769
770
771
# File 'lib/redis/distributed.rb', line 769

def exec
  raise CannotDistribute, :exec
end

- (Object) exists(key)

Determine if a key exists.



164
165
166
# File 'lib/redis/distributed.rb', line 164

def exists(key)
  node_for(key).exists(key)
end

- (Object) expire(key, seconds)

Set a key's time to live in seconds.



111
112
113
# File 'lib/redis/distributed.rb', line 111

def expire(key, seconds)
  node_for(key).expire(key, seconds)
end

- (Object) expireat(key, unix_time)

Set the expiration for a key as a UNIX timestamp.



116
117
118
# File 'lib/redis/distributed.rb', line 116

def expireat(key, unix_time)
  node_for(key).expireat(key, unix_time)
end

- (Object) flushall

Remove all keys from all databases.



71
72
73
# File 'lib/redis/distributed.rb', line 71

def flushall
  on_each_node :flushall
end

- (Object) flushdb

Remove all keys from the current database.



76
77
78
# File 'lib/redis/distributed.rb', line 76

def flushdb
  on_each_node :flushdb
end

- (Object) get(key)

Get the value of a key.



275
276
277
# File 'lib/redis/distributed.rb', line 275

def get(key)
  node_for(key).get(key)
end

- (Object) getbit(key, offset)

Returns the bit value at offset in the string value stored at key.



304
305
306
# File 'lib/redis/distributed.rb', line 304

def getbit(key, offset)
  node_for(key).getbit(key, offset)
end

- (Object) getrange(key, start, stop)

Get a substring of the string stored at a key.



294
295
296
# File 'lib/redis/distributed.rb', line 294

def getrange(key, start, stop)
  node_for(key).getrange(key, start, stop)
end

- (Object) getset(key, value)

Set the string value of a key and return its old value.



326
327
328
# File 'lib/redis/distributed.rb', line 326

def getset(key, value)
  node_for(key).getset(key, value)
end

- (Object) hdel(key, field)

Delete one or more hash fields.



676
677
678
# File 'lib/redis/distributed.rb', line 676

def hdel(key, field)
  node_for(key).hdel(key, field)
end

- (Object) hexists(key, field)

Determine if a hash field exists.



681
682
683
# File 'lib/redis/distributed.rb', line 681

def hexists(key, field)
  node_for(key).hexists(key, field)
end

- (Object) hget(key, field)

Get the value of a hash field.



662
663
664
# File 'lib/redis/distributed.rb', line 662

def hget(key, field)
  node_for(key).hget(key, field)
end

- (Object) hgetall(key)

Get all the fields and values in a hash.



706
707
708
# File 'lib/redis/distributed.rb', line 706

def hgetall(key)
  node_for(key).hgetall(key)
end

- (Object) hincrby(key, field, increment)

Increment the integer value of a hash field by the given integer number.



686
687
688
# File 'lib/redis/distributed.rb', line 686

def hincrby(key, field, increment)
  node_for(key).hincrby(key, field, increment)
end

- (Object) hincrbyfloat(key, field, increment)

Increment the numeric value of a hash field by the given float number.



691
692
693
# File 'lib/redis/distributed.rb', line 691

def hincrbyfloat(key, field, increment)
  node_for(key).hincrbyfloat(key, field, increment)
end

- (Object) hkeys(key)

Get all the fields in a hash.



696
697
698
# File 'lib/redis/distributed.rb', line 696

def hkeys(key)
  node_for(key).hkeys(key)
end

- (Object) hlen(key)

Get the number of fields in a hash.



638
639
640
# File 'lib/redis/distributed.rb', line 638

def hlen(key)
  node_for(key).hlen(key)
end

- (Object) hmget(key, *fields)

Get the values of all the given hash fields.



667
668
669
# File 'lib/redis/distributed.rb', line 667

def hmget(key, *fields)
  node_for(key).hmget(key, *fields)
end

- (Object) hmset(key, *attrs)

Set multiple hash fields to multiple values.



653
654
655
# File 'lib/redis/distributed.rb', line 653

def hmset(key, *attrs)
  node_for(key).hmset(key, *attrs)
end

- (Object) hset(key, field, value)

Set the string value of a hash field.



643
644
645
# File 'lib/redis/distributed.rb', line 643

def hset(key, field, value)
  node_for(key).hset(key, field, value)
end

- (Object) hsetnx(key, field, value)

Set the value of a hash field, only if the field does not exist.



648
649
650
# File 'lib/redis/distributed.rb', line 648

def hsetnx(key, field, value)
  node_for(key).hsetnx(key, field, value)
end

- (Object) hvals(key)

Get all the values in a hash.



701
702
703
# File 'lib/redis/distributed.rb', line 701

def hvals(key)
  node_for(key).hvals(key)
end

- (Object) incr(key)

Increment the integer value of a key by one.



222
223
224
# File 'lib/redis/distributed.rb', line 222

def incr(key)
  node_for(key).incr(key)
end

- (Object) incrby(key, increment)

Increment the integer value of a key by the given integer number.



227
228
229
# File 'lib/redis/distributed.rb', line 227

def incrby(key, increment)
  node_for(key).incrby(key, increment)
end

- (Object) incrbyfloat(key, increment)

Increment the numeric value of a key by the given float number.



232
233
234
# File 'lib/redis/distributed.rb', line 232

def incrbyfloat(key, increment)
  node_for(key).incrbyfloat(key, increment)
end

- (Object) info(cmd = nil)

Get information and statistics about the server.



81
82
83
# File 'lib/redis/distributed.rb', line 81

def info(cmd = nil)
  on_each_node :info, cmd
end

- (Object) inspect



806
807
808
# File 'lib/redis/distributed.rb', line 806

def inspect
  "#<Redis client v#{Redis::VERSION} for #{nodes.map(&:id).join(', ')}>"
end

- (Object) keys(glob = "*")

Find all keys matching the given pattern.



169
170
171
# File 'lib/redis/distributed.rb', line 169

def keys(glob = "*")
  on_each_node(:keys, glob).flatten
end

- (Object) lastsave

Get the UNIX time stamp of the last successful save to disk.



86
87
88
# File 'lib/redis/distributed.rb', line 86

def lastsave
  on_each_node :lastsave
end

- (Object) lindex(key, index)

Get an element from a list by its index.



435
436
437
# File 'lib/redis/distributed.rb', line 435

def lindex(key, index)
  node_for(key).lindex(key, index)
end

- (Object) linsert(key, where, pivot, value)

Insert an element before or after another element in a list.



440
441
442
# File 'lib/redis/distributed.rb', line 440

def linsert(key, where, pivot, value)
  node_for(key).linsert(key, where, pivot, value)
end

- (Object) llen(key)

Get the length of a list.



344
345
346
# File 'lib/redis/distributed.rb', line 344

def llen(key)
  node_for(key).llen(key)
end

- (Object) lpop(key)

Remove and get the first element in a list.



369
370
371
# File 'lib/redis/distributed.rb', line 369

def lpop(key)
  node_for(key).lpop(key)
end

- (Object) lpush(key, value)

Prepend one or more values to a list.



349
350
351
# File 'lib/redis/distributed.rb', line 349

def lpush(key, value)
  node_for(key).lpush(key, value)
end

- (Object) lpushx(key, value)

Prepend a value to a list, only if the list exists.



354
355
356
# File 'lib/redis/distributed.rb', line 354

def lpushx(key, value)
  node_for(key).lpushx(key, value)
end

- (Object) lrange(key, start, stop)

Get a range of elements from a list.



445
446
447
# File 'lib/redis/distributed.rb', line 445

def lrange(key, start, stop)
  node_for(key).lrange(key, start, stop)
end

- (Object) lrem(key, count, value)

Remove elements from a list.



450
451
452
# File 'lib/redis/distributed.rb', line 450

def lrem(key, count, value)
  node_for(key).lrem(key, count, value)
end

- (Object) lset(key, index, value)

Set the value of an element in a list by its index.



455
456
457
# File 'lib/redis/distributed.rb', line 455

def lset(key, index, value)
  node_for(key).lset(key, index, value)
end

- (Object) ltrim(key, start, stop)

Trim a list to the specified range.



460
461
462
# File 'lib/redis/distributed.rb', line 460

def ltrim(key, start, stop)
  node_for(key).ltrim(key, start, stop)
end

- (Object) mapped_hmget(key, *fields)



671
672
673
# File 'lib/redis/distributed.rb', line 671

def mapped_hmget(key, *fields)
  Hash[*fields.zip(hmget(key, *fields)).flatten]
end

- (Object) mapped_hmset(key, hash)



657
658
659
# File 'lib/redis/distributed.rb', line 657

def mapped_hmset(key, hash)
  node_for(key).hmset(key, *hash.to_a.flatten)
end

- (Object) mapped_mget(*keys)

Raises:



284
285
286
# File 'lib/redis/distributed.rb', line 284

def mapped_mget(*keys)
  raise CannotDistribute, :mapped_mget
end

- (Object) mapped_mset(hash)

Raises:



261
262
263
# File 'lib/redis/distributed.rb', line 261

def mapped_mset(hash)
  raise CannotDistribute, :mapped_mset
end

- (Object) mapped_msetnx(hash)

Raises:



270
271
272
# File 'lib/redis/distributed.rb', line 270

def mapped_msetnx(hash)
  raise CannotDistribute, :mapped_msetnx
end

- (Object) mget(*keys)

Get the values of all the given keys.

Raises:



280
281
282
# File 'lib/redis/distributed.rb', line 280

def mget(*keys)
  raise CannotDistribute, :mget
end

- (Object) migrate(key, options)

Transfer a key from the connected instance to another instance.

Raises:



151
152
153
# File 'lib/redis/distributed.rb', line 151

def migrate(key, options)
  raise CannotDistribute, :migrate
end

- (Object) monitor

Listen for all requests received by the server in real time.

Raises:

  • (NotImplementedError)


91
92
93
# File 'lib/redis/distributed.rb', line 91

def monitor
  raise NotImplementedError
end

- (Object) move(key, db)

Move a key to another database.



174
175
176
# File 'lib/redis/distributed.rb', line 174

def move(key, db)
  node_for(key).move(key, db)
end

- (Object) mset(*args)

Set multiple keys to multiple values.

Raises:



257
258
259
# File 'lib/redis/distributed.rb', line 257

def mset(*args)
  raise CannotDistribute, :mset
end

- (Object) msetnx(*args)

Set multiple keys to multiple values, only if none of the keys exist.

Raises:



266
267
268
# File 'lib/redis/distributed.rb', line 266

def msetnx(*args)
  raise CannotDistribute, :msetnx
end

- (Object) multi

Mark the start of a transaction block.

Raises:



764
765
766
# File 'lib/redis/distributed.rb', line 764

def multi
  raise CannotDistribute, :multi
end

- (Object) node_for(key)



26
27
28
# File 'lib/redis/distributed.rb', line 26

def node_for(key)
  @ring.get_node(key_tag(key.to_s) || key.to_s)
end

- (Object) nodes



30
31
32
# File 'lib/redis/distributed.rb', line 30

def nodes
  @ring.nodes
end

- (Object) persist(key)

Remove the expiration from a key.



106
107
108
# File 'lib/redis/distributed.rb', line 106

def persist(key)
  node_for(key).persist(key)
end

- (Object) pexpire(key, milliseconds)

Set a key's time to live in milliseconds.



126
127
128
# File 'lib/redis/distributed.rb', line 126

def pexpire(key, milliseconds)
  node_for(key).pexpire(key, milliseconds)
end

- (Object) pexpireat(key, ms_unix_time)

Set the expiration for a key as number of milliseconds from UNIX Epoch.



131
132
133
# File 'lib/redis/distributed.rb', line 131

def pexpireat(key, ms_unix_time)
  node_for(key).pexpireat(key, ms_unix_time)
end

- (Object) ping

Ping the server.



46
47
48
# File 'lib/redis/distributed.rb', line 46

def ping
  on_each_node :ping
end

- (Object) pipelined

Raises:



759
760
761
# File 'lib/redis/distributed.rb', line 759

def pipelined
  raise CannotDistribute, :pipelined
end

- (Object) psetex(key, ttl, value)

Set the time to live in milliseconds of a key.



247
248
249
# File 'lib/redis/distributed.rb', line 247

def psetex(key, ttl, value)
  node_for(key).psetex(key, ttl, value)
end

- (Object) psubscribe(*channels, &block)

Listen for messages published to channels matching the given patterns.

Raises:

  • (NotImplementedError)


739
740
741
# File 'lib/redis/distributed.rb', line 739

def psubscribe(*channels, &block)
  raise NotImplementedError
end

- (Object) pttl(key)

Get the time to live (in milliseconds) for a key.



136
137
138
# File 'lib/redis/distributed.rb', line 136

def pttl(key)
  node_for(key).pttl(key)
end

- (Object) publish(channel, message)

Post a message to a channel.



711
712
713
# File 'lib/redis/distributed.rb', line 711

def publish(channel, message)
  node_for(channel).publish(channel, message)
end

- (Object) punsubscribe(*channels)

Stop listening for messages posted to channels matching the given patterns.

Raises:

  • (NotImplementedError)


745
746
747
# File 'lib/redis/distributed.rb', line 745

def punsubscribe(*channels)
  raise NotImplementedError
end

- (Object) quit

Close the connection.



56
57
58
# File 'lib/redis/distributed.rb', line 56

def quit
  on_each_node :quit
end

- (Object) randomkey

Return a random key from the keyspace.

Raises:



179
180
181
# File 'lib/redis/distributed.rb', line 179

def randomkey
  raise CannotDistribute, :randomkey
end

- (Object) rename(old_name, new_name)

Rename a key.



184
185
186
187
188
# File 'lib/redis/distributed.rb', line 184

def rename(old_name, new_name)
  ensure_same_node(:rename, [old_name, new_name]) do |node|
    node.rename(old_name, new_name)
  end
end

- (Object) renamenx(old_name, new_name)

Rename a key, only if the new key does not exist.



191
192
193
194
195
# File 'lib/redis/distributed.rb', line 191

def renamenx(old_name, new_name)
  ensure_same_node(:renamenx, [old_name, new_name]) do |node|
    node.renamenx(old_name, new_name)
  end
end

- (Object) restore(key, ttl, serialized_value)

Create a key using the serialized value, previously obtained using DUMP.



146
147
148
# File 'lib/redis/distributed.rb', line 146

def restore(key, ttl, serialized_value)
  node_for(key).restore(key, ttl, serialized_value)
end

- (Object) rpop(key)

Remove and get the last element in a list.



374
375
376
# File 'lib/redis/distributed.rb', line 374

def rpop(key)
  node_for(key).rpop(key)
end

- (Object) rpoplpush(source, destination)

Remove the last element in a list, append it to another list and return it.



380
381
382
383
384
# File 'lib/redis/distributed.rb', line 380

def rpoplpush(source, destination)
  ensure_same_node(:rpoplpush, [source, destination]) do |node|
    node.rpoplpush(source, destination)
  end
end

- (Object) rpush(key, value)

Append one or more values to a list.



359
360
361
# File 'lib/redis/distributed.rb', line 359

def rpush(key, value)
  node_for(key).rpush(key, value)
end

- (Object) rpushx(key, value)

Append a value to a list, only if the list exists.



364
365
366
# File 'lib/redis/distributed.rb', line 364

def rpushx(key, value)
  node_for(key).rpushx(key, value)
end

- (Object) sadd(key, member)

Add one or more members to a set.



470
471
472
# File 'lib/redis/distributed.rb', line 470

def sadd(key, member)
  node_for(key).sadd(key, member)
end

- (Object) save

Synchronously save the dataset to disk.



96
97
98
# File 'lib/redis/distributed.rb', line 96

def save
  on_each_node :save
end

- (Object) scard(key)

Get the number of members in a set.



465
466
467
# File 'lib/redis/distributed.rb', line 465

def scard(key)
  node_for(key).scard(key)
end

- (Object) script(subcommand, *args)

Control remote script registry.



779
780
781
# File 'lib/redis/distributed.rb', line 779

def script(subcommand, *args)
  on_each_node(:script, subcommand, *args)
end

- (Object) sdiff(*keys)

Subtract multiple sets.



507
508
509
510
511
# File 'lib/redis/distributed.rb', line 507

def sdiff(*keys)
  ensure_same_node(:sdiff, keys) do |node|
    node.sdiff(*keys)
  end
end

- (Object) sdiffstore(destination, *keys)

Subtract multiple sets and store the resulting set in a key.



514
515
516
517
518
# File 'lib/redis/distributed.rb', line 514

def sdiffstore(destination, *keys)
  ensure_same_node(:sdiffstore, [destination] + keys) do |node|
    node.sdiffstore(destination, *keys)
  end
end

- (Object) select(db)

Change the selected database for the current connection.



41
42
43
# File 'lib/redis/distributed.rb', line 41

def select(db)
  on_each_node :select, db
end

- (Object) set(key, value, options = {})

Set the string value of a key.



237
238
239
# File 'lib/redis/distributed.rb', line 237

def set(key, value, options = {})
  node_for(key).set(key, value, options)
end

- (Object) setbit(key, offset, value)

Sets or clears the bit at offset in the string value stored at key.



299
300
301
# File 'lib/redis/distributed.rb', line 299

def setbit(key, offset, value)
  node_for(key).setbit(key, offset, value)
end

- (Object) setex(key, ttl, value)

Set the time to live in seconds of a key.



242
243
244
# File 'lib/redis/distributed.rb', line 242

def setex(key, ttl, value)
  node_for(key).setex(key, ttl, value)
end

- (Object) setnx(key, value)

Set the value of a key, only if the key does not exist.



252
253
254
# File 'lib/redis/distributed.rb', line 252

def setnx(key, value)
  node_for(key).setnx(key, value)
end

- (Object) setrange(key, offset, value)

Overwrite part of a string at key starting at the specified offset.



289
290
291
# File 'lib/redis/distributed.rb', line 289

def setrange(key, offset, value)
  node_for(key).setrange(key, offset, value)
end

- (Object) sinter(*keys)

Intersect multiple sets.



521
522
523
524
525
# File 'lib/redis/distributed.rb', line 521

def sinter(*keys)
  ensure_same_node(:sinter, keys) do |node|
    node.sinter(*keys)
  end
end

- (Object) sinterstore(destination, *keys)

Intersect multiple sets and store the resulting set in a key.



528
529
530
531
532
# File 'lib/redis/distributed.rb', line 528

def sinterstore(destination, *keys)
  ensure_same_node(:sinterstore, [destination] + keys) do |node|
    node.sinterstore(destination, *keys)
  end
end

- (Object) sismember(key, member)

Determine if a given value is a member of a set.



497
498
499
# File 'lib/redis/distributed.rb', line 497

def sismember(key, member)
  node_for(key).sismember(key, member)
end

- (Object) smembers(key)

Get all the members in a set.



502
503
504
# File 'lib/redis/distributed.rb', line 502

def smembers(key)
  node_for(key).smembers(key)
end

- (Object) smove(source, destination, member)

Move a member from one set to another.



490
491
492
493
494
# File 'lib/redis/distributed.rb', line 490

def smove(source, destination, member)
  ensure_same_node(:smove, [source, destination]) do |node|
    node.smove(source, destination, member)
  end
end

- (Object) sort(key, options = {})

Sort the elements in a list, set or sorted set.



198
199
200
201
202
203
204
# File 'lib/redis/distributed.rb', line 198

def sort(key, options = {})
  keys = [key, options[:by], options[:store], *Array(options[:get])].compact

  ensure_same_node(:sort, keys) do |node|
    node.sort(key, options)
  end
end

- (Object) spop(key)

Remove and return a random member from a set.



480
481
482
# File 'lib/redis/distributed.rb', line 480

def spop(key)
  node_for(key).spop(key)
end

- (Object) srandmember(key, count = nil)

Get a random member from a set.



485
486
487
# File 'lib/redis/distributed.rb', line 485

def srandmember(key, count = nil)
  node_for(key).srandmember(key, count)
end

- (Object) srem(key, member)

Remove one or more members from a set.



475
476
477
# File 'lib/redis/distributed.rb', line 475

def srem(key, member)
  node_for(key).srem(key, member)
end

- (Object) strlen(key)

Get the length of the value stored in a key.



331
332
333
# File 'lib/redis/distributed.rb', line 331

def strlen(key)
  node_for(key).strlen(key)
end

- (Object) subscribe(channel, *channels, &block)

Listen for messages published to the given channels.



720
721
722
723
724
725
726
727
728
729
730
# File 'lib/redis/distributed.rb', line 720

def subscribe(channel, *channels, &block)
  if channels.empty?
    @subscribed_node = node_for(channel)
    @subscribed_node.subscribe(channel, &block)
  else
    ensure_same_node(:subscribe, [channel] + channels) do |node|
      @subscribed_node = node
      node.subscribe(channel, *channels, &block)
    end
  end
end

- (Boolean) subscribed?

Returns:

  • (Boolean)


715
716
717
# File 'lib/redis/distributed.rb', line 715

def subscribed?
  !! @subscribed_node
end

- (Object) sunion(*keys)

Add multiple sets.



535
536
537
538
539
# File 'lib/redis/distributed.rb', line 535

def sunion(*keys)
  ensure_same_node(:sunion, keys) do |node|
    node.sunion(*keys)
  end
end

- (Object) sunionstore(destination, *keys)

Add multiple sets and store the resulting set in a key.



542
543
544
545
546
# File 'lib/redis/distributed.rb', line 542

def sunionstore(destination, *keys)
  ensure_same_node(:sunionstore, [destination] + keys) do |node|
    node.sunionstore(destination, *keys)
  end
end

- (Object) time

Get server time: an UNIX timestamp and the elapsed microseconds in the current second.



101
102
103
# File 'lib/redis/distributed.rb', line 101

def time
  on_each_node :time
end

- (Object) ttl(key)

Get the time to live (in seconds) for a key.



121
122
123
# File 'lib/redis/distributed.rb', line 121

def ttl(key)
  node_for(key).ttl(key)
end

- (Object) type(key)

Determine the type stored at key.



207
208
209
# File 'lib/redis/distributed.rb', line 207

def type(key)
  node_for(key).type(key)
end

- (Object) unsubscribe(*channels)

Stop listening for messages posted to the given channels.

Raises:

  • (RuntimeError)


733
734
735
736
# File 'lib/redis/distributed.rb', line 733

def unsubscribe(*channels)
  raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed?
  @subscribed_node.unsubscribe(*channels)
end

- (Object) unwatch

Forget about all watched keys.

Raises:



755
756
757
# File 'lib/redis/distributed.rb', line 755

def unwatch
  raise CannotDistribute, :unwatch
end

- (Object) watch(*keys)

Watch the given keys to determine execution of the MULTI/EXEC block.

Raises:



750
751
752
# File 'lib/redis/distributed.rb', line 750

def watch(*keys)
  raise CannotDistribute, :watch
end

- (Object) zadd(key, *args)

Add one or more members to a sorted set, or update the score for members that already exist.



555
556
557
# File 'lib/redis/distributed.rb', line 555

def zadd(key, *args)
  node_for(key).zadd(key, *args)
end

- (Object) zcard(key)

Get the number of members in a sorted set.



549
550
551
# File 'lib/redis/distributed.rb', line 549

def zcard(key)
  node_for(key).zcard(key)
end

- (Object) zcount(key, min, max)

Get the number of members in a particular score range.



618
619
620
# File 'lib/redis/distributed.rb', line 618

def zcount(key, min, max)
  node_for(key).zcount(key, min, max)
end

- (Object) zincrby(key, increment, member)

Increment the score of a member in a sorted set.



560
561
562
# File 'lib/redis/distributed.rb', line 560

def zincrby(key, increment, member)
  node_for(key).zincrby(key, increment, member)
end

- (Object) zinterstore(destination, keys, options = {})

Intersect multiple sorted sets and store the resulting sorted set in a new key.



624
625
626
627
628
# File 'lib/redis/distributed.rb', line 624

def zinterstore(destination, keys, options = {})
  ensure_same_node(:zinterstore, [destination] + keys) do |node|
    node.zinterstore(destination, keys, options)
  end
end

- (Object) zrange(key, start, stop, options = {})

Return a range of members in a sorted set, by index.



575
576
577
# File 'lib/redis/distributed.rb', line 575

def zrange(key, start, stop, options = {})
  node_for(key).zrange(key, start, stop, options)
end

- (Object) zrangebyscore(key, min, max, options = {})

Return a range of members in a sorted set, by score.



602
603
604
# File 'lib/redis/distributed.rb', line 602

def zrangebyscore(key, min, max, options = {})
  node_for(key).zrangebyscore(key, min, max, options)
end

- (Object) zrank(key, member)

Determine the index of a member in a sorted set.



586
587
588
# File 'lib/redis/distributed.rb', line 586

def zrank(key, member)
  node_for(key).zrank(key, member)
end

- (Object) zrem(key, member)

Remove one or more members from a sorted set.



565
566
567
# File 'lib/redis/distributed.rb', line 565

def zrem(key, member)
  node_for(key).zrem(key, member)
end

- (Object) zremrangebyrank(key, start, stop)

Remove all members in a sorted set within the given indexes.



597
598
599
# File 'lib/redis/distributed.rb', line 597

def zremrangebyrank(key, start, stop)
  node_for(key).zremrangebyrank(key, start, stop)
end

- (Object) zremrangebyscore(key, min, max)

Remove all members in a sorted set within the given scores.



613
614
615
# File 'lib/redis/distributed.rb', line 613

def zremrangebyscore(key, min, max)
  node_for(key).zremrangebyscore(key, min, max)
end

- (Object) zrevrange(key, start, stop, options = {})

Return a range of members in a sorted set, by index, with scores ordered from high to low.



581
582
583
# File 'lib/redis/distributed.rb', line 581

def zrevrange(key, start, stop, options = {})
  node_for(key).zrevrange(key, start, stop, options)
end

- (Object) zrevrangebyscore(key, max, min, options = {})

Return a range of members in a sorted set, by score, with scores ordered from high to low.



608
609
610
# File 'lib/redis/distributed.rb', line 608

def zrevrangebyscore(key, max, min, options = {})
  node_for(key).zrevrangebyscore(key, max, min, options)
end

- (Object) zrevrank(key, member)

Determine the index of a member in a sorted set, with scores ordered from high to low.



592
593
594
# File 'lib/redis/distributed.rb', line 592

def zrevrank(key, member)
  node_for(key).zrevrank(key, member)
end

- (Object) zscore(key, member)

Get the score associated with the given member in a sorted set.



570
571
572
# File 'lib/redis/distributed.rb', line 570

def zscore(key, member)
  node_for(key).zscore(key, member)
end

- (Object) zunionstore(destination, keys, options = {})

Add multiple sorted sets and store the resulting sorted set in a new key.



631
632
633
634
635
# File 'lib/redis/distributed.rb', line 631

def zunionstore(destination, keys, options = {})
  ensure_same_node(:zunionstore, [destination] + keys) do |node|
    node.zunionstore(destination, keys, options)
  end
end