Class: Redis::Distributed
- Inherits:
-
Object
- Object
- Redis::Distributed
- Defined in:
- lib/redis/distributed.rb
Defined Under Namespace
Classes: CannotDistribute
Instance Attribute Summary collapse
-
#ring ⇒ Object
readonly
Returns the value of attribute ring.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #_bpop(cmd, args) ⇒ Object
- #_eval(cmd, args) ⇒ Object
- #add_node(url) ⇒ Object
-
#append(key, value) ⇒ Object
Append a value to a key.
-
#bgsave ⇒ Object
Asynchronously save the dataset to disk.
-
#blpop(*args) ⇒ Object
Remove and get the first element in a list, or block until one is available.
-
#brpop(*args) ⇒ Object
Remove and get the last element in a list, or block until one is available.
-
#brpoplpush(source, destination, options = {}) ⇒ Object
Pop a value from a list, push it to another list and return it; or block until one is available.
-
#dbsize ⇒ Object
Return the number of keys in the selected database.
-
#decr(key) ⇒ Object
Decrement the integer value of a key by one.
-
#decrby(key, decrement) ⇒ Object
Decrement the integer value of a key by the given number.
-
#del(*args) ⇒ Object
Delete a key.
-
#discard ⇒ Object
Discard all commands issued after MULTI.
-
#echo(value) ⇒ Object
Echo the given string.
-
#eval(*args) ⇒ Object
Evaluate Lua script.
-
#evalsha(*args) ⇒ Object
Evaluate Lua script by its SHA.
-
#exec ⇒ Object
Execute all commands issued after MULTI.
-
#exists(key) ⇒ Object
Determine if a key exists.
-
#expire(key, seconds) ⇒ Object
Set a key's time to live in seconds.
-
#expireat(key, unix_time) ⇒ Object
Set the expiration for a key as a UNIX timestamp.
-
#flushall ⇒ Object
Remove all keys from all databases.
-
#flushdb ⇒ Object
Remove all keys from the current database.
-
#get(key) ⇒ Object
Get the value of a key.
-
#getbit(key, offset) ⇒ Object
Returns the bit value at offset in the string value stored at key.
-
#getrange(key, start, stop) ⇒ Object
Get a substring of the string stored at a key.
-
#getset(key, value) ⇒ Object
Set the string value of a key and return its old value.
-
#hdel(key, field) ⇒ Object
Delete one or more hash fields.
-
#hexists(key, field) ⇒ Object
Determine if a hash field exists.
-
#hget(key, field) ⇒ Object
Get the value of a hash field.
-
#hgetall(key) ⇒ Object
Get all the fields and values in a hash.
-
#hincrby(key, field, increment) ⇒ Object
Increment the integer value of a hash field by the given integer number.
-
#hincrbyfloat(key, field, increment) ⇒ Object
Increment the numeric value of a hash field by the given float number.
-
#hkeys(key) ⇒ Object
Get all the fields in a hash.
-
#hlen(key) ⇒ Object
Get the number of fields in a hash.
-
#hmget(key, *fields) ⇒ Object
Get the values of all the given hash fields.
-
#hmset(key, *attrs) ⇒ Object
Set multiple hash fields to multiple values.
-
#hset(key, field, value) ⇒ Object
Set the string value of a hash field.
-
#hsetnx(key, field, value) ⇒ Object
Set the value of a hash field, only if the field does not exist.
-
#hvals(key) ⇒ Object
Get all the values in a hash.
-
#incr(key) ⇒ Object
Increment the integer value of a key by one.
-
#incrby(key, increment) ⇒ Object
Increment the integer value of a key by the given integer number.
-
#incrbyfloat(key, increment) ⇒ Object
Increment the numeric value of a key by the given float number.
-
#info(cmd = nil) ⇒ Object
Get information and statistics about the server.
-
#initialize(urls, options = {}) ⇒ Distributed
constructor
A new instance of Distributed.
- #inspect ⇒ Object
-
#keys(glob = "*") ⇒ Object
Find all keys matching the given pattern.
-
#lastsave ⇒ Object
Get the UNIX time stamp of the last successful save to disk.
-
#lindex(key, index) ⇒ Object
Get an element from a list by its index.
-
#linsert(key, where, pivot, value) ⇒ Object
Insert an element before or after another element in a list.
-
#llen(key) ⇒ Object
Get the length of a list.
-
#lpop(key) ⇒ Object
Remove and get the first element in a list.
-
#lpush(key, value) ⇒ Object
Prepend one or more values to a list.
-
#lpushx(key, value) ⇒ Object
Prepend a value to a list, only if the list exists.
-
#lrange(key, start, stop) ⇒ Object
Get a range of elements from a list.
-
#lrem(key, count, value) ⇒ Object
Remove elements from a list.
-
#lset(key, index, value) ⇒ Object
Set the value of an element in a list by its index.
-
#ltrim(key, start, stop) ⇒ Object
Trim a list to the specified range.
- #mapped_hmget(key, *fields) ⇒ Object
- #mapped_hmset(key, hash) ⇒ Object
- #mapped_mget(*keys) ⇒ Object
- #mapped_mset(hash) ⇒ Object
- #mapped_msetnx(hash) ⇒ Object
-
#mget(*keys) ⇒ Object
Get the values of all the given keys.
-
#monitor ⇒ Object
Listen for all requests received by the server in real time.
-
#move(key, db) ⇒ Object
Move a key to another database.
-
#mset(*args) ⇒ Object
Set multiple keys to multiple values.
-
#msetnx(*args) ⇒ Object
Set multiple keys to multiple values, only if none of the keys exist.
-
#multi ⇒ Object
Mark the start of a transaction block.
- #node_for(key) ⇒ Object
- #nodes ⇒ Object
-
#persist(key) ⇒ Object
Remove the expiration from a key.
-
#pexpire(key, milliseconds) ⇒ Object
Set a key's time to live in milliseconds.
-
#pexpireat(key, ms_unix_time) ⇒ Object
Set the expiration for a key as number of milliseconds from UNIX Epoch.
-
#ping ⇒ Object
Ping the server.
- #pipelined ⇒ Object
-
#psetex(key, ttl, value) ⇒ Object
Set the time to live in milliseconds of a key.
-
#psubscribe(*channels, &block) ⇒ Object
Listen for messages published to channels matching the given patterns.
-
#pttl(key) ⇒ Object
Get the time to live (in milliseconds) for a key.
-
#publish(channel, message) ⇒ Object
Post a message to a channel.
-
#punsubscribe(*channels) ⇒ Object
Stop listening for messages posted to channels matching the given patterns.
-
#quit ⇒ Object
Close the connection.
-
#randomkey ⇒ Object
Return a random key from the keyspace.
-
#rename(old_name, new_name) ⇒ Object
Rename a key.
-
#renamenx(old_name, new_name) ⇒ Object
Rename a key, only if the new key does not exist.
-
#rpop(key) ⇒ Object
Remove and get the last element in a list.
-
#rpoplpush(source, destination) ⇒ Object
Remove the last element in a list, append it to another list and return it.
-
#rpush(key, value) ⇒ Object
Append one or more values to a list.
-
#rpushx(key, value) ⇒ Object
Append a value to a list, only if the list exists.
-
#sadd(key, member) ⇒ Object
Add one or more members to a set.
-
#save ⇒ Object
Synchronously save the dataset to disk.
-
#scard(key) ⇒ Object
Get the number of members in a set.
-
#script(subcommand, *args) ⇒ Object
Control remote script registry.
-
#sdiff(*keys) ⇒ Object
Subtract multiple sets.
-
#sdiffstore(destination, *keys) ⇒ Object
Subtract multiple sets and store the resulting set in a key.
-
#select(db) ⇒ Object
Change the selected database for the current connection.
-
#set(key, value) ⇒ Object
Set the string value of a key.
-
#setbit(key, offset, value) ⇒ Object
Sets or clears the bit at offset in the string value stored at key.
-
#setex(key, ttl, value) ⇒ Object
Set the time to live in seconds of a key.
-
#setnx(key, value) ⇒ Object
Set the value of a key, only if the key does not exist.
-
#setrange(key, offset, value) ⇒ Object
Overwrite part of a string at key starting at the specified offset.
-
#sinter(*keys) ⇒ Object
Intersect multiple sets.
-
#sinterstore(destination, *keys) ⇒ Object
Intersect multiple sets and store the resulting set in a key.
-
#sismember(key, member) ⇒ Object
Determine if a given value is a member of a set.
-
#smembers(key) ⇒ Object
Get all the members in a set.
-
#smove(source, destination, member) ⇒ Object
Move a member from one set to another.
-
#sort(key, options = {}) ⇒ Object
Sort the elements in a list, set or sorted set.
-
#spop(key) ⇒ Object
Remove and return a random member from a set.
-
#srandmember(key) ⇒ Object
Get a random member from a set.
-
#srem(key, member) ⇒ Object
Remove one or more members from a set.
-
#strlen(key) ⇒ Object
Get the length of the value stored in a key.
-
#subscribe(channel, *channels, &block) ⇒ Object
Listen for messages published to the given channels.
- #subscribed? ⇒ Boolean
-
#sunion(*keys) ⇒ Object
Add multiple sets.
-
#sunionstore(destination, *keys) ⇒ Object
Add multiple sets and store the resulting set in a key.
-
#time ⇒ Object
Get server time: an UNIX timestamp and the elapsed microseconds in the current second.
-
#ttl(key) ⇒ Object
Get the time to live (in seconds) for a key.
-
#type(key) ⇒ Object
Determine the type stored at key.
-
#unsubscribe(*channels) ⇒ Object
Stop listening for messages posted to the given channels.
-
#unwatch ⇒ Object
Forget about all watched keys.
-
#watch(*keys) ⇒ Object
Watch the given keys to determine execution of the MULTI/EXEC block.
-
#zadd(key, *args) ⇒ Object
Add one or more members to a sorted set, or update the score for members that already exist.
-
#zcard(key) ⇒ Object
Get the number of members in a sorted set.
-
#zcount(key, min, max) ⇒ Object
Get the number of members in a particular score range.
-
#zincrby(key, increment, member) ⇒ Object
Increment the score of a member in a sorted set.
-
#zinterstore(destination, keys, options = {}) ⇒ Object
Intersect multiple sorted sets and store the resulting sorted set in a new key.
-
#zrange(key, start, stop, options = {}) ⇒ Object
Return a range of members in a sorted set, by index.
-
#zrangebyscore(key, min, max, options = {}) ⇒ Object
Return a range of members in a sorted set, by score.
-
#zrank(key, member) ⇒ Object
Determine the index of a member in a sorted set.
-
#zrem(key, member) ⇒ Object
Remove one or more members from a sorted set.
-
#zremrangebyrank(key, start, stop) ⇒ Object
Remove all members in a sorted set within the given indexes.
-
#zremrangebyscore(key, min, max) ⇒ Object
Remove all members in a sorted set within the given scores.
-
#zrevrange(key, start, stop, options = {}) ⇒ Object
Return a range of members in a sorted set, by index, with scores ordered from high to low.
-
#zrevrangebyscore(key, max, min, options = {}) ⇒ Object
Return a range of members in a sorted set, by score, with scores ordered from high to low.
-
#zrevrank(key, member) ⇒ Object
Determine the index of a member in a sorted set, with scores ordered from high to low.
-
#zscore(key, member) ⇒ Object
Get the score associated with the given member in a sorted set.
-
#zunionstore(destination, keys, options = {}) ⇒ Object
Add multiple sorted sets and store the resulting sorted set in a new key.
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, = {}) @tag = .delete(:tag) || /^\{(.+?)\}/ @default_options = @ring = HashRing.new urls.map { |url| Redis.new(.merge(:url => url)) } @subscribed_node = nil end |
Instance Attribute Details
#ring ⇒ Object (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
305 306 307 |
# File 'lib/redis/distributed.rb', line 305 def [](key) get(key) end |
#[]=(key, value) ⇒ Object
309 310 311 |
# File 'lib/redis/distributed.rb', line 309 def []=(key,value) set(key, value) end |
#_bpop(cmd, args) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/redis/distributed.rb', line 356 def _bpop(cmd, args) = {} case args.last when Hash = args.pop when Integer # Issue deprecation notice in obnoxious mode... [: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, ) end end |
#_eval(cmd, args) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/redis/distributed.rb', line 753 def _eval(cmd, args) script = args.shift = args.pop if args.last.is_a?(Hash) ||= {} keys = args.shift || [:keys] || [] argv = args.shift || [:argv] || [] ensure_same_node(cmd, keys) do |node| node.send(cmd, script, keys, argv) end end |
#add_node(url) ⇒ Object
33 34 35 |
# File 'lib/redis/distributed.rb', line 33 def add_node(url) @ring.add_node Redis.new(@default_options.merge(:url => url)) end |
#append(key, value) ⇒ Object
Append a value to a key.
291 292 293 |
# File 'lib/redis/distributed.rb', line 291 def append(key, value) node_for(key).append(key, value) end |
#bgsave ⇒ Object
Asynchronously save the dataset to disk.
58 59 60 |
# File 'lib/redis/distributed.rb', line 58 def bgsave on_each_node :bgsave end |
#blpop(*args) ⇒ Object
Remove and get the first element in a list, or block until one is available.
380 381 382 |
# File 'lib/redis/distributed.rb', line 380 def blpop(*args) _bpop(:blpop, args) end |
#brpop(*args) ⇒ Object
Remove and get the last element in a list, or block until one is available.
386 387 388 |
# File 'lib/redis/distributed.rb', line 386 def brpop(*args) _bpop(:brpop, args) end |
#brpoplpush(source, destination, options = {}) ⇒ Object
Pop a value from a list, push it to another list and return it; or block until one is available.
392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/redis/distributed.rb', line 392 def brpoplpush(source, destination, = {}) case when Integer # Issue deprecation notice in obnoxious mode... = { :timeout => } end ensure_same_node(:brpoplpush, [source, destination]) do |node| node.brpoplpush(source, destination, ) end end |
#dbsize ⇒ Object
Return the number of keys in the selected database.
63 64 65 |
# File 'lib/redis/distributed.rb', line 63 def dbsize on_each_node :dbsize end |
#decr(key) ⇒ Object
Decrement the integer value of a key by one.
194 195 196 |
# File 'lib/redis/distributed.rb', line 194 def decr(key) node_for(key).decr(key) end |
#decrby(key, decrement) ⇒ Object
Decrement the integer value of a key by the given number.
199 200 201 |
# File 'lib/redis/distributed.rb', line 199 def decrby(key, decrement) node_for(key).decrby(key, decrement) end |
#del(*args) ⇒ Object
Delete a key.
138 139 140 141 142 143 |
# File 'lib/redis/distributed.rb', line 138 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 |
#discard ⇒ Object
Discard all commands issued after MULTI.
744 745 746 |
# File 'lib/redis/distributed.rb', line 744 def discard raise CannotDistribute, :discard end |
#echo(value) ⇒ Object
Echo the given string.
48 49 50 |
# File 'lib/redis/distributed.rb', line 48 def echo(value) on_each_node :echo, value end |
#eval(*args) ⇒ Object
Evaluate Lua script.
767 768 769 |
# File 'lib/redis/distributed.rb', line 767 def eval(*args) _eval(:eval, args) end |
#evalsha(*args) ⇒ Object
Evaluate Lua script by its SHA.
772 773 774 |
# File 'lib/redis/distributed.rb', line 772 def evalsha(*args) _eval(:evalsha, args) end |
#exec ⇒ Object
Execute all commands issued after MULTI.
739 740 741 |
# File 'lib/redis/distributed.rb', line 739 def exec raise CannotDistribute, :exec end |
#exists(key) ⇒ Object
Determine if a key exists.
146 147 148 |
# File 'lib/redis/distributed.rb', line 146 def exists(key) node_for(key).exists(key) end |
#expire(key, seconds) ⇒ Object
Set a key's time to live in seconds.
108 109 110 |
# File 'lib/redis/distributed.rb', line 108 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.
113 114 115 |
# File 'lib/redis/distributed.rb', line 113 def expireat(key, unix_time) node_for(key).expireat(key, unix_time) end |
#flushall ⇒ Object
Remove all keys from all databases.
68 69 70 |
# File 'lib/redis/distributed.rb', line 68 def flushall on_each_node :flushall end |
#flushdb ⇒ Object
Remove all keys from the current database.
73 74 75 |
# File 'lib/redis/distributed.rb', line 73 def flushdb on_each_node :flushdb end |
#get(key) ⇒ Object
Get the value of a key.
257 258 259 |
# File 'lib/redis/distributed.rb', line 257 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.
286 287 288 |
# File 'lib/redis/distributed.rb', line 286 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.
276 277 278 |
# File 'lib/redis/distributed.rb', line 276 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.
296 297 298 |
# File 'lib/redis/distributed.rb', line 296 def getset(key, value) node_for(key).getset(key, value) end |
#hdel(key, field) ⇒ Object
Delete one or more hash fields.
646 647 648 |
# File 'lib/redis/distributed.rb', line 646 def hdel(key, field) node_for(key).hdel(key, field) end |
#hexists(key, field) ⇒ Object
Determine if a hash field exists.
651 652 653 |
# File 'lib/redis/distributed.rb', line 651 def hexists(key, field) node_for(key).hexists(key, field) end |
#hget(key, field) ⇒ Object
Get the value of a hash field.
632 633 634 |
# File 'lib/redis/distributed.rb', line 632 def hget(key, field) node_for(key).hget(key, field) end |
#hgetall(key) ⇒ Object
Get all the fields and values in a hash.
676 677 678 |
# File 'lib/redis/distributed.rb', line 676 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 integer number.
656 657 658 |
# File 'lib/redis/distributed.rb', line 656 def hincrby(key, field, increment) node_for(key).hincrby(key, field, increment) end |
#hincrbyfloat(key, field, increment) ⇒ Object
Increment the numeric value of a hash field by the given float number.
661 662 663 |
# File 'lib/redis/distributed.rb', line 661 def hincrbyfloat(key, field, increment) node_for(key).hincrbyfloat(key, field, increment) end |
#hkeys(key) ⇒ Object
Get all the fields in a hash.
666 667 668 |
# File 'lib/redis/distributed.rb', line 666 def hkeys(key) node_for(key).hkeys(key) end |
#hlen(key) ⇒ Object
Get the number of fields in a hash.
608 609 610 |
# File 'lib/redis/distributed.rb', line 608 def hlen(key) node_for(key).hlen(key) end |
#hmget(key, *fields) ⇒ Object
Get the values of all the given hash fields.
637 638 639 |
# File 'lib/redis/distributed.rb', line 637 def hmget(key, *fields) node_for(key).hmget(key, *fields) end |
#hmset(key, *attrs) ⇒ Object
Set multiple hash fields to multiple values.
623 624 625 |
# File 'lib/redis/distributed.rb', line 623 def hmset(key, *attrs) node_for(key).hmset(key, *attrs) end |
#hset(key, field, value) ⇒ Object
Set the string value of a hash field.
613 614 615 |
# File 'lib/redis/distributed.rb', line 613 def hset(key, field, value) node_for(key).hset(key, field, value) end |
#hsetnx(key, field, value) ⇒ Object
Set the value of a hash field, only if the field does not exist.
618 619 620 |
# File 'lib/redis/distributed.rb', line 618 def hsetnx(key, field, value) node_for(key).hsetnx(key, field, value) end |
#hvals(key) ⇒ Object
Get all the values in a hash.
671 672 673 |
# File 'lib/redis/distributed.rb', line 671 def hvals(key) node_for(key).hvals(key) end |
#incr(key) ⇒ Object
Increment the integer value of a key by one.
204 205 206 |
# File 'lib/redis/distributed.rb', line 204 def incr(key) node_for(key).incr(key) end |
#incrby(key, increment) ⇒ Object
Increment the integer value of a key by the given integer number.
209 210 211 |
# File 'lib/redis/distributed.rb', line 209 def incrby(key, increment) node_for(key).incrby(key, increment) end |
#incrbyfloat(key, increment) ⇒ Object
Increment the numeric value of a key by the given float number.
214 215 216 |
# File 'lib/redis/distributed.rb', line 214 def incrbyfloat(key, increment) node_for(key).incrbyfloat(key, increment) end |
#info(cmd = nil) ⇒ Object
Get information and statistics about the server.
78 79 80 |
# File 'lib/redis/distributed.rb', line 78 def info(cmd = nil) on_each_node :info, cmd end |
#inspect ⇒ Object
776 777 778 |
# File 'lib/redis/distributed.rb', line 776 def inspect "#<Redis client v#{Redis::VERSION} for #{nodes.map(&:id).join(', ')}>" end |
#keys(glob = "*") ⇒ Object
Find all keys matching the given pattern.
151 152 153 |
# File 'lib/redis/distributed.rb', line 151 def keys(glob = "*") on_each_node(:keys, glob).flatten end |
#lastsave ⇒ Object
Get the UNIX time stamp of the last successful save to disk.
83 84 85 |
# File 'lib/redis/distributed.rb', line 83 def lastsave on_each_node :lastsave end |
#lindex(key, index) ⇒ Object
Get an element from a list by its index.
405 406 407 |
# File 'lib/redis/distributed.rb', line 405 def lindex(key, index) node_for(key).lindex(key, index) end |
#linsert(key, where, pivot, value) ⇒ Object
Insert an element before or after another element in a list.
410 411 412 |
# File 'lib/redis/distributed.rb', line 410 def linsert(key, where, pivot, value) node_for(key).linsert(key, where, pivot, value) end |
#llen(key) ⇒ Object
Get the length of a list.
314 315 316 |
# File 'lib/redis/distributed.rb', line 314 def llen(key) node_for(key).llen(key) end |
#lpop(key) ⇒ Object
Remove and get the first element in a list.
339 340 341 |
# File 'lib/redis/distributed.rb', line 339 def lpop(key) node_for(key).lpop(key) end |
#lpush(key, value) ⇒ Object
Prepend one or more values to a list.
319 320 321 |
# File 'lib/redis/distributed.rb', line 319 def lpush(key, value) node_for(key).lpush(key, value) end |
#lpushx(key, value) ⇒ Object
Prepend a value to a list, only if the list exists.
324 325 326 |
# File 'lib/redis/distributed.rb', line 324 def lpushx(key, value) node_for(key).lpushx(key, value) end |
#lrange(key, start, stop) ⇒ Object
Get a range of elements from a list.
415 416 417 |
# File 'lib/redis/distributed.rb', line 415 def lrange(key, start, stop) node_for(key).lrange(key, start, stop) end |
#lrem(key, count, value) ⇒ Object
Remove elements from a list.
420 421 422 |
# File 'lib/redis/distributed.rb', line 420 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.
425 426 427 |
# File 'lib/redis/distributed.rb', line 425 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.
430 431 432 |
# File 'lib/redis/distributed.rb', line 430 def ltrim(key, start, stop) node_for(key).ltrim(key, start, stop) end |
#mapped_hmget(key, *fields) ⇒ Object
641 642 643 |
# File 'lib/redis/distributed.rb', line 641 def mapped_hmget(key, *fields) Hash[*fields.zip(hmget(key, *fields)).flatten] end |
#mapped_hmset(key, hash) ⇒ Object
627 628 629 |
# File 'lib/redis/distributed.rb', line 627 def mapped_hmset(key, hash) node_for(key).hmset(key, *hash.to_a.flatten) end |
#mapped_mget(*keys) ⇒ Object
266 267 268 |
# File 'lib/redis/distributed.rb', line 266 def mapped_mget(*keys) raise CannotDistribute, :mapped_mget end |
#mapped_mset(hash) ⇒ Object
243 244 245 |
# File 'lib/redis/distributed.rb', line 243 def mapped_mset(hash) raise CannotDistribute, :mapped_mset end |
#mapped_msetnx(hash) ⇒ Object
252 253 254 |
# File 'lib/redis/distributed.rb', line 252 def mapped_msetnx(hash) raise CannotDistribute, :mapped_msetnx end |
#mget(*keys) ⇒ Object
Get the values of all the given keys.
262 263 264 |
# File 'lib/redis/distributed.rb', line 262 def mget(*keys) raise CannotDistribute, :mget end |
#monitor ⇒ Object
Listen for all requests received by the server in real time.
88 89 90 |
# File 'lib/redis/distributed.rb', line 88 def monitor raise NotImplementedError end |
#move(key, db) ⇒ Object
Move a key to another database.
156 157 158 |
# File 'lib/redis/distributed.rb', line 156 def move(key, db) node_for(key).move(key, db) end |
#mset(*args) ⇒ Object
Set multiple keys to multiple values.
239 240 241 |
# File 'lib/redis/distributed.rb', line 239 def mset(*args) raise CannotDistribute, :mset end |
#msetnx(*args) ⇒ Object
Set multiple keys to multiple values, only if none of the keys exist.
248 249 250 |
# File 'lib/redis/distributed.rb', line 248 def msetnx(*args) raise CannotDistribute, :msetnx end |
#multi ⇒ Object
Mark the start of a transaction block.
734 735 736 |
# File 'lib/redis/distributed.rb', line 734 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 |
#nodes ⇒ Object
29 30 31 |
# File 'lib/redis/distributed.rb', line 29 def nodes @ring.nodes end |
#persist(key) ⇒ Object
Remove the expiration from a key.
103 104 105 |
# File 'lib/redis/distributed.rb', line 103 def persist(key) node_for(key).persist(key) end |
#pexpire(key, milliseconds) ⇒ Object
Set a key's time to live in milliseconds.
123 124 125 |
# File 'lib/redis/distributed.rb', line 123 def pexpire(key, milliseconds) node_for(key).pexpire(key, milliseconds) end |
#pexpireat(key, ms_unix_time) ⇒ Object
Set the expiration for a key as number of milliseconds from UNIX Epoch.
128 129 130 |
# File 'lib/redis/distributed.rb', line 128 def pexpireat(key, ms_unix_time) node_for(key).pexpireat(key, ms_unix_time) end |
#ping ⇒ Object
Ping the server.
43 44 45 |
# File 'lib/redis/distributed.rb', line 43 def ping on_each_node :ping end |
#pipelined ⇒ Object
729 730 731 |
# File 'lib/redis/distributed.rb', line 729 def pipelined raise CannotDistribute, :pipelined end |
#psetex(key, ttl, value) ⇒ Object
Set the time to live in milliseconds of a key.
229 230 231 |
# File 'lib/redis/distributed.rb', line 229 def psetex(key, ttl, value) node_for(key).psetex(key, ttl, value) end |
#psubscribe(*channels, &block) ⇒ Object
Listen for messages published to channels matching the given patterns.
709 710 711 |
# File 'lib/redis/distributed.rb', line 709 def psubscribe(*channels, &block) raise NotImplementedError end |
#pttl(key) ⇒ Object
Get the time to live (in milliseconds) for a key.
133 134 135 |
# File 'lib/redis/distributed.rb', line 133 def pttl(key) node_for(key).pttl(key) end |
#publish(channel, message) ⇒ Object
Post a message to a channel.
681 682 683 |
# File 'lib/redis/distributed.rb', line 681 def publish(channel, ) node_for(channel).publish(channel, ) end |
#punsubscribe(*channels) ⇒ Object
Stop listening for messages posted to channels matching the given patterns.
715 716 717 |
# File 'lib/redis/distributed.rb', line 715 def punsubscribe(*channels) raise NotImplementedError end |
#quit ⇒ Object
Close the connection.
53 54 55 |
# File 'lib/redis/distributed.rb', line 53 def quit on_each_node :quit end |
#randomkey ⇒ Object
Return a random key from the keyspace.
161 162 163 |
# File 'lib/redis/distributed.rb', line 161 def randomkey raise CannotDistribute, :randomkey end |
#rename(old_name, new_name) ⇒ Object
Rename a key.
166 167 168 169 170 |
# File 'lib/redis/distributed.rb', line 166 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.
173 174 175 176 177 |
# File 'lib/redis/distributed.rb', line 173 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.
344 345 346 |
# File 'lib/redis/distributed.rb', line 344 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.
350 351 352 353 354 |
# File 'lib/redis/distributed.rb', line 350 def rpoplpush(source, destination) ensure_same_node(:rpoplpush, [source, destination]) do |node| node.rpoplpush(source, destination) end end |
#rpush(key, value) ⇒ Object
Append one or more values to a list.
329 330 331 |
# File 'lib/redis/distributed.rb', line 329 def rpush(key, value) node_for(key).rpush(key, value) end |
#rpushx(key, value) ⇒ Object
Append a value to a list, only if the list exists.
334 335 336 |
# File 'lib/redis/distributed.rb', line 334 def rpushx(key, value) node_for(key).rpushx(key, value) end |
#sadd(key, member) ⇒ Object
Add one or more members to a set.
440 441 442 |
# File 'lib/redis/distributed.rb', line 440 def sadd(key, member) node_for(key).sadd(key, member) end |
#save ⇒ Object
Synchronously save the dataset to disk.
93 94 95 |
# File 'lib/redis/distributed.rb', line 93 def save on_each_node :save end |
#scard(key) ⇒ Object
Get the number of members in a set.
435 436 437 |
# File 'lib/redis/distributed.rb', line 435 def scard(key) node_for(key).scard(key) end |
#script(subcommand, *args) ⇒ Object
Control remote script registry.
749 750 751 |
# File 'lib/redis/distributed.rb', line 749 def script(subcommand, *args) on_each_node(:script, subcommand, *args) end |
#sdiff(*keys) ⇒ Object
Subtract multiple sets.
477 478 479 480 481 |
# File 'lib/redis/distributed.rb', line 477 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.
484 485 486 487 488 |
# File 'lib/redis/distributed.rb', line 484 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.
38 39 40 |
# File 'lib/redis/distributed.rb', line 38 def select(db) on_each_node :select, db end |
#set(key, value) ⇒ Object
Set the string value of a key.
219 220 221 |
# File 'lib/redis/distributed.rb', line 219 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.
281 282 283 |
# File 'lib/redis/distributed.rb', line 281 def setbit(key, offset, value) node_for(key).setbit(key, offset, value) end |
#setex(key, ttl, value) ⇒ Object
Set the time to live in seconds of a key.
224 225 226 |
# File 'lib/redis/distributed.rb', line 224 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.
234 235 236 |
# File 'lib/redis/distributed.rb', line 234 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.
271 272 273 |
# File 'lib/redis/distributed.rb', line 271 def setrange(key, offset, value) node_for(key).setrange(key, offset, value) end |
#sinter(*keys) ⇒ Object
Intersect multiple sets.
491 492 493 494 495 |
# File 'lib/redis/distributed.rb', line 491 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.
498 499 500 501 502 |
# File 'lib/redis/distributed.rb', line 498 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.
467 468 469 |
# File 'lib/redis/distributed.rb', line 467 def sismember(key, member) node_for(key).sismember(key, member) end |
#smembers(key) ⇒ Object
Get all the members in a set.
472 473 474 |
# File 'lib/redis/distributed.rb', line 472 def smembers(key) node_for(key).smembers(key) end |
#smove(source, destination, member) ⇒ Object
Move a member from one set to another.
460 461 462 463 464 |
# File 'lib/redis/distributed.rb', line 460 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.
180 181 182 183 184 185 186 |
# File 'lib/redis/distributed.rb', line 180 def sort(key, = {}) keys = [key, [:by], [:store], *Array([:get])].compact ensure_same_node(:sort, keys) do |node| node.sort(key, ) end end |
#spop(key) ⇒ Object
Remove and return a random member from a set.
450 451 452 |
# File 'lib/redis/distributed.rb', line 450 def spop(key) node_for(key).spop(key) end |
#srandmember(key) ⇒ Object
Get a random member from a set.
455 456 457 |
# File 'lib/redis/distributed.rb', line 455 def srandmember(key) node_for(key).srandmember(key) end |
#srem(key, member) ⇒ Object
Remove one or more members from a set.
445 446 447 |
# File 'lib/redis/distributed.rb', line 445 def srem(key, member) node_for(key).srem(key, member) end |
#strlen(key) ⇒ Object
Get the length of the value stored in a key.
301 302 303 |
# File 'lib/redis/distributed.rb', line 301 def strlen(key) node_for(key).strlen(key) end |
#subscribe(channel, *channels, &block) ⇒ Object
Listen for messages published to the given channels.
690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/redis/distributed.rb', line 690 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
685 686 687 |
# File 'lib/redis/distributed.rb', line 685 def subscribed? !! @subscribed_node end |
#sunion(*keys) ⇒ Object
Add multiple sets.
505 506 507 508 509 |
# File 'lib/redis/distributed.rb', line 505 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.
512 513 514 515 516 |
# File 'lib/redis/distributed.rb', line 512 def sunionstore(destination, *keys) ensure_same_node(:sunionstore, [destination] + keys) do |node| node.sunionstore(destination, *keys) end end |
#time ⇒ Object
Get server time: an UNIX timestamp and the elapsed microseconds in the current second.
98 99 100 |
# File 'lib/redis/distributed.rb', line 98 def time on_each_node :time end |
#ttl(key) ⇒ Object
Get the time to live (in seconds) for a key.
118 119 120 |
# File 'lib/redis/distributed.rb', line 118 def ttl(key) node_for(key).ttl(key) end |
#type(key) ⇒ Object
Determine the type stored at key.
189 190 191 |
# File 'lib/redis/distributed.rb', line 189 def type(key) node_for(key).type(key) end |
#unsubscribe(*channels) ⇒ Object
Stop listening for messages posted to the given channels.
703 704 705 706 |
# File 'lib/redis/distributed.rb', line 703 def unsubscribe(*channels) raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed? @subscribed_node.unsubscribe(*channels) end |
#unwatch ⇒ Object
Forget about all watched keys.
725 726 727 |
# File 'lib/redis/distributed.rb', line 725 def unwatch raise CannotDistribute, :unwatch end |
#watch(*keys) ⇒ Object
Watch the given keys to determine execution of the MULTI/EXEC block.
720 721 722 |
# File 'lib/redis/distributed.rb', line 720 def watch(*keys) raise CannotDistribute, :watch end |
#zadd(key, *args) ⇒ Object
Add one or more members to a sorted set, or update the score for members that already exist.
525 526 527 |
# File 'lib/redis/distributed.rb', line 525 def zadd(key, *args) node_for(key).zadd(key, *args) end |
#zcard(key) ⇒ Object
Get the number of members in a sorted set.
519 520 521 |
# File 'lib/redis/distributed.rb', line 519 def zcard(key) node_for(key).zcard(key) end |
#zcount(key, min, max) ⇒ Object
Get the number of members in a particular score range.
588 589 590 |
# File 'lib/redis/distributed.rb', line 588 def zcount(key, min, max) node_for(key).zcount(key, min, max) end |
#zincrby(key, increment, member) ⇒ Object
Increment the score of a member in a sorted set.
530 531 532 |
# File 'lib/redis/distributed.rb', line 530 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.
594 595 596 597 598 |
# File 'lib/redis/distributed.rb', line 594 def zinterstore(destination, keys, = {}) ensure_same_node(:zinterstore, [destination] + keys) do |node| node.zinterstore(destination, keys, ) end end |
#zrange(key, start, stop, options = {}) ⇒ Object
Return a range of members in a sorted set, by index.
545 546 547 |
# File 'lib/redis/distributed.rb', line 545 def zrange(key, start, stop, = {}) node_for(key).zrange(key, start, stop, ) end |
#zrangebyscore(key, min, max, options = {}) ⇒ Object
Return a range of members in a sorted set, by score.
572 573 574 |
# File 'lib/redis/distributed.rb', line 572 def zrangebyscore(key, min, max, = {}) node_for(key).zrangebyscore(key, min, max, ) end |
#zrank(key, member) ⇒ Object
Determine the index of a member in a sorted set.
556 557 558 |
# File 'lib/redis/distributed.rb', line 556 def zrank(key, member) node_for(key).zrank(key, member) end |
#zrem(key, member) ⇒ Object
Remove one or more members from a sorted set.
535 536 537 |
# File 'lib/redis/distributed.rb', line 535 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.
567 568 569 |
# File 'lib/redis/distributed.rb', line 567 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.
583 584 585 |
# File 'lib/redis/distributed.rb', line 583 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.
551 552 553 |
# File 'lib/redis/distributed.rb', line 551 def zrevrange(key, start, stop, = {}) node_for(key).zrevrange(key, start, stop, ) 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.
578 579 580 |
# File 'lib/redis/distributed.rb', line 578 def zrevrangebyscore(key, max, min, = {}) node_for(key).zrevrangebyscore(key, max, min, ) end |
#zrevrank(key, member) ⇒ Object
Determine the index of a member in a sorted set, with scores ordered from high to low.
562 563 564 |
# File 'lib/redis/distributed.rb', line 562 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.
540 541 542 |
# File 'lib/redis/distributed.rb', line 540 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.
601 602 603 604 605 |
# File 'lib/redis/distributed.rb', line 601 def zunionstore(destination, keys, = {}) ensure_same_node(:zunionstore, [destination] + keys) do |node| node.zunionstore(destination, keys, ) end end |