class Redis::Distributed
Attributes
Public Class Methods
# File lib/redis/distributed.rb, line 19 def initialize(node_configs, options = {}) @tag = options[:tag] || /^\{(.+?)\}/ @ring = options[:ring] || HashRing.new @node_configs = node_configs.dup @default_options = options.dup node_configs.each { |node_config| add_node(node_config) } @subscribed_node = nil @watch_key = nil end
Public Instance Methods
# File lib/redis/distributed.rb, line 382 def [](key) get(key) end
# File lib/redis/distributed.rb, line 386 def []=(key, value) set(key, value) end
# File lib/redis/distributed.rb, line 433 def _bpop(cmd, args) timeout = if args.last.is_a?(Hash) options = args.pop options[:timeout] elsif args.last.respond_to?(:to_int) # Issue deprecation notice in obnoxious mode... args.pop.to_int end if args.size > 1 # Issue deprecation notice in obnoxious mode... end keys = args.flatten ensure_same_node(cmd, keys) do |node| if timeout node.__send__(cmd, keys, timeout: timeout) else node.__send__(cmd, keys) end end end
# File lib/redis/distributed.rb, line 883 def _eval(cmd, args) script = args.shift options = args.pop if args.last.is_a?(Hash) options ||= {} keys = args.shift || options[:keys] || [] argv = args.shift || options[:argv] || [] ensure_same_node(cmd, keys) do |node| node.send(cmd, script, keys, argv) end end
# File lib/redis/distributed.rb, line 40 def add_node(options) options = { url: options } if options.is_a?(String) options = @default_options.merge(options) @ring.add_node Redis.new(options) end
Append a value to a key.
# File lib/redis/distributed.rb, line 351 def append(key, value) node_for(key).append(key, value) end
Asynchronously save the dataset to disk.
# File lib/redis/distributed.rb, line 67 def bgsave on_each_node :bgsave end
Count the number of set bits in a range of the string value stored at key.
# File lib/redis/distributed.rb, line 356 def bitcount(key, start = 0, stop = -1) node_for(key).bitcount(key, start, stop) end
Perform a bitwise operation between strings and store the resulting string in a key.
# File lib/redis/distributed.rb, line 361 def bitop(operation, destkey, *keys) ensure_same_node(:bitop, [destkey] + keys) do |node| node.bitop(operation, destkey, *keys) end end
Return the position of the first bit set to 1 or 0 in a string.
# File lib/redis/distributed.rb, line 368 def bitpos(key, bit, start = nil, stop = nil) node_for(key).bitpos(key, bit, start, stop) end
Remove and get the first element in a list, or block until one is available.
# File lib/redis/distributed.rb, line 459 def blpop(*args) _bpop(:blpop, args) end
Remove and get the last element in a list, or block until one is available.
# File lib/redis/distributed.rb, line 465 def brpop(*args) _bpop(:brpop, args) end
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 471 def brpoplpush(source, destination, deprecated_timeout = 0, **options) ensure_same_node(:brpoplpush, [source, destination]) do |node| node.brpoplpush(source, destination, deprecated_timeout, **options) end end
Return the number of keys in the selected database.
# File lib/redis/distributed.rb, line 72 def dbsize on_each_node :dbsize end
Decrement the integer value of a key by one.
# File lib/redis/distributed.rb, line 251 def decr(key) node_for(key).decr(key) end
Decrement the integer value of a key by the given number.
# File lib/redis/distributed.rb, line 256 def decrby(key, decrement) node_for(key).decrby(key, decrement) end
Delete a key.
# File lib/redis/distributed.rb, line 162 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 all commands issued after MULTI.
# File lib/redis/distributed.rb, line 850 def discard raise CannotDistribute, :discard unless @watch_key result = node_for(@watch_key).discard @watch_key = nil result end
Return a serialized version of the value stored at a key.
# File lib/redis/distributed.rb, line 147 def dump(key) node_for(key).dump(key) end
# File lib/redis/distributed.rb, line 910 def dup self.class.new(@node_configs, @default_options) end
Echo the given string.
# File lib/redis/distributed.rb, line 57 def echo(value) on_each_node :echo, value end
Evaluate Lua script.
# File lib/redis/distributed.rb, line 897 def eval(*args) _eval(:eval, args) end
Evaluate Lua script by its SHA.
# File lib/redis/distributed.rb, line 902 def evalsha(*args) _eval(:evalsha, args) end
Execute all commands issued after MULTI.
# File lib/redis/distributed.rb, line 841 def exec raise CannotDistribute, :exec unless @watch_key result = node_for(@watch_key).exec @watch_key = nil result end
Determine if a key exists.
# File lib/redis/distributed.rb, line 178 def exists(*args) if !Redis.exists_returns_integer && args.size == 1 message = "`Redis#exists(key)` will return an Integer in redis-rb 4.3, if you want to keep the old behavior, " \ "use `exists?` instead. To opt-in to the new behavior now you can set Redis.exists_returns_integer = true. " \ "(#{::Kernel.caller(1, 1).first})\n" if defined?(::Warning) ::Warning.warn(message) else warn(message) end exists?(*args) else keys_per_node = args.group_by { |key| node_for(key) } keys_per_node.inject(0) do |sum, (node, keys)| sum + node._exists(*keys) end end end
Determine if any of the keys exists.
# File lib/redis/distributed.rb, line 199 def exists?(*args) keys_per_node = args.group_by { |key| node_for(key) } keys_per_node.each do |node, keys| return true if node.exists?(*keys) end false end
Set a key's time to live in seconds.
# File lib/redis/distributed.rb, line 117 def expire(key, seconds) node_for(key).expire(key, seconds) end
Set the expiration for a key as a UNIX timestamp.
# File lib/redis/distributed.rb, line 122 def expireat(key, unix_time) node_for(key).expireat(key, unix_time) end
Remove all keys from all databases.
# File lib/redis/distributed.rb, line 77 def flushall on_each_node :flushall end
Remove all keys from the current database.
# File lib/redis/distributed.rb, line 82 def flushdb on_each_node :flushdb end
Get the value of a key.
# File lib/redis/distributed.rb, line 314 def get(key) node_for(key).get(key) end
Returns the bit value at offset in the string value stored at key.
# File lib/redis/distributed.rb, line 346 def getbit(key, offset) node_for(key).getbit(key, offset) end
Get a substring of the string stored at a key.
# File lib/redis/distributed.rb, line 336 def getrange(key, start, stop) node_for(key).getrange(key, start, stop) end
Set the string value of a key and return its old value.
# File lib/redis/distributed.rb, line 373 def getset(key, value) node_for(key).getset(key, value) end
Delete one or more hash fields.
# File lib/redis/distributed.rb, line 730 def hdel(key, *fields) node_for(key).hdel(key, *fields) end
Determine if a hash field exists.
# File lib/redis/distributed.rb, line 735 def hexists(key, field) node_for(key).hexists(key, field) end
Get the value of a hash field.
# File lib/redis/distributed.rb, line 716 def hget(key, field) node_for(key).hget(key, field) end
Get all the fields and values in a hash.
# File lib/redis/distributed.rb, line 760 def hgetall(key) node_for(key).hgetall(key) end
Increment the integer value of a hash field by the given integer number.
# File lib/redis/distributed.rb, line 740 def hincrby(key, field, increment) node_for(key).hincrby(key, field, increment) end
Increment the numeric value of a hash field by the given float number.
# File lib/redis/distributed.rb, line 745 def hincrbyfloat(key, field, increment) node_for(key).hincrbyfloat(key, field, increment) end
Get all the fields in a hash.
# File lib/redis/distributed.rb, line 750 def hkeys(key) node_for(key).hkeys(key) end
Get the number of fields in a hash.
# File lib/redis/distributed.rb, line 692 def hlen(key) node_for(key).hlen(key) end
Get the values of all the given hash fields.
# File lib/redis/distributed.rb, line 721 def hmget(key, *fields) node_for(key).hmget(key, *fields) end
Set multiple hash fields to multiple values.
# File lib/redis/distributed.rb, line 707 def hmset(key, *attrs) node_for(key).hmset(key, *attrs) end
Set multiple hash fields to multiple values.
# File lib/redis/distributed.rb, line 697 def hset(key, *attrs) node_for(key).hset(key, *attrs) end
Set the value of a hash field, only if the field does not exist.
# File lib/redis/distributed.rb, line 702 def hsetnx(key, field, value) node_for(key).hsetnx(key, field, value) end
Get all the values in a hash.
# File lib/redis/distributed.rb, line 755 def hvals(key) node_for(key).hvals(key) end
Increment the integer value of a key by one.
# File lib/redis/distributed.rb, line 261 def incr(key) node_for(key).incr(key) end
Increment the integer value of a key by the given integer number.
# File lib/redis/distributed.rb, line 266 def incrby(key, increment) node_for(key).incrby(key, increment) end
Increment the numeric value of a key by the given float number.
# File lib/redis/distributed.rb, line 271 def incrbyfloat(key, increment) node_for(key).incrbyfloat(key, increment) end
Get information and statistics about the server.
# File lib/redis/distributed.rb, line 87 def info(cmd = nil) on_each_node :info, cmd end
# File lib/redis/distributed.rb, line 906 def inspect "#<Redis client v#{Redis::VERSION} for #{nodes.map(&:id).join(', ')}>" end
Find all keys matching the given pattern.
# File lib/redis/distributed.rb, line 208 def keys(glob = "*") on_each_node(:keys, glob).flatten end
Get the UNIX time stamp of the last successful save to disk.
# File lib/redis/distributed.rb, line 92 def lastsave on_each_node :lastsave end
Get an element from a list by its index.
# File lib/redis/distributed.rb, line 478 def lindex(key, index) node_for(key).lindex(key, index) end
Insert an element before or after another element in a list.
# File lib/redis/distributed.rb, line 483 def linsert(key, where, pivot, value) node_for(key).linsert(key, where, pivot, value) end
Get the length of a list.
# File lib/redis/distributed.rb, line 391 def llen(key) node_for(key).llen(key) end
Remove and get the first element in a list.
# File lib/redis/distributed.rb, line 416 def lpop(key) node_for(key).lpop(key) end
Prepend one or more values to a list.
# File lib/redis/distributed.rb, line 396 def lpush(key, value) node_for(key).lpush(key, value) end
Prepend a value to a list, only if the list exists.
# File lib/redis/distributed.rb, line 401 def lpushx(key, value) node_for(key).lpushx(key, value) end
Get a range of elements from a list.
# File lib/redis/distributed.rb, line 488 def lrange(key, start, stop) node_for(key).lrange(key, start, stop) end
Remove elements from a list.
# File lib/redis/distributed.rb, line 493 def lrem(key, count, value) node_for(key).lrem(key, count, value) end
Set the value of an element in a list by its index.
# File lib/redis/distributed.rb, line 498 def lset(key, index, value) node_for(key).lset(key, index, value) end
Trim a list to the specified range.
# File lib/redis/distributed.rb, line 503 def ltrim(key, start, stop) node_for(key).ltrim(key, start, stop) end
# File lib/redis/distributed.rb, line 725 def mapped_hmget(key, *fields) Hash[*fields.zip(hmget(key, *fields)).flatten] end
# File lib/redis/distributed.rb, line 711 def mapped_hmset(key, hash) node_for(key).hmset(key, *hash.to_a.flatten) end
Get the values of all the given keys as a Hash.
# File lib/redis/distributed.rb, line 324 def mapped_mget(*keys) keys.group_by { |k| node_for k }.inject({}) do |results, (node, subkeys)| results.merge! node.mapped_mget(*subkeys) end end
# File lib/redis/distributed.rb, line 300 def mapped_mset(_hash) raise CannotDistribute, :mapped_mset end
# File lib/redis/distributed.rb, line 309 def mapped_msetnx(_hash) raise CannotDistribute, :mapped_msetnx end
Get the values of all the given keys as an Array.
# File lib/redis/distributed.rb, line 319 def mget(*keys) mapped_mget(*keys).values_at(*keys) end
Transfer a key from the connected instance to another instance.
# File lib/redis/distributed.rb, line 157 def migrate(_key, _options) raise CannotDistribute, :migrate end
Listen for all requests received by the server in real time.
# File lib/redis/distributed.rb, line 97 def monitor raise NotImplementedError end
Move a key to another database.
# File lib/redis/distributed.rb, line 213 def move(key, db) node_for(key).move(key, db) end
Set multiple keys to multiple values.
# File lib/redis/distributed.rb, line 296 def mset(*_args) raise CannotDistribute, :mset end
Set multiple keys to multiple values, only if none of the keys exist.
# File lib/redis/distributed.rb, line 305 def msetnx(*_args) raise CannotDistribute, :msetnx end
Mark the start of a transaction block.
# File lib/redis/distributed.rb, line 832 def multi(&block) raise CannotDistribute, :multi unless @watch_key result = node_for(@watch_key).multi(&block) @watch_key = nil if block_given? result end
# File lib/redis/distributed.rb, line 29 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
# File lib/redis/distributed.rb, line 36 def nodes @ring.nodes end
Remove the expiration from a key.
# File lib/redis/distributed.rb, line 112 def persist(key) node_for(key).persist(key) end
Set a key's time to live in milliseconds.
# File lib/redis/distributed.rb, line 132 def pexpire(key, milliseconds) node_for(key).pexpire(key, milliseconds) end
Set the expiration for a key as number of milliseconds from UNIX Epoch.
# File lib/redis/distributed.rb, line 137 def pexpireat(key, ms_unix_time) node_for(key).pexpireat(key, ms_unix_time) end
Add one or more members to a HyperLogLog structure.
# File lib/redis/distributed.rb, line 864 def pfadd(key, member) node_for(key).pfadd(key, member) end
Get the approximate cardinality of members added to HyperLogLog structure.
# File lib/redis/distributed.rb, line 869 def pfcount(*keys) ensure_same_node(:pfcount, keys.flatten(1)) do |node| node.pfcount(keys) end end
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 877 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 the server.
# File lib/redis/distributed.rb, line 52 def ping on_each_node :ping end
# File lib/redis/distributed.rb, line 827 def pipelined raise CannotDistribute, :pipelined end
Set the time to live in milliseconds of a key.
# File lib/redis/distributed.rb, line 286 def psetex(key, ttl, value) node_for(key).psetex(key, ttl, value) end
Listen for messages published to channels matching the given patterns.
# File lib/redis/distributed.rb, line 794 def psubscribe(*channels, &block) raise NotImplementedError end
Get the time to live (in milliseconds) for a key.
# File lib/redis/distributed.rb, line 142 def pttl(key) node_for(key).pttl(key) end
Post a message to a channel.
# File lib/redis/distributed.rb, line 765 def publish(channel, message) node_for(channel).publish(channel, message) end
Stop listening for messages posted to channels matching the given patterns.
# File lib/redis/distributed.rb, line 800 def punsubscribe(*channels) raise NotImplementedError end
Close the connection.
# File lib/redis/distributed.rb, line 62 def quit on_each_node :quit end
Return a random key from the keyspace.
# File lib/redis/distributed.rb, line 218 def randomkey raise CannotDistribute, :randomkey end
Rename a key.
# File lib/redis/distributed.rb, line 223 def rename(old_name, new_name) ensure_same_node(:rename, [old_name, new_name]) do |node| node.rename(old_name, new_name) end end
Rename a key, only if the new key does not exist.
# File lib/redis/distributed.rb, line 230 def renamenx(old_name, new_name) ensure_same_node(:renamenx, [old_name, new_name]) do |node| node.renamenx(old_name, new_name) end end
Create a key using the serialized value, previously obtained using DUMP.
# File lib/redis/distributed.rb, line 152 def restore(key, ttl, serialized_value, **options) node_for(key).restore(key, ttl, serialized_value, **options) end
Remove and get the last element in a list.
# File lib/redis/distributed.rb, line 421 def rpop(key) node_for(key).rpop(key) end
Remove the last element in a list, append it to another list and return it.
# File lib/redis/distributed.rb, line 427 def rpoplpush(source, destination) ensure_same_node(:rpoplpush, [source, destination]) do |node| node.rpoplpush(source, destination) end end
Append one or more values to a list.
# File lib/redis/distributed.rb, line 406 def rpush(key, value) node_for(key).rpush(key, value) end
Append a value to a list, only if the list exists.
# File lib/redis/distributed.rb, line 411 def rpushx(key, value) node_for(key).rpushx(key, value) end
Add one or more members to a set.
# File lib/redis/distributed.rb, line 513 def sadd(key, member) node_for(key).sadd(key, member) end
Synchronously save the dataset to disk.
# File lib/redis/distributed.rb, line 102 def save on_each_node :save end
Get the number of members in a set.
# File lib/redis/distributed.rb, line 508 def scard(key) node_for(key).scard(key) end
Control remote script registry.
# File lib/redis/distributed.rb, line 859 def script(subcommand, *args) on_each_node(:script, subcommand, *args) end
Subtract multiple sets.
# File lib/redis/distributed.rb, line 560 def sdiff(*keys) ensure_same_node(:sdiff, keys) do |node| node.sdiff(*keys) end end
Subtract multiple sets and store the resulting set in a key.
# File lib/redis/distributed.rb, line 567 def sdiffstore(destination, *keys) ensure_same_node(:sdiffstore, [destination] + keys) do |node| node.sdiffstore(destination, *keys) end end
Change the selected database for the current connection.
# File lib/redis/distributed.rb, line 47 def select(db) on_each_node :select, db end
Set the string value of a key.
# File lib/redis/distributed.rb, line 276 def set(key, value, **options) node_for(key).set(key, value, **options) end
Sets or clears the bit at offset in the string value stored at key.
# File lib/redis/distributed.rb, line 341 def setbit(key, offset, value) node_for(key).setbit(key, offset, value) end
Set the time to live in seconds of a key.
# File lib/redis/distributed.rb, line 281 def setex(key, ttl, value) node_for(key).setex(key, ttl, value) end
Set the value of a key, only if the key does not exist.
# File lib/redis/distributed.rb, line 291 def setnx(key, value) node_for(key).setnx(key, value) end
Overwrite part of a string at key starting at the specified offset.
# File lib/redis/distributed.rb, line 331 def setrange(key, offset, value) node_for(key).setrange(key, offset, value) end
Intersect multiple sets.
# File lib/redis/distributed.rb, line 574 def sinter(*keys) ensure_same_node(:sinter, keys) do |node| node.sinter(*keys) end end
Intersect multiple sets and store the resulting set in a key.
# File lib/redis/distributed.rb, line 581 def sinterstore(destination, *keys) ensure_same_node(:sinterstore, [destination] + keys) do |node| node.sinterstore(destination, *keys) end end
Determine if a given value is a member of a set.
# File lib/redis/distributed.rb, line 540 def sismember(key, member) node_for(key).sismember(key, member) end
Get all the members in a set.
# File lib/redis/distributed.rb, line 545 def smembers(key) node_for(key).smembers(key) end
Move a member from one set to another.
# File lib/redis/distributed.rb, line 533 def smove(source, destination, member) ensure_same_node(:smove, [source, destination]) do |node| node.smove(source, destination, member) end end
Sort the elements in a list, set or sorted set.
# File lib/redis/distributed.rb, line 237 def sort(key, **options) keys = [key, options[:by], options[:store], *Array(options[:get])].compact ensure_same_node(:sort, keys) do |node| node.sort(key, **options) end end
Remove and return a random member from a set.
# File lib/redis/distributed.rb, line 523 def spop(key, count = nil) node_for(key).spop(key, count) end
Get a random member from a set.
# File lib/redis/distributed.rb, line 528 def srandmember(key, count = nil) node_for(key).srandmember(key, count) end
Remove one or more members from a set.
# File lib/redis/distributed.rb, line 518 def srem(key, member) node_for(key).srem(key, member) end
Scan a set
# File lib/redis/distributed.rb, line 550 def sscan(key, cursor, **options) node_for(key).sscan(key, cursor, **options) end
Scan a set and return an enumerator
# File lib/redis/distributed.rb, line 555 def sscan_each(key, **options, &block) node_for(key).sscan_each(key, **options, &block) end
Get the length of the value stored in a key.
# File lib/redis/distributed.rb, line 378 def strlen(key) node_for(key).strlen(key) end
Listen for messages published to the given channels.
# File lib/redis/distributed.rb, line 774 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
# File lib/redis/distributed.rb, line 769 def subscribed? !!@subscribed_node end
Add multiple sets.
# File lib/redis/distributed.rb, line 588 def sunion(*keys) ensure_same_node(:sunion, keys) do |node| node.sunion(*keys) end end
Add multiple sets and store the resulting set in a key.
# File lib/redis/distributed.rb, line 595 def sunionstore(destination, *keys) ensure_same_node(:sunionstore, [destination] + keys) do |node| node.sunionstore(destination, *keys) end end
Get server time: an UNIX timestamp and the elapsed microseconds in the current second.
# File lib/redis/distributed.rb, line 107 def time on_each_node :time end
Get the time to live (in seconds) for a key.
# File lib/redis/distributed.rb, line 127 def ttl(key) node_for(key).ttl(key) end
Determine the type stored at key.
# File lib/redis/distributed.rb, line 246 def type(key) node_for(key).type(key) end
Unlink keys.
# File lib/redis/distributed.rb, line 170 def unlink(*args) keys_per_node = args.group_by { |key| node_for(key) } keys_per_node.inject(0) do |sum, (node, keys)| sum + node.unlink(*keys) end end
Stop listening for messages posted to the given channels.
# File lib/redis/distributed.rb, line 787 def unsubscribe(*channels) raise "Can't unsubscribe if not subscribed." unless subscribed? @subscribed_node.unsubscribe(*channels) end
Forget about all watched keys.
# File lib/redis/distributed.rb, line 819 def unwatch raise CannotDistribute, :unwatch unless @watch_key result = node_for(@watch_key).unwatch @watch_key = nil result end
Watch the given keys to determine execution of the MULTI/EXEC block.
# File lib/redis/distributed.rb, line 805 def watch(*keys, &block) ensure_same_node(:watch, keys) do |node| @watch_key = key_tag(keys.first) || keys.first.to_s begin node.watch(*keys, &block) rescue StandardError @watch_key = nil raise end end end
Add one or more members to a sorted set, or update the score for members that already exist.
# File lib/redis/distributed.rb, line 608 def zadd(key, *args) node_for(key).zadd(key, *args) end
Get the number of members in a sorted set.
# File lib/redis/distributed.rb, line 602 def zcard(key) node_for(key).zcard(key) end
Get the number of members in a particular score range.
# File lib/redis/distributed.rb, line 672 def zcount(key, min, max) node_for(key).zcount(key, min, max) end
Increment the score of a member in a sorted set.
# File lib/redis/distributed.rb, line 614 def zincrby(key, increment, member) node_for(key).zincrby(key, increment, member) end
Intersect multiple sorted sets and store the resulting sorted set in a new key.
# File lib/redis/distributed.rb, line 678 def zinterstore(destination, keys, **options) ensure_same_node(:zinterstore, [destination] + keys) do |node| node.zinterstore(destination, keys, **options) end end
Return a range of members in a sorted set, by index.
# File lib/redis/distributed.rb, line 629 def zrange(key, start, stop, **options) node_for(key).zrange(key, start, stop, **options) end
Return a range of members in a sorted set, by score.
# File lib/redis/distributed.rb, line 656 def zrangebyscore(key, min, max, **options) node_for(key).zrangebyscore(key, min, max, **options) end
Determine the index of a member in a sorted set.
# File lib/redis/distributed.rb, line 640 def zrank(key, member) node_for(key).zrank(key, member) end
Remove one or more members from a sorted set.
# File lib/redis/distributed.rb, line 619 def zrem(key, member) node_for(key).zrem(key, member) end
Remove all members in a sorted set within the given indexes.
# File lib/redis/distributed.rb, line 651 def zremrangebyrank(key, start, stop) node_for(key).zremrangebyrank(key, start, stop) end
Remove all members in a sorted set within the given scores.
# File lib/redis/distributed.rb, line 667 def zremrangebyscore(key, min, max) node_for(key).zremrangebyscore(key, min, max) end
Return a range of members in a sorted set, by index, with scores ordered from high to low.
# File lib/redis/distributed.rb, line 635 def zrevrange(key, start, stop, **options) node_for(key).zrevrange(key, start, stop, **options) end
Return a range of members in a sorted set, by score, with scores ordered from high to low.
# File lib/redis/distributed.rb, line 662 def zrevrangebyscore(key, max, min, **options) node_for(key).zrevrangebyscore(key, max, min, **options) end
Determine the index of a member in a sorted set, with scores ordered from high to low.
# File lib/redis/distributed.rb, line 646 def zrevrank(key, member) node_for(key).zrevrank(key, member) end
Get the score associated with the given member in a sorted set.
# File lib/redis/distributed.rb, line 624 def zscore(key, member) node_for(key).zscore(key, member) end
Add multiple sorted sets and store the resulting sorted set in a new key.
# File lib/redis/distributed.rb, line 685 def zunionstore(destination, keys, **options) ensure_same_node(:zunionstore, [destination] + keys) do |node| node.zunionstore(destination, keys, **options) end end
Protected Instance Methods
# File lib/redis/distributed.rb, line 930 def ensure_same_node(command, keys) all = true tags = keys.map do |key| tag = key_tag(key) all = false unless tag tag end if (all && tags.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
# File lib/redis/distributed.rb, line 926 def key_tag(key) key.to_s[@tag, 1] if @tag end
# File lib/redis/distributed.rb, line 922 def node_index_for(key) nodes.index(node_for(key)) end
# File lib/redis/distributed.rb, line 916 def on_each_node(command, *args) nodes.map do |node| node.send(command, *args) end end