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

#initialize(urls, options = {}) ⇒ Distributed

Returns a new instance of Distributed.



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

def initialize(urls, options = {})
  @tag = options.delete(:tag) || /^\{(.+?)\}/
  @default_options = options
  @ring = HashRing.new urls.map { |url| Redis.connect(options.merge(:url => url)) }
  @subscribed_node = nil
end

Instance Attribute Details

#ringObject (readonly)

Returns the value of attribute ring.



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

def ring
  @ring
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  get(key)
end

#[]=(key, value) ⇒ Object



187
188
189
# File 'lib/redis/distributed.rb', line 187

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

#add_node(url) ⇒ Object



33
34
35
# File 'lib/redis/distributed.rb', line 33

def add_node(url)
  @ring.add_node Redis.connect(@default_options.merge(:url => url))
end

#append(key, value) ⇒ Object

Append a value to a key.



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

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

#bgsaveObject

Asynchronously save the dataset to disk.



630
631
632
# File 'lib/redis/distributed.rb', line 630

def bgsave
  on_each_node :bgsave
end

#blpop(key, timeout) ⇒ Object

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



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

def blpop(key, timeout)
  node_for(key).blpop(key, timeout)
end

#brpop(key, timeout) ⇒ Object

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



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

def brpop(key, timeout)
  node_for(key).brpop(key, timeout)
end

#brpoplpush(source, destination, timeout) ⇒ Object

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



315
316
317
318
319
# File 'lib/redis/distributed.rb', line 315

def brpoplpush(source, destination, timeout)
  ensure_same_node(:brpoplpush, source, destination) do |node|
    node.brpoplpush(source, destination, timeout)
  end
end

#dbsizeObject

Return the number of keys in the selected database.



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

def dbsize
  on_each_node :dbsize
end

#decr(key) ⇒ Object

Decrement the integer value of a key by one.



234
235
236
# File 'lib/redis/distributed.rb', line 234

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

#decrby(key, decrement) ⇒ Object

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



239
240
241
# File 'lib/redis/distributed.rb', line 239

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

#del(*args) ⇒ Object

Delete a key.



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

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

#discardObject

Discard all commands issued after MULTI.

Raises:



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

def discard
  raise CannotDistribute, :discard
end

#echo(value) ⇒ Object

Echo the given string.



650
651
652
# File 'lib/redis/distributed.rb', line 650

def echo(value)
  on_each_node :echo, value
end

#execObject

Execute all commands issued after MULTI.

Raises:



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

def exec
  raise CannotDistribute, :exec
end

#exists(key) ⇒ Object

Determine if a key exists.



58
59
60
# File 'lib/redis/distributed.rb', line 58

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

#expire(key, seconds) ⇒ Object

Set a key’s time to live in seconds.



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

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

#expireat(key, unix_time) ⇒ Object

Set the expiration for a key as a UNIX timestamp.



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

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

#flushallObject

Remove all keys from all databases.



53
54
55
# File 'lib/redis/distributed.rb', line 53

def flushall
  on_each_node :flushall
end

#flushdbObject

Remove all keys from the current database.



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

def flushdb
  on_each_node :flushdb
end

#get(key) ⇒ Object

Get the value of a key.



155
156
157
# File 'lib/redis/distributed.rb', line 155

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

#getbit(key, offset) ⇒ Object

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



160
161
162
# File 'lib/redis/distributed.rb', line 160

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

#getrange(key, start, stop) ⇒ Object

Get a substring of the string stored at a key.



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

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

#getset(key, value) ⇒ Object

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



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

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

#hdel(key, field) ⇒ Object

Delete a hash field.



499
500
501
# File 'lib/redis/distributed.rb', line 499

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

#hexists(key, field) ⇒ Object

Determine if a hash field exists.



504
505
506
# File 'lib/redis/distributed.rb', line 504

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

#hget(key, field) ⇒ Object

Get the value of a hash field.



494
495
496
# File 'lib/redis/distributed.rb', line 494

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

#hgetall(key) ⇒ Object

Get all the fields and values in a hash.



524
525
526
# File 'lib/redis/distributed.rb', line 524

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

#hincrby(key, field, increment) ⇒ Object

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



547
548
549
# File 'lib/redis/distributed.rb', line 547

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

#hkeys(key) ⇒ Object

Get all the fields in a hash.



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

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

#hlen(key) ⇒ Object

Get the number of fields in a hash.



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

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

#hmget(key, *fields) ⇒ Object

Get the values of all the given hash fields.



538
539
540
# File 'lib/redis/distributed.rb', line 538

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

#hmset(key, *attrs) ⇒ Object

Set multiple hash fields to multiple values.



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

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

#hset(key, field, value) ⇒ Object

Set the string value of a hash field.



489
490
491
# File 'lib/redis/distributed.rb', line 489

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

#hvals(key) ⇒ Object

Get all the values in a hash.



519
520
521
# File 'lib/redis/distributed.rb', line 519

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

