Module: Redis::Commands
Constant Summary
-
Boolify =
# File 'lib/redis/commands.rb', line 42
Commandsreturning 1 for true and 0 for false may be executed in a pipeline where the method call will return nil. Propagate the nil instead of falsely returning false.lambda { |value| value != 0 unless value.nil? }
-
BoolifySet =
# File 'lib/redis/commands.rb', line 46lambda { |value| case value when "OK" true when nil false else value end }
-
EMPTY_STREAM_RESPONSE =
private
# File 'lib/redis/commands.rb', line 112[nil].freeze
-
Floatify =
# File 'lib/redis/commands.rb', line 73lambda { |value| case value when "inf" Float::INFINITY when "-inf" -Float::INFINITY when String Float(value) else value end }
-
FloatifyPair =
# File 'lib/redis/commands.rb', line 86lambda { |(first, score)| [first, Floatify.call(score)] }
-
FloatifyPairs =
# File 'lib/redis/commands.rb', line 90lambda { |value| return value unless value.respond_to?(:each_slice) value.each_slice(2).map(&FloatifyPair) }
-
Hashify =
# File 'lib/redis/commands.rb', line 57lambda { |value| if value.respond_to?(:each_slice) value.each_slice(2).to_h else value end }
-
HashifyClusterNodeInfo =
# File 'lib/redis/commands.rb', line 157lambda { |str| arr = str.split(' ') { 'node_id' => arr[0], 'ip_port' => arr[1], 'flags' => arr[2].split(','), 'master_node_id' => arr[3], 'ping_sent' => arr[4], 'pong_recv' => arr[5], 'config_epoch' => arr[6], 'link_state' => arr[7], 'slots' => arr[8].nil? ? nil : Range.new(*arr[8].split('-')) } }
-
HashifyClusterNodes =
# File 'lib/redis/commands.rb', line 186lambda { |reply| reply.split(/[\r\n]+/).map { |str| HashifyClusterNodeInfo.call(str) } }
-
HashifyClusterSlaves =
# File 'lib/redis/commands.rb', line 190lambda { |reply| reply.map { |str| HashifyClusterNodeInfo.call(str) } }
-
HashifyClusterSlots =
# File 'lib/redis/commands.rb', line 172lambda { |reply| reply.map do |arr| first_slot, last_slot = arr[0..1] master = { 'ip' => arr[2][0], 'port' => arr[2][1], 'node_id' => arr[2][2] } replicas = arr[3..-1].map { |r| { 'ip' => r[0], 'port' => r[1], 'node_id' => r[2] } } { 'start_slot' => first_slot, 'end_slot' => last_slot, 'master' => master, 'replicas' => replicas } end }
-
HashifyInfo =
# File 'lib/redis/commands.rb', line 96lambda { |reply| lines = reply.split("\r\n").grep_v(/^(#|$)/) lines.map! { |line| line.split(':', 2) } lines.compact! lines.to_h }
-
HashifyStreamAutoclaim =
# File 'lib/redis/commands.rb', line 121lambda { |reply| { 'next' => reply[0], 'entries' => reply[1].compact.map do |entry, values| [entry, values.each_slice(2)&.to_h] end } }
-
HashifyStreamAutoclaimJustId =
# File 'lib/redis/commands.rb', line 130lambda { |reply| { 'next' => reply[0], 'entries' => reply[1] } }
-
HashifyStreamEntries =
# File 'lib/redis/commands.rb', line 115lambda { |reply| reply.compact.map do |entry_id, values| [entry_id, values&.each_slice(2)&.to_h] end }
-
HashifyStreamPendingDetails =
# File 'lib/redis/commands.rb', line 146lambda { |reply| reply.map do |arr| { 'entry_id' => arr[0], 'consumer' => arr[1], 'elapsed' => arr[2], 'count' => arr[3] } end }
-
HashifyStreamPendings =
# File 'lib/redis/commands.rb', line 137lambda { |reply| { 'size' => reply[0], 'min_entry_id' => reply[1], 'max_entry_id' => reply[2], 'consumers' => reply[3].nil? ? {} : reply[3].to_h } }
-
HashifyStreams =
# File 'lib/redis/commands.rb', line 103lambda { |reply| case reply when nil {} else reply.map { |key, entries| [key, HashifyStreamEntries.call(entries)] }.to_h end }
-
Noop =
# File 'lib/redis/commands.rb', line 194->(reply) { reply }
-
Pairify =
# File 'lib/redis/commands.rb', line 65lambda { |value| if value.respond_to?(:each_slice) value.each_slice(2).to_a else value end }
Instance Attribute Summary
Pubsub - Included
Instance Method Summary
-
#call(*command, &block)
Sends a command to
::Redisand returns its reply. -
#sentinel(subcommand, *args) ⇒ Array<String>, ...
Interact with the sentinel command (masters, master, slaves, failover).
- #method_missing(*command) private
Transactions - Included
| #discard | Discard all commands issued after MULTI. |
| #exec | Execute all commands issued after MULTI. |
| #multi | Mark the start of a transaction block. |
| #unwatch | Forget about all watched keys. |
| #watch | Watch the given keys to determine execution of the MULTI/EXEC block. |
Strings - Included
| #append | Append a value to a key. |
| #decr | Decrement the integer value of a key by one. |
| #decrby | Decrement the integer value of a key by the given number. |
| #get | Get the value of a key. |
| #getdel | Get the value of key and delete the key. |
| #getex | Get the value of key and optionally set its expiration. |
| #getrange | Get a substring of the string stored at a key. |
| #getset | Set the string value of a key and return its old value. |
| #incr | Increment the integer value of a key by one. |
| #incrby | Increment the integer value of a key by the given integer number. |
| #incrbyfloat | Increment the numeric value of a key by the given float number. |
| #mapped_mget | Get the values of all the given keys. |
| #mapped_mset | Set one or more values. |
| #mapped_msetnx | Set one or more values, only if none of the keys exist. |
| #mget | Get the values of all the given keys. |
| #mset | Set one or more values. |
| #msetnx | Set one or more values, only if none of the keys exist. |
| #psetex | Set the time to live in milliseconds of a key. |
| #set | Set the string value of a key. |
| #setex | Set the time to live in seconds of a key. |
| #setnx | Set the value of a key, only if the key does not exist. |
| #setrange | Overwrite part of a string at key starting at the specified offset. |
| #strlen | Get the length of the value stored in a key. |
Streams - Included
| #xack | Removes one or multiple entries from the pending entries list of a stream consumer group. |
| #xadd | Add new entry to the stream. |
| #xautoclaim | Transfers ownership of pending stream entries that match the specified criteria. |
| #xclaim | Changes the ownership of a pending entry. |
| #xdel | Delete entries by entry ids. |
| #xgroup | Manages the consumer group of the stream. |
| #xinfo | Returns the stream information each subcommand. |
| #xlen | Returns the number of entries inside a stream. |
| #xpending | Fetches not acknowledging pending entries. |
| #xrange | Fetches entries of the stream in ascending order. |
| #xread | Fetches entries from one or multiple streams. |
| #xreadgroup | Fetches a subset of the entries from one or multiple streams related with the consumer group. |
| #xrevrange | Fetches entries of the stream in descending order. |
| #xtrim | Trims older entries of the stream if needed. |
| #_xread | |
SortedSets - Included
| #bzmpop | Removes and returns up to count members with scores in the sorted set stored at key. |
| #bzpopmax | Removes and returns up to count members with the highest scores in the sorted set stored at keys,. |
| #bzpopmin | Removes and returns up to count members with the lowest scores in the sorted set stored at keys,. |
| #zadd | Add one or more members to a sorted set, or update the score for members that already exist. |
| #zcard | Get the number of members in a sorted set. |
| #zcount | Count the members in a sorted set with scores within the given values. |
| #zdiff | Return the difference between the first and all successive input sorted sets. |
| #zdiffstore | Compute the difference between the first and all successive input sorted sets and store the resulting sorted set in a new key. |
| #zincrby | Increment the score of a member in a sorted set. |
| #zinter | Return the intersection of multiple sorted sets. |
| #zinterstore | Intersect multiple sorted sets and store the resulting sorted set in a new key. |
| #zlexcount | Count the members, with the same score in a sorted set, within the given lexicographical range. |
| #zmpop | Removes and returns up to count members with scores in the sorted set stored at key. |
| #zmscore | Get the scores associated with the given members in a sorted set. |
| #zpopmax | Removes and returns up to count members with the highest scores in the sorted set stored at key. |
| #zpopmin | Removes and returns up to count members with the lowest scores in the sorted set stored at key. |
| #zrandmember | Get one or more random members from a sorted set. |
| #zrange | Return a range of members in a sorted set, by index, score or lexicographical ordering. |
| #zrangebylex | Return a range of members with the same score in a sorted set, by lexicographical ordering. |
| #zrangebyscore | Return a range of members in a sorted set, by score. |
| #zrangestore | 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 | Determine the index of a member in a sorted set. |
| #zrem | Remove one or more members from a sorted set. |
| #zremrangebyrank | Remove all members in a sorted set within the given indexes. |
| #zremrangebyscore | Remove all members in a sorted set within the given scores. |
| #zrevrange | Return a range of members in a sorted set, by index, with scores ordered from high to low. |
| #zrevrangebylex | Return a range of members with the same score in a sorted set, by reversed lexicographical ordering. |
| #zrevrangebyscore | Return a range of members in a sorted set, by score, with scores ordered from high to low. |
| #zrevrank | Determine the index of a member in a sorted set, with scores ordered from high to low. |
| #zscan | Scan a sorted set. |
| #zscan_each | Scan a sorted set. |
| #zscore | Get the score associated with the given member in a sorted set. |
| #zunion | Return the union of multiple sorted sets. |
| #zunionstore | Add multiple sorted sets and store the resulting sorted set in a new key. |
| #_zsets_operation, #_zsets_operation_store | |
Sets - Included
| #sadd | Add one or more members to a set. |
| #sadd? | Add one or more members to a set. |
| #scard | Get the number of members in a set. |
| #sdiff | Subtract multiple sets. |
| #sdiffstore | Subtract multiple sets and store the resulting set in a key. |
| #sinter | Intersect multiple sets. |
| #sinterstore | Intersect multiple sets and store the resulting set in a key. |
| #sismember | Determine if a given value is a member of a set. |
| #smembers | Get all the members in a set. |
| #smismember | Determine if multiple values are members of a set. |
| #smove | Move a member from one set to another. |
| #spop | Remove and return one or more random member from a set. |
| #srandmember | Get one or more random members from a set. |
| #srem | Remove one or more members from a set. |
| #srem? | Remove one or more members from a set. |
| #sscan | Scan a set. |
| #sscan_each | Scan a set. |
| #sunion | Add multiple sets. |
| #sunionstore | Add multiple sets and store the resulting set in a key. |
Server - Included
| #bgrewriteaof | Asynchronously rewrite the append-only file. |
| #bgsave | Asynchronously save the dataset to disk. |
| #client | Manage client connections. |
| #config | Get or set server configuration parameters. |
| #dbsize | Return the number of keys in the selected database. |
| #debug, | |
| #flushall | Remove all keys from all databases. |
| #flushdb | Remove all keys from the current database. |
| #info | Get information and statistics about the server. |
| #lastsave | Get the UNIX time stamp of the last successful save to disk. |
| #monitor | Listen for all requests received by the server in real time. |
| #save | Synchronously save the dataset to disk. |
| #shutdown | Synchronously save the dataset to disk and then shut down the server. |
| #slaveof | Make the server a slave of another instance, or promote it as master. |
| #slowlog | Interact with the slowlog (get, len, reset). |
| #sync | Internal command used for replication. |
| #time | Return the server time. |
Scripting - Included
| #eval | Evaluate Lua script. |
| #evalsha | Evaluate Lua script by its SHA. |
| #script | Control remote script registry. |
| #_eval | |
Pubsub - Included
| #psubscribe | Listen for messages published to channels matching the given patterns. |
| #psubscribe_with_timeout | Listen for messages published to channels matching the given patterns. |
| #publish | Post a message to a channel. |
| #pubsub | Inspect the state of the Pub/Sub subsystem. |
| #punsubscribe | Stop listening for messages posted to channels matching the given patterns. |
| #spublish | Post a message to a channel in a shard. |
| #ssubscribe | Listen for messages published to the given channels in a shard. |
| #ssubscribe_with_timeout | Listen for messages published to the given channels in a shard. |
| #subscribe | Listen for messages published to the given channels. |
| #subscribe_with_timeout | Listen for messages published to the given channels. |
| #sunsubscribe | Stop listening for messages posted to the given channels in a shard. |
| #unsubscribe | Stop listening for messages posted to the given channels. |
Lists - Included
| #blmove | 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 | Pops one or more elements from the first non-empty list key from the list of provided key names. |
| #blpop | Remove and get the first element in a list, or block until one is available. |
| #brpop | Remove and get the last element in a list, or block until one is available. |
| #brpoplpush | Pop a value from a list, push it to another list and return it; or block until one is available. |
| #lindex | Get an element from a list by its index. |
| #linsert | Insert an element before or after another element in a list. |
| #llen | Get the length of a list. |
| #lmove | Remove the first/last element in a list, append/prepend it to another list and return it. |
| #lmpop | Pops one or more elements from the first non-empty list key from the list of provided key names. |
| #lpop | Remove and get the first elements in a list. |
| #lpush | Prepend one or more values to a list, creating the list if it doesn't exist. |
| #lpushx | Prepend a value to a list, only if the list exists. |
| #lrange | Get a range of elements from a list. |
| #lrem | Remove elements from a list. |
| #lset | Set the value of an element in a list by its index. |
| #ltrim | Trim a list to the specified range. |
| #rpop | Remove and get the last elements in a list. |
| #rpoplpush | Remove the last element in a list, append it to another list and return it. |
| #rpush | Append one or more values to a list, creating the list if it doesn't exist. |
| #rpushx | Append a value to a list, only if the list exists. |
| #_bpop, #_normalize_move_wheres | |
Keys - Included
| #copy | Copy a value from one key to another. |
| #del | Delete one or more keys. |
| #dump | Return a serialized version of the value stored at a key. |
| #exists | Determine how many of the keys exists. |
| #exists? | Determine if any of the keys exists. |
| #expire | Set a key's time to live in seconds. |
| #expireat | Set the expiration for a key as a UNIX timestamp. |
| #expiretime | Get a key's expiry time specified as number of seconds from UNIX Epoch. |
| #keys | Find all keys matching the given pattern. |
| #migrate | Transfer a key from the connected instance to another instance. |
| #move | Move a key to another database. |
| #object, | |
| #persist | Remove the expiration from a key. |
| #pexpire | Set a key's time to live in milliseconds. |
| #pexpireat | Set the expiration for a key as number of milliseconds from UNIX Epoch. |
| #pexpiretime | Get a key's expiry time specified as number of milliseconds from UNIX Epoch. |
| #pttl | Get the time to live (in milliseconds) for a key. |
| #randomkey | Return a random key from the keyspace. |
| #rename | Rename a key. |
| #renamenx | Rename a key, only if the new key does not exist. |
| #restore | Create a key using the serialized value, previously obtained using DUMP. |
| #scan | Scan the keyspace. |
| #scan_each | Scan the keyspace. |
| #sort | Sort the elements in a list, set or sorted set. |
| #ttl | Get the time to live (in seconds) for a key. |
| #type | Determine the type stored at key. |
| #unlink | Unlink one or more keys. |
| #_scan | |
HyperLogLog - Included
| #pfadd | Add one or more members to a |
| #pfcount | Get the approximate cardinality of members added to |
| #pfmerge | Merge multiple |
Hashes - Included
| #hdel | Delete one or more hash fields. |
| #hexists | Determine if a hash field exists. |
| #hexpire |
|
| #hget | Get the value of a hash field. |
| #hgetall | Get all the fields and values in a hash. |
| #hincrby | Increment the integer value of a hash field by the given integer number. |
| #hincrbyfloat | Increment the numeric value of a hash field by the given float number. |
| #hkeys | Get all the fields in a hash. |
| #hlen | Get the number of fields in a hash. |
| #hmget | Get the values of all the given hash fields. |
| #hmset | Set one or more hash values. |
| #hrandfield | Get one or more random fields from a hash. |
| #hscan | Scan a hash. |
| #hscan_each | Scan a hash. |
| #hset | Set one or more hash values. |
| #hsetnx | Set the value of a hash field, only if the field does not exist. |
| #httl | Returns the time to live in seconds for one or more fields. |
| #hvals | Get all the values in a hash. |
| #mapped_hmget | Get the values of all the given hash fields. |
| #mapped_hmset | Set one or more hash values. |
Geo - Included
| #geoadd | Adds the specified geospatial items (latitude, longitude, name) to the specified key. |
| #geodist | Returns the distance between two members of a geospatial index. |
| #geohash | Returns geohash string representing position for specified members of the specified key. |
| #geopos | Returns longitude and latitude of members of a geospatial index. |
| #georadius | Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point. |
| #georadiusbymember | Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from an already existing member. |
| #_geoarguments | |
Cluster - Included
| #asking | Sends |
| #cluster | Sends |
Bitmaps - Included
| #bitcount | Count the number of set bits in a range of the string value stored at key. |
| #bitop | Perform a bitwise operation between strings and store the resulting string in a key. |
| #bitpos | Return the position of the first bit set to 1 or 0 in a string. |
| #getbit | Returns the bit value at offset in the string value stored at key. |
| #setbit |
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*command) (private)
[ GitHub ]# File 'lib/redis/commands.rb', line 235
def method_missing(*command) # rubocop:disable Style/MissingRespondToMissing send_command(command) end
Instance Method Details
#call(*command, &block)
Sends a command to ::Redis and returns its reply.
Replies are converted to Ruby objects according to the RESP protocol, so
you can expect a Ruby array, integer or nil when ::Redis sends one. Higher
level transformations, such as converting an array of pairs into a Ruby
hash, are up to consumers.
::Redis error replies are raised as Ruby exceptions.
# File 'lib/redis/commands.rb', line 204
def call(*command, &block) send_command(command, &block) end
#sentinel(subcommand, *args) ⇒ Array<String>, ...
Interact with the sentinel command (masters, master, slaves, failover)
# File 'lib/redis/commands.rb', line 213
def sentinel(subcommand, *args) subcommand = subcommand.to_s.downcase send_command([:sentinel, subcommand] + args) do |reply| case subcommand when "get-master-addr-by-name" reply else if reply.is_a?(Array) if reply[0].is_a?(Array) reply.map(&Hashify) else Hashify.call(reply) end else reply end end end end