Class: Redis::Distributed
| Relationships & Source Files | |
| Namespace Children | |
|
Exceptions:
| |
| Inherits: | Object |
| Defined in: | lib/redis/distributed.rb |
Class Method Summary
- .new(node_configs, options = {}) ⇒ Distributed constructor
Instance Attribute Summary
- #ring readonly
- #subscribed? ⇒ Boolean readonly
Instance Method Summary
- #[](key)
- #[]=(key, value)
- #_bpop(cmd, args)
- #_eval(cmd, args)
- #add_node(options)
-
#append(key, value)
Append a value to a key.
-
#bgsave
Asynchronously save the dataset to disk.
-
#bitcount(key, start = 0, stop = -1,, scale: nil)
Count the number of set bits in a range of the string value stored at key.
-
#bitop(operation, destkey, *keys)
Perform a bitwise operation between strings and store the resulting string in a key.
-
#bitpos(key, bit, start = nil, stop = nil, scale: nil)
Return the position of the first bit set to 1 or 0 in a string.
-
#blmove(source, destination, where_source, where_destination, timeout: 0)
Remove the first/last element in a list and append/prepend it to another list and return it, or block until one is available.
-
#blmpop(timeout, *keys, modifier: "LEFT", count: nil)
Iterate over keys, blocking and removing elements from the first non empty liist found.
-
#blpop(*args)
Remove and get the first element in a list, or block until one is available.
-
#brpop(*args)
Remove and get the last element in a list, or block until one is available.
-
#brpoplpush(source, destination, **options)
Pop a value from a list, push it to another list and return it; or block until one is available.
-
#bzmpop(timeout, *keys, modifier: "MIN", count: nil)
Iterate over keys, blocking and removing members from the first non empty sorted set found.
- #bzpopmax(*args)
- #bzpopmin(*args)
- #close
-
#copy(source, destination, **options)
Copy a value from one key to another.
-
#dbsize
Return the number of keys in the selected database.
-
#decr(key)
Decrement the integer value of a key by one.
-
#decrby(key, decrement)
Decrement the integer value of a key by the given number.
-
#del(*args)
Delete a key.
-
#discard
Discard all commands issued after MULTI.
-
#dump(key)
Return a serialized version of the value stored at a key.
- #dup
-
#echo(value)
Echo the given string.
-
#eval(*args)
Evaluate Lua script.
-
#evalsha(*args)
Evaluate Lua script by its SHA.
-
#exec
Execute all commands issued after MULTI.
-
#exists(*args)
Determine if a key exists.
-
#exists?(*args) ⇒ Boolean
Determine if any of the keys exists.
-
#expire(key, seconds, **kwargs)
Set a key's time to live in seconds.
-
#expireat(key, unix_time, **kwargs)
Set the expiration for a key as a UNIX timestamp.
-
#expiretime(key)
Get the expiration for a key as a UNIX timestamp.
-
#flushall
Remove all keys from all databases.
-
#flushdb
Remove all keys from the current database.
-
#geoadd(key, *member, **options)
Add one or more geospatial items to a sorted set.
-
#geodist(key, member1, member2, unit = 'm')
Get the distance between two members of a geospatial index.
-
#geohash(key, member)
Get geohash strings representing the position of one or more members.
-
#geopos(key, member)
Get longitude and latitude of one or more members of a geospatial index.
-
#georadius(*args, **geoptions)
Query a geospatial index for members within a given radius from a point.
-
#georadiusbymember(*args, **geoptions)
Query a geospatial index for members within a given radius from an existing member.
-
#geosearch(key, **options)
Search a geospatial index for members within a given shape from a center point.
-
#geosearchstore(destination, source, **options)
Like #geosearch, but stores the result in a destination key.
-
#get(key)
Get the value of a key.
-
#getbit(key, offset)
Returns the bit value at offset in the string value stored at key.
-
#getdel(key)
Get the value of a key and delete it.
-
#getex(key, **options)
Get the value of a key and sets its time to live based on options.
-
#getrange(key, start, stop)
Get a substring of the string stored at a key.
-
#getset(key, value)
Set the string value of a key and return its old value.
-
#hdel(key, *fields)
Delete one or more hash fields.
-
#hexists(key, field)
Determine if a hash field exists.
- #hexpire(key, ttl, *fields)
-
#hget(key, field)
Get the value of a hash field.
-
#hgetall(key)
Get all the fields and values in a hash.
-
#hincrby(key, field, increment)
Increment the integer value of a hash field by the given integer number.
-
#hincrbyfloat(key, field, increment)
Increment the numeric value of a hash field by the given float number.
-
#hkeys(key)
Get all the fields in a hash.
-
#hlen(key)
Get the number of fields in a hash.
-
#hmget(key, *fields)
Get the values of all the given hash fields.
-
#hmset(key, *attrs)
Set multiple hash fields to multiple values.
- #hpexpire(key, ttl, *fields, nx: nil, xx: nil, gt: nil, lt: nil)
- #hpttl(key, *fields)
- #hrandfield(key, count = nil, **options)
-
#hscan(key, cursor, **options)
Scan a hash.
-
#hscan_each(key, **options, &block)
Scan a hash and return an enumerator.
-
#hset(key, *attrs)
Set multiple hash fields to multiple values.
-
#hsetnx(key, field, value)
Set the value of a hash field, only if the field does not exist.
-
#hstrlen(key, field)
Get the length of the value stored in a hash field.
- #httl(key, *fields)
-
#hvals(key)
Get all the values in a hash.
-
#incr(key)
Increment the integer value of a key by one.
-
#incrby(key, increment)
Increment the integer value of a key by the given integer number.
-
#incrbyfloat(key, increment)
Increment the numeric value of a key by the given float number.
-
#info(cmd = nil)
Get information and statistics about the server.
- #inspect
-
#json_arrappend(key, path, *values, **options)
Append one or more values to the JSON array at a path in the document stored under a key.
-
#json_arrindex(key, path, value, **options)
Return the index of the first occurrence of a scalar in the JSON array at a path.
-
#json_arrinsert(key, path, index, *values, **options)
Insert one or more values into the JSON array at a path in the document stored under a key.
-
#json_arrlen(key, path = nil)
Return the length of the JSON array at a path in the document stored under a key.
-
#json_arrpop(key, path = nil, index = nil, **options)
Remove and return an element from the JSON array at a path in the document stored under a key.
-
#json_arrtrim(key, path, start, stop)
Trim the JSON array at a path in the document stored under a key to an inclusive range.
-
#json_clear(key, path = nil)
Clear the container and numeric JSON value(s) at a path in the document stored under a key.
-
#json_debug_memory(key, path = nil)
Report the size in bytes of the JSON value(s) at a path in the document stored under a key.
-
#json_del(key, path = nil)
Delete the JSON value(s) at a path in the document stored under a key.
-
#json_forget(key, path = nil)
Delete the JSON value(s) at a path in the document stored under a key (alias of json_del).
-
#json_get(key, *paths, **options)
Get the JSON value(s) at one or more paths in the document stored under a key.
-
#json_merge(key, path, value, **options)
Merge a JSON value into the document stored under a key at a path.
-
#json_mget(*keys, path, **options)
Get the values at a path from several keys.
-
#json_mset
Set one or more JSON values.
-
#json_numincrby(key, path, number)
Increment the numeric JSON value(s) at a path in the document stored under a key.
-
#json_objkeys(key, path = nil)
Return the key names of the JSON object(s) at a path in the document stored under a key.
-
#json_objlen(key, path = nil)
Return the number of keys in the JSON object(s) at a path in the document stored under a key.
-
#json_set(key, path, value, **options)
Set the JSON value at a path in the document stored under a key.
-
#json_strappend(key, path, value, **options)
Append a string to the JSON string(s) at a path in the document stored under a key.
-
#json_strlen(key, path = nil)
Return the length of the JSON string(s) at a path in the document stored under a key.
-
#json_toggle(key, path)
Toggle the boolean JSON value(s) at a path in the document stored under a key.
-
#json_type(key, path = nil)
Return the type name(s) of the JSON value(s) at a path in the document stored under a key.
-
#keys(glob = "*")
Find all keys matching the given pattern.
-
#lastsave
Get the UNIX time stamp of the last successful save to disk.
-
#lindex(key, index)
Get an element from a list by its index.
-
#linsert(key, where, pivot, value)
Insert an element before or after another element in a list.
-
#llen(key)
Get the length of a list.
-
#lmove(source, destination, where_source, where_destination)
Remove the first/last element in a list, append/prepend it to another list and return it.
-
#lmpop(*keys, modifier: "LEFT", count: nil)
Iterate over keys, removing elements from the first non list found.
-
#lpop(key, count = nil)
Remove and get the first elements in a list.
-
#lpush(key, value)
Prepend one or more values to a list.
-
#lpushx(key, value)
Prepend a value to a list, only if the list exists.
-
#lrange(key, start, stop)
Get a range of elements from a list.
-
#lrem(key, count, value)
Remove elements from a list.
-
#lset(key, index, value)
Set the value of an element in a list by its index.
-
#ltrim(key, start, stop)
Trim a list to the specified range.
- #mapped_hmget(key, *fields)
- #mapped_hmset(key, hash)
-
#mapped_mget(*keys)
Get the values of all the given keys as a Hash.
- #mapped_mset(_hash)
- #mapped_msetnx(_hash)
-
#mget(*keys)
Get the values of all the given keys as an Array.
-
#migrate(_key, _options)
Transfer a key from the connected instance to another instance.
-
#monitor
Listen for all requests received by the server in real time.
-
#move(key, db)
Move a key to another database.
-
#mset
Set multiple keys to multiple values.
-
#msetnx
Set multiple keys to multiple values, only if none of the keys exist.
-
#multi(&block)
Mark the start of a transaction block.
- #node_for(key)
- #nodes
-
#persist(key)
Remove the expiration from a key.
-
#pexpire(key, milliseconds, **kwarg)
Set a key's time to live in milliseconds.
-
#pexpireat(key, ms_unix_time, **kwarg)
Set the expiration for a key as number of milliseconds from UNIX Epoch.
-
#pexpiretime(key)
Get the expiration for a key as number of milliseconds from UNIX Epoch.
-
#pfadd(key, member)
Add one or more members to a HyperLogLog structure.
-
#pfcount(*keys)
Get the approximate cardinality of members added to HyperLogLog structure.
-
#pfmerge(dest_key, *source_key)
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
-
#ping
Ping the server.
- #pipelined
-
#psetex(key, ttl, value)
Set the time to live in milliseconds of a key.
-
#psubscribe(*channels, &block)
Listen for messages published to channels matching the given patterns.
-
#pttl(key)
Get the time to live (in milliseconds) for a key.
-
#publish(channel, message)
Post a message to a channel.
-
#punsubscribe(*channels)
Stop listening for messages posted to channels matching the given patterns.
-
#quit
Close the connection.
-
#randomkey
Return a random key from the keyspace.
-
#rename(old_name, new_name)
Rename a key.
-
#renamenx(old_name, new_name)
Rename a key, only if the new key does not exist.
-
#restore(key, ttl, serialized_value, **options)
Create a key using the serialized value, previously obtained using DUMP.
-
#rpop(key, count = nil)
Remove and get the last elements in a list.
-
#rpoplpush(source, destination)
Remove the last element in a list, append it to another list and return it.
-
#rpush(key, value)
Append one or more values to a list.
-
#rpushx(key, value)
Append a value to a list, only if the list exists.
-
#sadd(key, *members)
Add one or more members to a set.
-
#sadd?(key, *members) ⇒ Boolean
Add one or more members to a set.
-
#save
Synchronously save the dataset to disk.
-
#scard(key)
Get the number of members in a set.
-
#script(subcommand, *args)
Control remote script registry.
-
#sdiff(*keys)
Subtract multiple sets.
-
#sdiffstore(destination, *keys)
Subtract multiple sets and store the resulting set in a key.
-
#select(db)
Change the selected database for the current connection.
-
#set(key, value, **options)
Set the string value of a key.
-
#setbit(key, offset, value)
Sets or clears the bit at offset in the string value stored at key.
-
#setex(key, ttl, value)
Set the time to live in seconds of a key.
-
#setnx(key, value)
Set the value of a key, only if the key does not exist.
-
#setrange(key, offset, value)
Overwrite part of a string at key starting at the specified offset.
-
#sinter(*keys)
Intersect multiple sets.
-
#sinterstore(destination, *keys)
Intersect multiple sets and store the resulting set in a key.
-
#sismember(key, member)
Determine if a given value is a member of a set.
-
#smembers(key)
Get all the members in a set.
-
#smismember(key, *members)
Determine if multiple values are members of a set.
-
#smove(source, destination, member)
Move a member from one set to another.
-
#sort(key, **options)
Sort the elements in a list, set or sorted set.
-
#spop(key, count = nil)
Remove and return a random member from a set.
-
#srandmember(key, count = nil)
Get a random member from a set.
-
#srem(key, *members)
Remove one or more members from a set.
-
#srem?(key, *members) ⇒ Boolean
Remove one or more members from a set.
-
#sscan(key, cursor, **options)
Scan a set.
-
#sscan_each(key, **options, &block)
Scan a set and return an enumerator.
-
#strlen(key)
Get the length of the value stored in a key.
-
#subscribe(channel, *channels, &block)
Listen for messages published to the given channels.
-
#sunion(*keys)
Add multiple sets.
-
#sunionstore(destination, *keys)
Add multiple sets and store the resulting set in a key.
-
#time
Get server time: an UNIX timestamp and the elapsed microseconds in the current second.
-
#ttl(key)
Get the time to live (in seconds) for a key.
-
#type(key)
Determine the type stored at key.
-
#unlink(*args)
Unlink keys.
-
#unsubscribe(*channels)
Stop listening for messages posted to the given channels.
-
#unwatch
Forget about all watched keys.
-
#watch(*keys, &block)
Watch the given keys to determine execution of the MULTI/EXEC block.
-
#zadd(key, *args)
Add one or more members to a sorted set, or update the score for members that already exist.
-
#zcard(key)
Get the number of members in a sorted set.
-
#zcount(key, min, max)
Get the number of members in a particular score range.
-
#zdiff(*keys, **options)
Return the difference between the first and all successive input sorted sets.
-
#zdiffstore(destination, *keys, **options)
Compute the difference between the first and all successive input sorted sets and store the resulting sorted set in a new key.
-
#zincrby(key, increment, member)
Increment the score of a member in a sorted set.
-
#zinter(*keys, **options)
Get the intersection of multiple sorted sets.
-
#zinterstore(destination, *keys, **options)
Intersect multiple sorted sets and store the resulting sorted set in a new key.
-
#zmpop(*keys, modifier: "MIN", count: nil)
Iterate over keys, removing members from the first non empty sorted set found.
-
#zmscore(key, *members)
Get the scores associated with the given members in a sorted set.
-
#zrandmember(key, count = nil, **options)
Get one or more random members from a sorted set.
-
#zrange(key, start, stop, **options)
Return a range of members in a sorted set, by index, score or lexicographical ordering.
-
#zrangebyscore(key, min, max, **options)
Return a range of members in a sorted set, by score.
-
#zrangestore(dest_key, src_key, start, stop, **options)
Select a range of members in a sorted set, by index, score or lexicographical ordering and store the resulting sorted set in a new key.
-
#zrank(key, member, **options)
Determine the index of a member in a sorted set.
-
#zrem(key, member)
Remove one or more members from a sorted set.
-
#zremrangebyrank(key, start, stop)
Remove all members in a sorted set within the given indexes.
-
#zremrangebyscore(key, min, max)
Remove all members in a sorted set within the given scores.
-
#zrevrange(key, start, stop, **options)
Return a range of members in a sorted set, by index, with scores ordered from high to low.
-
#zrevrangebyscore(key, max, min, **options)
Return a range of members in a sorted set, by score, with scores ordered from high to low.
-
#zrevrank(key, member, **options)
Determine the index of a member in a sorted set, with scores ordered from high to low.
-
#zscore(key, member)
Get the score associated with the given member in a sorted set.
-
#zunion(*keys, **options)
Return the union of multiple sorted sets.
-
#zunionstore(destination, *keys, **options)
Add multiple sorted sets and store the resulting sorted set in a new key.
- #ensure_same_node(command, keys) {|node_for(keys.first)| ... } protected
- #key_tag(key) protected
- #node_index_for(key) protected
- #on_each_node(command, *args) protected
Constructor Details
.new(node_configs, options = {}) ⇒ Distributed
# File 'lib/redis/distributed.rb', line 20
def initialize(node_configs, = {}) @tag = [:tag] || /^\{(.+?)\}/ @ring = [:ring] || HashRing.new @node_configs = node_configs.map(&:dup) @default_options = .dup node_configs.each { |node_config| add_node(node_config) } @subscribed_node = nil @watch_key = nil end
Instance Attribute Details
#ring (readonly)
[ GitHub ]# File 'lib/redis/distributed.rb', line 18
attr_reader :ring
#subscribed? ⇒ Boolean (readonly)
[ GitHub ]
# File 'lib/redis/distributed.rb', line 1120
def subscribed? !!@subscribed_node end
Instance Method Details
#[](key)
[ GitHub ]# File 'lib/redis/distributed.rb', line 528
def [](key) get(key) end
#[]=(key, value)
[ GitHub ]# File 'lib/redis/distributed.rb', line 532
def []=(key, value) set(key, value) end
#_bpop(cmd, args)
[ GitHub ]# File 'lib/redis/distributed.rb', line 594
def _bpop(cmd, args) timeout = if args.last.is_a?(Hash) = args.pop [:timeout] end args.flatten!(1) ensure_same_node(cmd, args) do |node| if timeout node.__send__(cmd, args, timeout: timeout) else node.__send__(cmd, args) end end end
#_eval(cmd, args)
[ GitHub ]#add_node(options)
[ GitHub ]#append(key, value)
Append a value to a key.
# File 'lib/redis/distributed.rb', line 496
def append(key, value) node_for(key).append(key, value) end
#bgsave
Asynchronously save the dataset to disk.
# File 'lib/redis/distributed.rb', line 74
def bgsave on_each_node :bgsave end
#bitcount(key, start = 0, stop = -1,, scale: nil)
Count the number of set bits in a range of the string value stored at key.
# File 'lib/redis/distributed.rb', line 501
def bitcount(key, start = 0, stop = -1, scale: nil) node_for(key).bitcount(key, start, stop, scale: scale) end
#bitop(operation, destkey, *keys)
Perform a bitwise operation between strings and store the resulting string in a key.
# File 'lib/redis/distributed.rb', line 506
def bitop(operation, destkey, *keys) keys.flatten!(1) ensure_same_node(:bitop, [destkey] + keys) do |node| node.bitop(operation, destkey, keys) end end
#bitpos(key, bit, start = nil, stop = nil, scale: nil)
Return the position of the first bit set to 1 or 0 in a string.
# File 'lib/redis/distributed.rb', line 514
def bitpos(key, bit, start = nil, stop = nil, scale: nil) node_for(key).bitpos(key, bit, start, stop, scale: scale) end
#blmove(source, destination, where_source, where_destination, timeout: 0)
Remove the first/last element in a list and append/prepend it to another list and return it, or block until one is available.
# File 'lib/redis/distributed.rb', line 550
def blmove(source, destination, where_source, where_destination, timeout: 0) ensure_same_node(:lmove, [source, destination]) do |node| node.blmove(source, destination, where_source, where_destination, timeout: timeout) end end
#blmpop(timeout, *keys, modifier: "LEFT", count: nil)
Iterate over keys, blocking and removing elements from the first non empty liist found.
# File 'lib/redis/distributed.rb', line 674
def blmpop(timeout, *keys, modifier: "LEFT", count: nil) ensure_same_node(:blmpop, keys) do |node| node.blmpop(timeout, *keys, modifier: modifier, count: count) end end
#blpop(*args)
Remove and get the first element in a list, or block until one is available.
# File 'lib/redis/distributed.rb', line 613
def blpop(*args) _bpop(:blpop, args) end
#brpop(*args)
Remove and get the last element in a list, or block until one is available.
# File 'lib/redis/distributed.rb', line 631
def brpop(*args) _bpop(:brpop, args) end
#brpoplpush(source, destination, **options)
Pop a value from a list, push it to another list and return it; or block until one is available.
# File 'lib/redis/distributed.rb', line 637
def brpoplpush(source, destination, **) ensure_same_node(:brpoplpush, [source, destination]) do |node| node.brpoplpush(source, destination, **) end end
#bzmpop(timeout, *keys, modifier: "MIN", count: nil)
Iterate over keys, blocking and removing members from the first non empty sorted set found.
# File 'lib/redis/distributed.rb', line 840
def bzmpop(timeout, *keys, modifier: "MIN", count: nil) ensure_same_node(:bzmpop, keys) do |node| node.bzmpop(timeout, *keys, modifier: modifier, count: count) end end
#bzpopmax(*args)
[ GitHub ]#bzpopmin(*args)
[ GitHub ]#close
[ GitHub ]# File 'lib/redis/distributed.rb', line 69
def close on_each_node :close end
#copy(source, destination, **options)
Copy a value from one key to another.
# File 'lib/redis/distributed.rb', line 226
def copy(source, destination, **) ensure_same_node(:copy, [source, destination]) do |node| node.copy(source, destination, **) end end
#dbsize
Return the number of keys in the selected database.
# File 'lib/redis/distributed.rb', line 79
def dbsize on_each_node :dbsize end
#decr(key)
Decrement the integer value of a key by one.
# File 'lib/redis/distributed.rb', line 266
def decr(key) node_for(key).decr(key) end
#decrby(key, decrement)
Decrement the integer value of a key by the given number.
# File 'lib/redis/distributed.rb', line 271
def decrby(key, decrement) node_for(key).decrby(key, decrement) end
#del(*args)
Delete a key.
#discard
Discard all commands issued after MULTI.
# File 'lib/redis/distributed.rb', line 1203
def discard raise CannotDistribute, :discard unless @watch_key result = node_for(@watch_key).discard @watch_key = nil result end
#dump(key)
Return a serialized version of the value stored at a key.
# File 'lib/redis/distributed.rb', line 164
def dump(key) node_for(key).dump(key) end
#dup
[ GitHub ]# File 'lib/redis/distributed.rb', line 1263
def dup self.class.new(@node_configs, @default_options) end
#echo(value)
Echo the given string.
# File 'lib/redis/distributed.rb', line 60
def echo(value) on_each_node :echo, value end
#ensure_same_node(command, keys) {|node_for(keys.first)| ... } (protected)
# File 'lib/redis/distributed.rb', line 1284
def ensure_same_node(command, keys) all = true = keys.map do |key| tag = key_tag(key) all = false unless tag tag end if (all && .uniq.size != 1) || (!all && keys.uniq.size != 1) # Not 1 unique tag or not 1 unique key raise CannotDistribute, command end yield(node_for(keys.first)) end
#eval(*args)
Evaluate Lua script.
# File 'lib/redis/distributed.rb', line 1250
def eval(*args) _eval(:eval, args) end
#evalsha(*args)
Evaluate Lua script by its SHA.
# File 'lib/redis/distributed.rb', line 1255
def evalsha(*args) _eval(:evalsha, args) end
#exec
Execute all commands issued after MULTI.
# File 'lib/redis/distributed.rb', line 1194
def exec raise CannotDistribute, :exec unless @watch_key result = node_for(@watch_key).exec @watch_key = nil result end
#exists(*args)
Determine if a key exists.
#exists?(*args) ⇒ Boolean
Determine if any of the keys exists.
#expire(key, seconds, **kwargs)
Set a key's time to live in seconds.
# File 'lib/redis/distributed.rb', line 124
def expire(key, seconds, **kwargs) node_for(key).expire(key, seconds, **kwargs) end
#expireat(key, unix_time, **kwargs)
Set the expiration for a key as a UNIX timestamp.
# File 'lib/redis/distributed.rb', line 129
def expireat(key, unix_time, **kwargs) node_for(key).expireat(key, unix_time, **kwargs) end
#expiretime(key)
Get the expiration for a key as a UNIX timestamp.
# File 'lib/redis/distributed.rb', line 134
def expiretime(key) node_for(key).expiretime(key) end
#flushall
Remove all keys from all databases.
# File 'lib/redis/distributed.rb', line 84
def flushall on_each_node :flushall end
#flushdb
Remove all keys from the current database.
# File 'lib/redis/distributed.rb', line 89
def flushdb on_each_node :flushdb end
#geoadd(key, *member, **options)
Add one or more geospatial items to a sorted set.
# File 'lib/redis/distributed.rb', line 1071
def geoadd(key, *member, **) node_for(key).geoadd(key, *member, **) end
#geodist(key, member1, member2, unit = 'm')
Get the distance between two members of a geospatial index.
# File 'lib/redis/distributed.rb', line 1086
def geodist(key, member1, member2, unit = 'm') node_for(key).geodist(key, member1, member2, unit) end
#geohash(key, member)
Get geohash strings representing the position of one or more members.
# File 'lib/redis/distributed.rb', line 1076
def geohash(key, member) node_for(key).geohash(key, member) end
#geopos(key, member)
Get longitude and latitude of one or more members of a geospatial index.
# File 'lib/redis/distributed.rb', line 1081
def geopos(key, member) node_for(key).geopos(key, member) end
#georadius(*args, **geoptions)
Query a geospatial index for members within a given radius from a point.
# File 'lib/redis/distributed.rb', line 1091
def georadius(*args, **) key = args.first node_for(key).georadius(*args, **) end
#georadiusbymember(*args, **geoptions)
Query a geospatial index for members within a given radius from an existing member.
# File 'lib/redis/distributed.rb', line 1097
def georadiusbymember(*args, **) key = args.first node_for(key).georadiusbymember(*args, **) end
#geosearch(key, **options)
Search a geospatial index for members within a given shape from a center point.
# File 'lib/redis/distributed.rb', line 1103
def geosearch(key, **) node_for(key).geosearch(key, **) end
#geosearchstore(destination, source, **options)
Like #geosearch, but stores the result in a destination key. Destination and source must hash to the same node; use a key tag to ensure that.
# File 'lib/redis/distributed.rb', line 1109
def geosearchstore(destination, source, **) ensure_same_node(:geosearchstore, [destination, source]) do |node| node.geosearchstore(destination, source, **) end end
#get(key)
Get the value of a key.
# File 'lib/redis/distributed.rb', line 329
def get(key) node_for(key).get(key) end
#getbit(key, offset)
Returns the bit value at offset in the string value stored at key.
# File 'lib/redis/distributed.rb', line 491
def getbit(key, offset) node_for(key).getbit(key, offset) end
#getdel(key)
Get the value of a key and delete it.
# File 'lib/redis/distributed.rb', line 334
def getdel(key) node_for(key).getdel(key) end
#getex(key, **options)
Get the value of a key and sets its time to live based on options.
# File 'lib/redis/distributed.rb', line 339
def getex(key, **) node_for(key).getex(key, **) end
#getrange(key, start, stop)
Get a substring of the string stored at a key.
# File 'lib/redis/distributed.rb', line 481
def getrange(key, start, stop) node_for(key).getrange(key, start, stop) end
#getset(key, value)
Set the string value of a key and return its old value.
# File 'lib/redis/distributed.rb', line 519
def getset(key, value) node_for(key).getset(key, value) end
#hdel(key, *fields)
Delete one or more hash fields.
# File 'lib/redis/distributed.rb', line 1004
def hdel(key, *fields) fields.flatten!(1) node_for(key).hdel(key, fields) end
#hexists(key, field)
Determine if a hash field exists.
# File 'lib/redis/distributed.rb', line 1010
def hexists(key, field) node_for(key).hexists(key, field) end
#hexpire(key, ttl, *fields)
[ GitHub ]#hget(key, field)
Get the value of a hash field.
# File 'lib/redis/distributed.rb', line 984
def hget(key, field) node_for(key).hget(key, field) end
#hgetall(key)
Get all the fields and values in a hash.
# File 'lib/redis/distributed.rb', line 1035
def hgetall(key) node_for(key).hgetall(key) end
#hincrby(key, field, increment)
Increment the integer value of a hash field by the given integer number.
# File 'lib/redis/distributed.rb', line 1015
def hincrby(key, field, increment) node_for(key).hincrby(key, field, increment) end
#hincrbyfloat(key, field, increment)
Increment the numeric value of a hash field by the given float number.
# File 'lib/redis/distributed.rb', line 1020
def hincrbyfloat(key, field, increment) node_for(key).hincrbyfloat(key, field, increment) end
#hkeys(key)
Get all the fields in a hash.
# File 'lib/redis/distributed.rb', line 1025
def hkeys(key) node_for(key).hkeys(key) end
#hlen(key)
Get the number of fields in a hash.
# File 'lib/redis/distributed.rb', line 960
def hlen(key) node_for(key).hlen(key) end
#hmget(key, *fields)
Get the values of all the given hash fields.
# File 'lib/redis/distributed.rb', line 989
def hmget(key, *fields) fields.flatten!(1) node_for(key).hmget(key, fields) end
#hmset(key, *attrs)
Set multiple hash fields to multiple values.
# File 'lib/redis/distributed.rb', line 975
def hmset(key, *attrs) node_for(key).hmset(key, *attrs) end
#hpexpire(key, ttl, *fields, nx: nil, xx: nil, gt: nil, lt: nil)
[ GitHub ]#hpttl(key, *fields)
[ GitHub ]# File 'lib/redis/distributed.rb', line 1066
def hpttl(key, *fields) node_for(key).hpttl(key, *fields) end
#hrandfield(key, count = nil, **options)
[ GitHub ]# File 'lib/redis/distributed.rb', line 999
def hrandfield(key, count = nil, **) node_for(key).hrandfield(key, count, **) end
#hscan(key, cursor, **options)
Scan a hash
# File 'lib/redis/distributed.rb', line 1048
def hscan(key, cursor, **) node_for(key).hscan(key, cursor, **) end
#hscan_each(key, **options, &block)
Scan a hash and return an enumerator
# File 'lib/redis/distributed.rb', line 1053
def hscan_each(key, **, &block) node_for(key).hscan_each(key, **, &block) end
#hset(key, *attrs)
Set multiple hash fields to multiple values.
# File 'lib/redis/distributed.rb', line 965
def hset(key, *attrs) node_for(key).hset(key, *attrs) end
#hsetnx(key, field, value)
Set the value of a hash field, only if the field does not exist.
# File 'lib/redis/distributed.rb', line 970
def hsetnx(key, field, value) node_for(key).hsetnx(key, field, value) end
#hstrlen(key, field)
Get the length of the value stored in a hash field
# File 'lib/redis/distributed.rb', line 1058
def hstrlen(key, field) node_for(key).hstrlen(key, field) end
#httl(key, *fields)
[ GitHub ]# File 'lib/redis/distributed.rb', line 1043
def httl(key, *fields) node_for(key).httl(key, *fields) end
#hvals(key)
Get all the values in a hash.
# File 'lib/redis/distributed.rb', line 1030
def hvals(key) node_for(key).hvals(key) end
#incr(key)
Increment the integer value of a key by one.
# File 'lib/redis/distributed.rb', line 276
def incr(key) node_for(key).incr(key) end
#incrby(key, increment)
Increment the integer value of a key by the given integer number.
# File 'lib/redis/distributed.rb', line 281
def incrby(key, increment) node_for(key).incrby(key, increment) end
#incrbyfloat(key, increment)
Increment the numeric value of a key by the given float number.
# File 'lib/redis/distributed.rb', line 286
def incrbyfloat(key, increment) node_for(key).incrbyfloat(key, increment) end
#info(cmd = nil)
Get information and statistics about the server.
# File 'lib/redis/distributed.rb', line 94
def info(cmd = nil) on_each_node :info, cmd end
#inspect
[ GitHub ]#json_arrappend(key, path, *values, **options)
Append one or more values to the JSON array at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 392
def json_arrappend(key, path, *values, **) node_for(key).json_arrappend(key, path, *values, **) end
#json_arrindex(key, path, value, **options)
Return the index of the first occurrence of a scalar in the JSON array at a path.
# File 'lib/redis/distributed.rb', line 397
def json_arrindex(key, path, value, **) node_for(key).json_arrindex(key, path, value, **) end
#json_arrinsert(key, path, index, *values, **options)
Insert one or more values into the JSON array at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 402
def json_arrinsert(key, path, index, *values, **) node_for(key).json_arrinsert(key, path, index, *values, **) end
#json_arrlen(key, path = nil)
Return the length of the JSON array at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 407
def json_arrlen(key, path = nil) node_for(key).json_arrlen(key, path) end
#json_arrpop(key, path = nil, index = nil, **options)
Remove and return an element from the JSON array at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 412
def json_arrpop(key, path = nil, index = nil, **) node_for(key).json_arrpop(key, path, index, **) end
#json_arrtrim(key, path, start, stop)
Trim the JSON array at a path in the document stored under a key to an inclusive range.
# File 'lib/redis/distributed.rb', line 417
def json_arrtrim(key, path, start, stop) node_for(key).json_arrtrim(key, path, start, stop) end
#json_clear(key, path = nil)
Clear the container and numeric JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 382
def json_clear(key, path = nil) node_for(key).json_clear(key, path) end
#json_debug_memory(key, path = nil)
Report the size in bytes of the JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 457
def json_debug_memory(key, path = nil) node_for(key).json_debug_memory(key, path) end
#json_del(key, path = nil)
Delete the JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 372
def json_del(key, path = nil) node_for(key).json_del(key, path) end
#json_forget(key, path = nil)
Delete the JSON value(s) at a path in the document stored under a key (alias of json_del).
# File 'lib/redis/distributed.rb', line 377
def json_forget(key, path = nil) node_for(key).json_forget(key, path) end
#json_get(key, *paths, **options)
Get the JSON value(s) at one or more paths in the document stored under a key.
# File 'lib/redis/distributed.rb', line 349
def json_get(key, *paths, **) node_for(key).json_get(key, *paths, **) end
#json_merge(key, path, value, **options)
Merge a JSON value into the document stored under a key at a path.
# File 'lib/redis/distributed.rb', line 387
def json_merge(key, path, value, **) node_for(key).json_merge(key, path, value, **) end
#json_mget(*keys, path, **options)
Get the values at a path from several keys. Keys are grouped by node, queried per node, and reassembled in the original key order.
# File 'lib/redis/distributed.rb', line 361
def json_mget(*keys, path, **) keys.flatten!(1) values = keys.group_by { |key| node_for(key) }.each_with_object({}) do |(node, subkeys), acc| node.json_mget(*subkeys, path, **).each_with_index do |value, i| acc[subkeys[i]] = value end end keys.map { |key| values[key] } end
#json_mset
Set one or more JSON values. The keys may live on different nodes and the operation must be atomic, so it cannot be distributed.
# File 'lib/redis/distributed.rb', line 355
def json_mset(*) raise CannotDistribute, :json_mset end
#json_numincrby(key, path, number)
Increment the numeric JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 422
def json_numincrby(key, path, number) node_for(key).json_numincrby(key, path, number) end
#json_objkeys(key, path = nil)
Return the key names of the JSON object(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 432
def json_objkeys(key, path = nil) node_for(key).json_objkeys(key, path) end
#json_objlen(key, path = nil)
Return the number of keys in the JSON object(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 437
def json_objlen(key, path = nil) node_for(key).json_objlen(key, path) end
#json_set(key, path, value, **options)
Set the JSON value at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 344
def json_set(key, path, value, **) node_for(key).json_set(key, path, value, **) end
#json_strappend(key, path, value, **options)
Append a string to the JSON string(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 447
def json_strappend(key, path, value, **) node_for(key).json_strappend(key, path, value, **) end
#json_strlen(key, path = nil)
Return the length of the JSON string(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 442
def json_strlen(key, path = nil) node_for(key).json_strlen(key, path) end
#json_toggle(key, path)
Toggle the boolean JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 452
def json_toggle(key, path) node_for(key).json_toggle(key, path) end
#json_type(key, path = nil)
Return the type name(s) of the JSON value(s) at a path in the document stored under a key.
# File 'lib/redis/distributed.rb', line 427
def json_type(key, path = nil) node_for(key).json_type(key, path) end
#key_tag(key) (protected)
[ GitHub ]# File 'lib/redis/distributed.rb', line 1279
def key_tag(key) key = key.to_s key[@tag, 1] if key.match?(@tag) end
#keys(glob = "*")
Find all keys matching the given pattern.
# File 'lib/redis/distributed.rb', line 216
def keys(glob = "*") on_each_node(:keys, glob).flatten end
#lastsave
Get the UNIX time stamp of the last successful save to disk.
# File 'lib/redis/distributed.rb', line 99
def lastsave on_each_node :lastsave end
#lindex(key, index)
Get an element from a list by its index.
# File 'lib/redis/distributed.rb', line 644
def lindex(key, index) node_for(key).lindex(key, index) end
#linsert(key, where, pivot, value)
Insert an element before or after another element in a list.
# File 'lib/redis/distributed.rb', line 649
def linsert(key, where, pivot, value) node_for(key).linsert(key, where, pivot, value) end
#llen(key)
Get the length of a list.
# File 'lib/redis/distributed.rb', line 537
def llen(key) node_for(key).llen(key) end
#lmove(source, destination, where_source, where_destination)
Remove the first/last element in a list, append/prepend it to another list and return it.
# File 'lib/redis/distributed.rb', line 542
def lmove(source, destination, where_source, where_destination) ensure_same_node(:lmove, [source, destination]) do |node| node.lmove(source, destination, where_source, where_destination) end end
#lmpop(*keys, modifier: "LEFT", count: nil)
Iterate over keys, removing elements from the first non list found.
# File 'lib/redis/distributed.rb', line 681
def lmpop(*keys, modifier: "LEFT", count: nil) ensure_same_node(:lmpop, keys) do |node| node.lmpop(*keys, modifier: modifier, count: count) end end
#lpop(key, count = nil)
Remove and get the first elements in a list.
# File 'lib/redis/distributed.rb', line 577
def lpop(key, count = nil) node_for(key).lpop(key, count) end
#lpush(key, value)
Prepend one or more values to a list.
# File 'lib/redis/distributed.rb', line 557
def lpush(key, value) node_for(key).lpush(key, value) end
#lpushx(key, value)
Prepend a value to a list, only if the list exists.
# File 'lib/redis/distributed.rb', line 562
def lpushx(key, value) node_for(key).lpushx(key, value) end
#lrange(key, start, stop)
Get a range of elements from a list.
# File 'lib/redis/distributed.rb', line 654
def lrange(key, start, stop) node_for(key).lrange(key, start, stop) end
#lrem(key, count, value)
Remove elements from a list.
# File 'lib/redis/distributed.rb', line 659
def lrem(key, count, value) node_for(key).lrem(key, count, value) end
#lset(key, index, value)
Set the value of an element in a list by its index.
# File 'lib/redis/distributed.rb', line 664
def lset(key, index, value) node_for(key).lset(key, index, value) end
#ltrim(key, start, stop)
Trim a list to the specified range.
# File 'lib/redis/distributed.rb', line 669
def ltrim(key, start, stop) node_for(key).ltrim(key, start, stop) end
#mapped_hmget(key, *fields)
[ GitHub ]# File 'lib/redis/distributed.rb', line 994
def mapped_hmget(key, *fields) fields.flatten!(1) node_for(key).mapped_hmget(key, fields) end
#mapped_hmset(key, hash)
[ GitHub ]#mapped_mget(*keys)
Get the values of all the given keys as a Hash.
#mapped_mset(_hash)
# File 'lib/redis/distributed.rb', line 315
def mapped_mset(_hash) raise CannotDistribute, :mapped_mset end
#mapped_msetnx(_hash)
# File 'lib/redis/distributed.rb', line 324
def mapped_msetnx(_hash) raise CannotDistribute, :mapped_msetnx end
#mget(*keys)
Get the values of all the given keys as an Array.
# File 'lib/redis/distributed.rb', line 462
def mget(*keys) keys.flatten!(1) mapped_mget(*keys).values_at(*keys) end
#migrate(_key, _options)
Transfer a key from the connected instance to another instance.
# File 'lib/redis/distributed.rb', line 174
def migrate(_key, ) raise CannotDistribute, :migrate end
#monitor
Listen for all requests received by the server in real time.
# File 'lib/redis/distributed.rb', line 104
def monitor raise NotImplementedError end
#move(key, db)
Move a key to another database.
# File 'lib/redis/distributed.rb', line 221
def move(key, db) node_for(key).move(key, db) end
#mset
Set multiple keys to multiple values.
# File 'lib/redis/distributed.rb', line 311
def mset(*) raise CannotDistribute, :mset end
#msetnx
Set multiple keys to multiple values, only if none of the keys exist.
# File 'lib/redis/distributed.rb', line 320
def msetnx(*) raise CannotDistribute, :msetnx end
#multi(&block)
Mark the start of a transaction block.
# File 'lib/redis/distributed.rb', line 1187
def multi(&block) raise CannotDistribute, :multi unless @watch_key node_for(@watch_key).multi(&block) end
#node_for(key)
# File 'lib/redis/distributed.rb', line 30
def node_for(key) key = key_tag(key.to_s) || key.to_s raise CannotDistribute, :watch if @watch_key && @watch_key != key @ring.get_node(key) end
#node_index_for(key) (protected)
[ GitHub ]#nodes
[ GitHub ]# File 'lib/redis/distributed.rb', line 37
def nodes @ring.nodes end
#on_each_node(command, *args) (protected)
[ GitHub ]# File 'lib/redis/distributed.rb', line 1269
def on_each_node(command, *args) nodes.map do |node| node.send(command, *args) end end
#persist(key)
Remove the expiration from a key.
# File 'lib/redis/distributed.rb', line 119
def persist(key) node_for(key).persist(key) end
#pexpire(key, milliseconds, **kwarg)
Set a key's time to live in milliseconds.
# File 'lib/redis/distributed.rb', line 144
def pexpire(key, milliseconds, **kwarg) node_for(key).pexpire(key, milliseconds, **kwarg) end
#pexpireat(key, ms_unix_time, **kwarg)
Set the expiration for a key as number of milliseconds from UNIX Epoch.
# File 'lib/redis/distributed.rb', line 149
def pexpireat(key, ms_unix_time, **kwarg) node_for(key).pexpireat(key, ms_unix_time, **kwarg) end
#pexpiretime(key)
Get the expiration for a key as number of milliseconds from UNIX Epoch.
# File 'lib/redis/distributed.rb', line 154
def pexpiretime(key) node_for(key).pexpiretime(key) end
#pfadd(key, member)
Add one or more members to a HyperLogLog structure.
# File 'lib/redis/distributed.rb', line 1217
def pfadd(key, member) node_for(key).pfadd(key, member) end
#pfcount(*keys)
Get the approximate cardinality of members added to HyperLogLog structure.
# File 'lib/redis/distributed.rb', line 1222
def pfcount(*keys) ensure_same_node(:pfcount, keys.flatten(1)) do |node| node.pfcount(keys) end end
#pfmerge(dest_key, *source_key)
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
# File 'lib/redis/distributed.rb', line 1230
def pfmerge(dest_key, *source_key) ensure_same_node(:pfmerge, [dest_key, *source_key]) do |node| node.pfmerge(dest_key, *source_key) end end
#ping
Ping the server.
# File 'lib/redis/distributed.rb', line 55
def ping on_each_node :ping end
#pipelined
# File 'lib/redis/distributed.rb', line 1182
def pipelined raise CannotDistribute, :pipelined end
#psetex(key, ttl, value)
Set the time to live in milliseconds of a key.
#psubscribe(*channels, &block)
Listen for messages published to channels matching the given patterns. See the Redis Server PSUBSCRIBE documentation for further details
# File 'lib/redis/distributed.rb', line 1147
def psubscribe(*channels, &block) raise NotImplementedError end
#pttl(key)
Get the time to live (in milliseconds) for a key.
# File 'lib/redis/distributed.rb', line 159
def pttl(key) node_for(key).pttl(key) end
#publish(channel, message)
Post a message to a channel.
# File 'lib/redis/distributed.rb', line 1116
def publish(channel, ) node_for(channel).publish(channel, ) end
#punsubscribe(*channels)
Stop listening for messages posted to channels matching the given patterns. See the Redis Server PUNSUBSCRIBE documentation for further details
# File 'lib/redis/distributed.rb', line 1155
def punsubscribe(*channels) raise NotImplementedError end
#quit
Close the connection.
# File 'lib/redis/distributed.rb', line 65
def quit on_each_node :quit end
#randomkey
Return a random key from the keyspace.
# File 'lib/redis/distributed.rb', line 233
def randomkey raise CannotDistribute, :randomkey end
#rename(old_name, new_name)
Rename a key.
# File 'lib/redis/distributed.rb', line 238
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)
Rename a key, only if the new key does not exist.
# File 'lib/redis/distributed.rb', line 245
def renamenx(old_name, new_name) ensure_same_node(:renamenx, [old_name, new_name]) do |node| node.renamenx(old_name, new_name) end end
#restore(key, ttl, serialized_value, **options)
Create a key using the serialized value, previously obtained using DUMP.
#rpop(key, count = nil)
Remove and get the last elements in a list.
# File 'lib/redis/distributed.rb', line 582
def rpop(key, count = nil) node_for(key).rpop(key, count) end
#rpoplpush(source, destination)
Remove the last element in a list, append it to another list and return it.
# File 'lib/redis/distributed.rb', line 588
def rpoplpush(source, destination) ensure_same_node(:rpoplpush, [source, destination]) do |node| node.rpoplpush(source, destination) end end
#rpush(key, value)
Append one or more values to a list.
# File 'lib/redis/distributed.rb', line 567
def rpush(key, value) node_for(key).rpush(key, value) end
#rpushx(key, value)
Append a value to a list, only if the list exists.
# File 'lib/redis/distributed.rb', line 572
def rpushx(key, value) node_for(key).rpushx(key, value) end
#sadd(key, *members)
Add one or more members to a set.
# File 'lib/redis/distributed.rb', line 693
def sadd(key, *members) node_for(key).sadd(key, *members) end
#sadd?(key, *members) ⇒ Boolean
Add one or more members to a set.
# File 'lib/redis/distributed.rb', line 698
def sadd?(key, *members) node_for(key).sadd?(key, *members) end
#save
Synchronously save the dataset to disk.
# File 'lib/redis/distributed.rb', line 109
def save on_each_node :save end
#scard(key)
Get the number of members in a set.
# File 'lib/redis/distributed.rb', line 688
def scard(key) node_for(key).scard(key) end
#script(subcommand, *args)
Control remote script registry.
# File 'lib/redis/distributed.rb', line 1212
def script(subcommand, *args) on_each_node(:script, subcommand, *args) end
#sdiff(*keys)
Subtract multiple sets.
# File 'lib/redis/distributed.rb', line 755
def sdiff(*keys) keys.flatten!(1) ensure_same_node(:sdiff, keys) do |node| node.sdiff(keys) end end
#sdiffstore(destination, *keys)
Subtract multiple sets and store the resulting set in a key.
# File 'lib/redis/distributed.rb', line 763
def sdiffstore(destination, *keys) keys.flatten!(1) ensure_same_node(:sdiffstore, [destination].concat(keys)) do |node| node.sdiffstore(destination, keys) end end
#select(db)
Change the selected database for the current connection.
# File 'lib/redis/distributed.rb', line 50
def select(db) on_each_node :select, db end
#set(key, value, **options)
Set the string value of a key.
# File 'lib/redis/distributed.rb', line 291
def set(key, value, **) node_for(key).set(key, value, **) end
#setbit(key, offset, value)
Sets or clears the bit at offset in the string value stored at key.
# File 'lib/redis/distributed.rb', line 486
def setbit(key, offset, value) node_for(key).setbit(key, offset, value) end
#setex(key, ttl, value)
Set the time to live in seconds of a key.
#setnx(key, value)
Set the value of a key, only if the key does not exist.
# File 'lib/redis/distributed.rb', line 306
def setnx(key, value) node_for(key).setnx(key, value) end
#setrange(key, offset, value)
Overwrite part of a string at key starting at the specified offset.
# File 'lib/redis/distributed.rb', line 476
def setrange(key, offset, value) node_for(key).setrange(key, offset, value) end
#sinter(*keys)
Intersect multiple sets.
# File 'lib/redis/distributed.rb', line 771
def sinter(*keys) keys.flatten!(1) ensure_same_node(:sinter, keys) do |node| node.sinter(keys) end end
#sinterstore(destination, *keys)
Intersect multiple sets and store the resulting set in a key.
# File 'lib/redis/distributed.rb', line 779
def sinterstore(destination, *keys) keys.flatten!(1) ensure_same_node(:sinterstore, [destination].concat(keys)) do |node| node.sinterstore(destination, keys) end end
#sismember(key, member)
Determine if a given value is a member of a set.
# File 'lib/redis/distributed.rb', line 730
def sismember(key, member) node_for(key).sismember(key, member) end
#smembers(key)
Get all the members in a set.
# File 'lib/redis/distributed.rb', line 740
def smembers(key) node_for(key).smembers(key) end
#smismember(key, *members)
Determine if multiple values are members of a set.
# File 'lib/redis/distributed.rb', line 735
def smismember(key, *members) node_for(key).smismember(key, *members) end
#smove(source, destination, member)
Move a member from one set to another.
# File 'lib/redis/distributed.rb', line 723
def smove(source, destination, member) ensure_same_node(:smove, [source, destination]) do |node| node.smove(source, destination, member) end end
#sort(key, **options)
Sort the elements in a list, set or sorted set.
# File 'lib/redis/distributed.rb', line 252
def sort(key, **) keys = [key, [:by], [:store], *Array([:get])].compact ensure_same_node(:sort, keys) do |node| node.sort(key, **) end end
#spop(key, count = nil)
Remove and return a random member from a set.
# File 'lib/redis/distributed.rb', line 713
def spop(key, count = nil) node_for(key).spop(key, count) end
#srandmember(key, count = nil)
Get a random member from a set.
# File 'lib/redis/distributed.rb', line 718
def srandmember(key, count = nil) node_for(key).srandmember(key, count) end
#srem(key, *members)
Remove one or more members from a set.
# File 'lib/redis/distributed.rb', line 703
def srem(key, *members) node_for(key).srem(key, *members) end
#srem?(key, *members) ⇒ Boolean
Remove one or more members from a set.
# File 'lib/redis/distributed.rb', line 708
def srem?(key, *members) node_for(key).srem?(key, *members) end
#sscan(key, cursor, **options)
Scan a set
# File 'lib/redis/distributed.rb', line 745
def sscan(key, cursor, **) node_for(key).sscan(key, cursor, **) end
#sscan_each(key, **options, &block)
Scan a set and return an enumerator
# File 'lib/redis/distributed.rb', line 750
def sscan_each(key, **, &block) node_for(key).sscan_each(key, **, &block) end
#strlen(key)
Get the length of the value stored in a key.
# File 'lib/redis/distributed.rb', line 524
def strlen(key) node_for(key).strlen(key) end
#subscribe(channel, *channels, &block)
Listen for messages published to the given channels.
# File 'lib/redis/distributed.rb', line 1125
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
#sunion(*keys)
Add multiple sets.
# File 'lib/redis/distributed.rb', line 787
def sunion(*keys) keys.flatten!(1) ensure_same_node(:sunion, keys) do |node| node.sunion(keys) end end
#sunionstore(destination, *keys)
Add multiple sets and store the resulting set in a key.
# File 'lib/redis/distributed.rb', line 795
def sunionstore(destination, *keys) keys.flatten!(1) ensure_same_node(:sunionstore, [destination].concat(keys)) do |node| node.sunionstore(destination, keys) end end
#time
Get server time: an UNIX timestamp and the elapsed microseconds in the current second.
# File 'lib/redis/distributed.rb', line 114
def time on_each_node :time end
#ttl(key)
Get the time to live (in seconds) for a key.
# File 'lib/redis/distributed.rb', line 139
def ttl(key) node_for(key).ttl(key) end
#type(key)
Determine the type stored at key.
# File 'lib/redis/distributed.rb', line 261
def type(key) node_for(key).type(key) end
#unlink(*args)
Unlink keys.
#unsubscribe(*channels)
Stop listening for messages posted to the given channels.
# File 'lib/redis/distributed.rb', line 1138
def unsubscribe(*channels) raise SubscriptionError, "Can't unsubscribe if not subscribed." unless subscribed? @subscribed_node.unsubscribe(*channels) end
#unwatch
Forget about all watched keys.
# File 'lib/redis/distributed.rb', line 1174
def unwatch raise CannotDistribute, :unwatch unless @watch_key result = node_for(@watch_key).unwatch @watch_key = nil result end
#watch(*keys, &block)
Watch the given keys to determine execution of the MULTI/EXEC block.
#zadd(key, *args)
Add one or more members to a sorted set, or update the score for members that already exist.
# File 'lib/redis/distributed.rb', line 809
def zadd(key, *args) node_for(key).zadd(key, *args) end
#zcard(key)
Get the number of members in a sorted set.
# File 'lib/redis/distributed.rb', line 803
def zcard(key) node_for(key).zcard(key) end
#zcount(key, min, max)
Get the number of members in a particular score range.
# File 'lib/redis/distributed.rb', line 905
def zcount(key, min, max) node_for(key).zcount(key, min, max) end
#zdiff(*keys, **options)
Return the difference between the first and all successive input sorted sets.
# File 'lib/redis/distributed.rb', line 943
def zdiff(*keys, **) keys.flatten!(1) ensure_same_node(:zdiff, keys) do |node| node.zdiff(keys, **) end end
#zdiffstore(destination, *keys, **options)
Compute the difference between the first and all successive input sorted sets and store the resulting sorted set in a new key.
# File 'lib/redis/distributed.rb', line 952
def zdiffstore(destination, *keys, **) keys.flatten!(1) ensure_same_node(:zdiffstore, [destination] + keys) do |node| node.zdiffstore(destination, keys, **) end end
#zincrby(key, increment, member)
Increment the score of a member in a sorted set.
# File 'lib/redis/distributed.rb', line 815
def zincrby(key, increment, member) node_for(key).zincrby(key, increment, member) end
#zinter(*keys, **options)
Get the intersection of multiple sorted sets
# File 'lib/redis/distributed.rb', line 910
def zinter(*keys, **) keys.flatten!(1) ensure_same_node(:zinter, keys) do |node| node.zinter(keys, **) end end
#zinterstore(destination, *keys, **options)
Intersect multiple sorted sets and store the resulting sorted set in a new key.
# File 'lib/redis/distributed.rb', line 919
def zinterstore(destination, *keys, **) keys.flatten!(1) ensure_same_node(:zinterstore, [destination].concat(keys)) do |node| node.zinterstore(destination, keys, **) end end
#zmpop(*keys, modifier: "MIN", count: nil)
Iterate over keys, removing members from the first non empty sorted set found.
# File 'lib/redis/distributed.rb', line 847
def zmpop(*keys, modifier: "MIN", count: nil) ensure_same_node(:zmpop, keys) do |node| node.zmpop(*keys, modifier: modifier, count: count) end end
#zmscore(key, *members)
Get the scores associated with the given members in a sorted set.
# File 'lib/redis/distributed.rb', line 835
def zmscore(key, *members) node_for(key).zmscore(key, *members) end
#zrandmember(key, count = nil, **options)
Get one or more random members from a sorted set.
# File 'lib/redis/distributed.rb', line 830
def zrandmember(key, count = nil, **) node_for(key).zrandmember(key, count, **) end
#zrange(key, start, stop, **options)
Return a range of members in a sorted set, by index, score or lexicographical ordering.
# File 'lib/redis/distributed.rb', line 854
def zrange(key, start, stop, **) node_for(key).zrange(key, start, stop, **) end
#zrangebyscore(key, min, max, **options)
Return a range of members in a sorted set, by score.
# File 'lib/redis/distributed.rb', line 889
def zrangebyscore(key, min, max, **) node_for(key).zrangebyscore(key, min, max, **) end
#zrangestore(dest_key, src_key, start, stop, **options)
Select a range of members in a sorted set, by index, score or lexicographical ordering and store the resulting sorted set in a new key.
# File 'lib/redis/distributed.rb', line 860
def zrangestore(dest_key, src_key, start, stop, **) ensure_same_node(:zrangestore, [dest_key, src_key]) do |node| node.zrangestore(dest_key, src_key, start, stop, **) end end
#zrank(key, member, **options)
Determine the index of a member in a sorted set.
# File 'lib/redis/distributed.rb', line 873
def zrank(key, member, **) node_for(key).zrank(key, member, **) end
#zrem(key, member)
Remove one or more members from a sorted set.
# File 'lib/redis/distributed.rb', line 820
def zrem(key, member) node_for(key).zrem(key, member) end
#zremrangebyrank(key, start, stop)
Remove all members in a sorted set within the given indexes.
# File 'lib/redis/distributed.rb', line 884
def zremrangebyrank(key, start, stop) node_for(key).zremrangebyrank(key, start, stop) end
#zremrangebyscore(key, min, max)
Remove all members in a sorted set within the given scores.
# File 'lib/redis/distributed.rb', line 900
def zremrangebyscore(key, min, max) node_for(key).zremrangebyscore(key, min, max) end
#zrevrange(key, start, stop, **options)
Return a range of members in a sorted set, by index, with scores ordered from high to low.
# File 'lib/redis/distributed.rb', line 868
def zrevrange(key, start, stop, **) node_for(key).zrevrange(key, start, stop, **) end
#zrevrangebyscore(key, max, min, **options)
Return a range of members in a sorted set, by score, with scores ordered from high to low.
# File 'lib/redis/distributed.rb', line 895
def zrevrangebyscore(key, max, min, **) node_for(key).zrevrangebyscore(key, max, min, **) end
#zrevrank(key, member, **options)
Determine the index of a member in a sorted set, with scores ordered from high to low.
# File 'lib/redis/distributed.rb', line 879
def zrevrank(key, member, **) node_for(key).zrevrank(key, member, **) end
#zscore(key, member)
Get the score associated with the given member in a sorted set.
# File 'lib/redis/distributed.rb', line 825
def zscore(key, member) node_for(key).zscore(key, member) end
#zunion(*keys, **options)
Return the union of multiple sorted sets.
# File 'lib/redis/distributed.rb', line 927
def zunion(*keys, **) keys.flatten!(1) ensure_same_node(:zunion, keys) do |node| node.zunion(keys, **) end end
#zunionstore(destination, *keys, **options)
Add multiple sorted sets and store the resulting sorted set in a new key.
# File 'lib/redis/distributed.rb', line 935
def zunionstore(destination, *keys, **) keys.flatten!(1) ensure_same_node(:zunionstore, [destination].concat(keys)) do |node| node.zunionstore(destination, keys, **) end end