#incr(key) ⇒ Object

Increment the integer value of a key by one.



224
225
226
# File 'lib/redis/distributed.rb', line 224

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

#incrby(key, increment) ⇒ Object

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



229
230
231
# File 'lib/redis/distributed.rb', line 229

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

#infoObject

Get information and statistics about the server.



640
641
642
# File 'lib/redis/distributed.rb', line 640

def info
  on_each_node :info
end

#keys(glob = "*") ⇒ Object

Find all keys matching the given pattern.



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

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

#lastsaveObject

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



635
636
637
# File 'lib/redis/distributed.rb', line 635

def lastsave
  on_each_node :lastsave
end

#lindex(key, index) ⇒ Object

Get an element from a list by its index.



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

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

#llen(key) ⇒ Object

Get the length of a list.



254
255
256
# File 'lib/redis/distributed.rb', line 254

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

#lpop(key) ⇒ Object

Remove and get the first element in a list.



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

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

#lpush(key, value) ⇒ Object

Prepend a value to a list.



249
250
251
# File 'lib/redis/distributed.rb', line 249

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

#lrange(key, start, stop) ⇒ Object

Get a range of elements from a list.



259
260
261
# File 'lib/redis/distributed.rb', line 259

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

#lrem(key, count, value) ⇒ Object

Remove elements from a list.



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

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

#lset(key, index, value) ⇒ Object

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



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

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

#ltrim(key, start, stop) ⇒ Object

Trim a list to the specified range.



264
265
266
# File 'lib/redis/distributed.rb', line 264

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

#mapped_hmget(key, *fields) ⇒ Object



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

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

#mapped_hmset(key, hash) ⇒ Object



533
534
535
# File 'lib/redis/distributed.rb', line 533

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

#mapped_mget(*keys) ⇒ Object

Raises:



196
197
198
# File 'lib/redis/distributed.rb', line 196

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

#mapped_mset(hash) ⇒ Object



210
211
212
# File 'lib/redis/distributed.rb', line 210

def mapped_mset(hash)
  mset(*hash.to_a.flatten)
end

#mapped_msetnx(hash) ⇒ Object

Raises:



219
220
221
# File 'lib/redis/distributed.rb', line 219

def mapped_msetnx(hash)
  raise CannotDistribute, :mapped_msetnx
end

#mget(*keys) ⇒ Object

Get the values of all the given keys.

Raises:



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

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

#monitorObject

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

Raises:

  • (NotImplementedError)


645
646
647
# File 'lib/redis/distributed.rb', line 645

def monitor
  raise NotImplementedError
end

#move(key, db) ⇒ Object

Move a key to another database.



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

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

#mset(*args) ⇒ Object

Set multiple keys to multiple values.

Raises:



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

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

#msetnx(*args) ⇒ Object

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

Raises:



215
216
217
# File 'lib/redis/distributed.rb', line 215

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

#multiObject

Mark the start of a transaction block.

Raises:



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

def multi
  raise CannotDistribute, :multi
end

#node_for(key) ⇒ Object



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

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

#nodesObject



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

def nodes
  @ring.nodes
end

#persist(key) ⇒ Object

Remove the expiration from a key.



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

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

#pingObject

Ping the server.



48
49
50
# File 'lib/redis/distributed.rb', line 48

def ping
  on_each_node :ping
end

#pipelinedObject

Raises:



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

def pipelined
  raise CannotDistribute, :pipelined
end

#psubscribe(*channels, &block) ⇒ Object

Listen for messages published to channels matching the given patterns.

Raises:

  • (NotImplementedError)


620
621
622
# File 'lib/redis/distributed.rb', line 620

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

#publish(channel, message) ⇒ Object

Post a message to a channel.



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

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

#punsubscribe(*channels) ⇒ Object

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

Raises:

  • (NotImplementedError)


615
616
617
# File 'lib/redis/distributed.rb', line 615

def punsubscribe(*channels)
  raise NotImplementedError
end

#quitObject

Close the connection.



38
39
40
# File 'lib/redis/distributed.rb', line 38

def quit
  on_each_node :quit
end

#randomkeyObject

Return a random key from the keyspace.

Raises:



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

def randomkey
  raise CannotDistribute, :randomkey
end

#rename(old_name, new_name) ⇒ Object

Rename a key.



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

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

#renamenx(old_name, new_name) ⇒ Object

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



93
94
95
96
97
# File 'lib/redis/distributed.rb', line 93

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

#rpop(key) ⇒ Object

Remove and get the last element in a list.



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

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

#rpoplpush(source, destination) ⇒ Object

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



295
296
297
298
299
# File 'lib/redis/distributed.rb', line 295

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

#rpush(key, value) ⇒ Object

Append a value to a list.



244
245
246
# File 'lib/redis/distributed.rb', line 244

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

#sadd(key, value) ⇒ Object

Add a member to a set.



322
323
324
# File 'lib/redis/distributed.rb', line 322

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

