module Oxblood::Commands::Keys
Public Instance Methods
Delete a key @see redis.io/commands/del
@param [String, Array<String>] keys to delete
@return [Integer] the number of keys that were removed
# File lib/oxblood/commands/keys.rb, line 12 def del(*keys) run(*keys.unshift(:DEL)) end
Return a serialized version of the value stored at specified key. @see redis.io/commands/dump
@param [String] key
@return [String] serialized value
# File lib/oxblood/commands/keys.rb, line 22 def dump(key) run(:DUMP, key) end
Determine if a key exists @see redis.io/commands/exists
@param [String, Array<String>] keys to check
@return [Integer] the number of keys existing among the ones specified as
arguments. Keys mentioned multiple times and existing are counted multiple times.
# File lib/oxblood/commands/keys.rb, line 34 def exists(*keys) run(*keys.unshift(:EXISTS)) end
Set a key's time to live in seconds @see redis.io/commands/expire
@param [String] key to expire @param [Integer] seconds number of seconds
@return [Integer] 1 if the timeout was set. 0 if key does not exist or
the timeout could not be set.
# File lib/oxblood/commands/keys.rb, line 46 def expire(key, seconds) run(:EXPIRE, key, seconds) end
Set the expiration for a key as a UNIX timestamp @see redis.io/commands/expireat
@param [String] key @param [Integer] timestamp in UNIX format
@return [Integer] 1 if the timeout was set. 0 if key does not exist or
the timeout could not be set.
# File lib/oxblood/commands/keys.rb, line 58 def expireat(key, timestamp) run(:EXPIREAT, key, timestamp) end
Find all keys matching the given pattern @see redis.io/commands/keys
@param [String] pattern used to match keys
# File lib/oxblood/commands/keys.rb, line 66 def keys(pattern) run(:KEYS, pattern) end
Move a key to another database @see redis.io/commands/move
@param [String] key @param [Integer] db index
@return [Integer] 1 if key was moved and 0 otherwise.
# File lib/oxblood/commands/keys.rb, line 77 def move(key, db) run(:MOVE, key, db) end
Inspect the internals of Redis
objects @see redis.io/commands/object
@param [String] subcommand `REFCOUNT`, `ENCODING`, `IDLETIME` @param [String] key
@return [Integer] in case of `REFCOUNT` and `IDLETIME` subcommands @return [String] in case of `ENCODING` subcommand @return [nil] if object you try to inspect is missing
# File lib/oxblood/commands/keys.rb, line 90 def object(subcommand, key) run(:OBJECT, subcommand, key) end
Remove expiration from a key @see redis.io/commands/persist @param [String] key
@return [Integer] 1 if the timeout was removed and 0 otherwise
# File lib/oxblood/commands/keys.rb, line 99 def persist(key) run(:PERSIST, key) end
Set a key's time to live in milliseconds @see redis.io/commands/pexpire
@param [String] key @param [Integer] milliseconds
@return [Integer] 1 if the timeout was set and 0 otherwise
# File lib/oxblood/commands/keys.rb, line 110 def pexpire(key, milliseconds) run(:PEXPIRE, key, milliseconds) end
Set the expiration for a key as a UNIX timestamp specified in milliseconds @see redis.io/commands/pexpireat
@param [String] key @param [Integer] timestamp in milliseconds
@return [Integer] 1 if the timeout was set and 0 otherwise
# File lib/oxblood/commands/keys.rb, line 121 def pexpireat(key, timestamp) run(:PEXPIREAT, key, timestamp) end
Get the time to live for a key in milliseconds @see redis.io/commands/pttl
@param [String] key
@return [Integer] TTL in milliseconds, or a negative value in order to
signal an error
# File lib/oxblood/commands/keys.rb, line 132 def pttl(key) run(:PTTL, key) end
Return a random key from the keyspace @see redis.io/commands/randomkey
@return [String] the random key @return [nil] if database is empty
# File lib/oxblood/commands/keys.rb, line 141 def randomkey run(:RANDOMKEY) end
Rename a key @see redis.io/commands/rename
@param [String] key to rename @param [String] newkey
@return [String] OK in case of success @return [RError] if key does not exist. Before Redis
3.2.0, an error is
returned if source and destination names are the same.
# File lib/oxblood/commands/keys.rb, line 154 def rename(key, newkey) run(:RENAME, key, newkey) end
Rename a key, only if the new key does not exist @see redis.io/commands/renamenx
@param [String] key to rename @param [String] newkey
@return [Integer] 1 if key was renamed to newkey. 0 if newkey already
exists.
@return [RError] if key does not exist. Before Redis
3.2.0, an error is
returned if source and destination names are the same.
# File lib/oxblood/commands/keys.rb, line 168 def renamenx(key, newkey) run(:RENAMENX, key, newkey) end
Create a key using the provided serialized value, previously obtained using DUMP @see redis.io/commands/restore
@param [String] key @param [Integer] ttl expire time in milliseconds @param [String] serialized_value obtained using DUMP command @param [Hash] opts
@option opts [Boolean] :replace (false) Override key if it already exists
@return [String] OK on success @return [RError] if replace is false and key already exists or RDB version
and data checksum don't match.
# File lib/oxblood/commands/keys.rb, line 186 def restore(key, ttl, serialized_value, opts = {}) args = [:RESTORE, key, ttl, serialized_value] args << :REPLACE if opts[:replace] run(*args) end
Incrementally iterate the keys space @see redis.io/commands/scan
@param [Integer] cursor @param [Hash] opts
@option opts [Integer] :count Amount of work that should be done at
every call in order to retrieve elements from the collection.
@option opts [String] :match
@return [Array] two elements array, where the first element is String
representing an unsigned 64 bit number (the cursor), and the second element is an Array of elements.
# File lib/oxblood/commands/keys.rb, line 227 def scan(cursor, opts = {}) args = [:SCAN, cursor] Scan.merge_opts!(args, opts) run(*args) end
Get the time to live for a key @see redis.io/commands/ttl
@param [String] key
@return [Integer] TTL in seconds, or a negative value in order to signal
an error
# File lib/oxblood/commands/keys.rb, line 200 def ttl(key) run(:TTL, key) end
Determine the type stored at key @see redis.io/commands/type
@param [String] key
@return [String] type of key, or none when key does not exist.
# File lib/oxblood/commands/keys.rb, line 210 def type(key) run(:TYPE, key) end