#saveObject

Synchronously save the dataset to disk.



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

def save
  on_each_node :save
end

#scard(key) ⇒ Object

Get the number of members in a set.



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

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

#sdiff(*keys) ⇒ Object

Subtract multiple sets.



382
383
384
385
386
# File 'lib/redis/distributed.rb', line 382

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

#sdiffstore(destination, *keys) ⇒ Object

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



389
390
391
392
393
# File 'lib/redis/distributed.rb', line 389

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

#select(db) ⇒ Object

Change the selected database for the current connection.



43
44
45
# File 'lib/redis/distributed.rb', line 43

def select(db)
  on_each_node :select, db
end

#set(key, value) ⇒ Object

Set the string value of a key.



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

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

#setbit(key, offset, value) ⇒ Object

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



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

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

#setex(key, ttl, value) ⇒ Object

Set the value and expiration of a key.



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

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

#setnx(key, value) ⇒ Object

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



201
202
203
# File 'lib/redis/distributed.rb', line 201

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

#setrange(key, offset, value) ⇒ Object

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



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

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

#sinter(*keys) ⇒ Object

Intersect multiple sets.



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

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

#sinterstore(destination, *keys) ⇒ Object

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



361
362
363
364
365
# File 'lib/redis/distributed.rb', line 361

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

#sismember(key, member) ⇒ Object

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



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

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

#smembers(key) ⇒ Object

Get all the members in a set.



396
397
398
# File 'lib/redis/distributed.rb', line 396

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

#smove(source, destination, member) ⇒ Object

Move a member from one set to another.



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

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

#sort(key, options = {}) ⇒ Object

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



552
553
554
555
556
557
558
# File 'lib/redis/distributed.rb', line 552

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

#spop(key) ⇒ Object

Remove and return a random member from a set.



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

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

#srandmember(key) ⇒ Object

Get a random member from a set.



401
402
403
# File 'lib/redis/distributed.rb', line 401

def srandmember(key)
  node_for(key).srandmember(key)
end

#srem(key, value) ⇒ Object

Remove a member from a set.



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

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

#subscribe(channel, *channels, &block) ⇒ Object

Listen for messages published to the given channels.



601
602
603
604
605
606
607
608
609
610
611
# File 'lib/redis/distributed.rb', line 601

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

#subscribed?Boolean

Returns:

  • (Boolean)


590
591
592
# File 'lib/redis/distributed.rb', line 590

def subscribed?
  !! @subscribed_node
end

#substr(key, start, stop) ⇒ Object



183
184
185
# File 'lib/redis/distributed.rb', line 183

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

#sunion(*keys) ⇒ Object

Add multiple sets.



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

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

#sunionstore(destination, *keys) ⇒ Object

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



375
376
377
378
379
# File 'lib/redis/distributed.rb', line 375

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

#ttl(key) ⇒ Object

Get the time to live for a key.



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

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

#type(key) ⇒ Object

Determine the type stored at key.



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

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

#unsubscribe(*channels) ⇒ Object

Stop listening for messages posted to the given channels.

Raises:

  • (RuntimeError)


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

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

#unwatchObject

Forget about all watched keys.

Raises:



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

def unwatch
  raise CannotDistribute, :unwatch
end

#watch(*keys) ⇒ Object

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

Raises:



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

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

#zadd(key, score, member) ⇒ Object

Add a member to a sorted set, or update its score if it already exists.



406
407
408
# File 'lib/redis/distributed.rb', line 406

def zadd(key, score, member)
  node_for(key).zadd(key, score, member)
end

#zcard(key) ⇒ Object

Get the number of members in a sorted set.



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

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

#zincrby(key, increment, member) ⇒ Object

Increment the score of a member in a sorted set.



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

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

#zinterstore(destination, keys, options = {}) ⇒ Object

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



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

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

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

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



421
422
423
# File 'lib/redis/distributed.rb', line 421

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

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

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



453
454
455
# File 'lib/redis/distributed.rb', line 453

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

#zrank(key, member) ⇒ Object

Determine the index of a member in a sorted set.



426
427
428
# File 'lib/redis/distributed.rb', line 426

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

#zrem(key, member) ⇒ Object

Remove a member from a sorted set.



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

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

#zremrangebyrank(key, start, stop) ⇒ Object

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



448
449
450
# File 'lib/redis/distributed.rb', line 448

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

#zremrangebyscore(key, min, max) ⇒ Object

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



443
444
445
# File 'lib/redis/distributed.rb', line 443

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

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

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



438
439
440
# File 'lib/redis/distributed.rb', line 438

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

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

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



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

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

#zrevrank(key, member) ⇒ Object

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



432
433
434
# File 'lib/redis/distributed.rb', line 432

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

#zscore(key, member) ⇒ Object

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



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

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

#zunionstore(destination, keys, options = {}) ⇒ Object

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



482
483
484
485
486
# File 'lib/redis/distributed.rb', line 482

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