module Oxblood::Commands::Server
Public Instance Methods
Asynchronously rewrite the append-only file. @see redis.io/commands/bgrewriteaof
@return [String] always 'OK'
# File lib/oxblood/commands/server.rb, line 8 def bgrewriteaof run(:BGREWRITEAOF) end
Asynchronously save the dataset to disk @see redis.io/commands/bgsave
@return [String] command status message
# File lib/oxblood/commands/server.rb, line 16 def bgsave run(:BGSAVE) end
Get the current conneciton name. @see redis.io/commands/client-getname
@return [nil, String] client name
# File lib/oxblood/commands/server.rb, line 24 def client_getname run(:CLIENT, :GETNAME) end
Kill the connection of a client. @see redis.io/commands/client-kill
@param [Hash, String] opts_or_addr hash of options or addr in
an addr:port form.
@option opts_or_addr [Integer] :id unique client ID. @option opts_or_addr [Symbol] :type Close connections of all the clients
of specified type (for example: `normal`, `master`, `slave`, `pubsub`).
@option opts_or_addr [String] :addr ip:port which matches a line
returned by CLIENT LIST command (addr field).
@option opts_or_addr [Boolean] :skipme Skip client that is calling this
command (enabled by default).
@return [String] 'OK' @return [Integer] the number of clients killed when called with
the filter/value format
# File lib/oxblood/commands/server.rb, line 53 def client_kill(opts_or_addr = {}) if opts_or_addr.is_a?(String) run(:CLIENT, :KILL, opts_or_addr) else args = [:CLIENT, :KILL] if v = opts_or_addr[:id] args.push(:ID, v) end if v = opts_or_addr[:type] args.push(:TYPE, v) end if v = opts_or_addr[:addr] args.push(:ADDR, v) end if opts_or_addr.key?(:skipme) case opts_or_addr[:skipme] when false, 'no'.freeze args.push(:SKIPME, 'no'.freeze) when true, 'yes'.freeze args.push(:SKIPME, 'yes'.freeze) end end run(*args) end end
Get the list of client connections. @see redis.io/commands/client-list
@return [String] client list in the formatted string
# File lib/oxblood/commands/server.rb, line 32 def client_list run(:CLIENT, :LIST) end
Stop processing commands from clients for some time. @see redis.io/commands/client-pause
@param [Integer] timeout in milliseconds
@return [String] 'OK' in case of success.
# File lib/oxblood/commands/server.rb, line 100 def client_pause(timeout) run(:CLIENT, :PAUSE, timeout) end
Set the current connection name. @see redis.io/commands/client-setname
@param [String] connection_name
@return [String] 'OK' in case of success.
# File lib/oxblood/commands/server.rb, line 90 def client_setname(connection_name) run(:CLIENT, :SETNAME, connection_name) end
Get array of Redis
command details. @see redis.io/commands/command
@return [Array] nested list of command details
# File lib/oxblood/commands/server.rb, line 108 def command run(:COMMAND) end
Get total number of Redis
commands. @see redis.io/commands/command-count
@return [Integer] number of commands returned by COMMAND
# File lib/oxblood/commands/server.rb, line 116 def command_count run(:COMMAND, :COUNT) end
Extract keys given a full Redis
command @see redis.io/commands/command-getkeys
@return [Array] list of keys from your command
# File lib/oxblood/commands/server.rb, line 124 def command_getkeys(*args) run(*args.unshift(:COMMAND, :GETKEYS)) end
Get array of specific Redis
command details. @see redis.io/commands/command-info
@param [String, Array<String>] command_names
@return [Array] nested list of command details.
# File lib/oxblood/commands/server.rb, line 134 def command_info(*command_names) run(*command_names.unshift(:COMMAND, :INFO)) end
Get the value of a configuration parameter @see redis.io/commands/config-get
@param [String] parameter
@return [Array] parameters with values
# File lib/oxblood/commands/server.rb, line 144 def config_get(parameter) run(:CONFIG, :GET, parameter) end
Reset the stats returned by INFO @see redis.io/commands/config-resetstat
@return [String] 'OK'
# File lib/oxblood/commands/server.rb, line 171 def config_resetstat run(:CONFIG, :RESETSTAT) end
Rewrite the configuration file with the in memory configuration @see redis.io/commands/config-rewrite
@return [String] 'OK'
# File lib/oxblood/commands/server.rb, line 152 def config_rewrite run(:CONFIG, :REWRITE) end
Set a configuration parameter to the given value @see redis.io/commands/config-set
@param [String] parameter @param [String] value
@return [String] OK if parameter was set properly.
# File lib/oxblood/commands/server.rb, line 163 def config_set(parameter, value) run(:CONFIG, :SET, parameter, value) end
Return the number of keys in the selected database @see redis.io/commands/dbsize
@return [Integer] selected database size
# File lib/oxblood/commands/server.rb, line 179 def dbsize run(:DBSIZE) end
Remove all keys from all databases. @see redis.io/commands/flushall
@param [Hash] opts
@option opts [Boolean] :async
@return [String] 'OK'
# File lib/oxblood/commands/server.rb, line 191 def flushall(opts = {}) opts[:async] ? run(:FLUSHALL, :ASYNC) : run(:FLUSHALL) end
Remove all keys from the current database. @see redis.io/commands/flushdb
@param [Hash] opts
@option opts [Boolean] :async
@return [String] should always return 'OK'
# File lib/oxblood/commands/server.rb, line 203 def flushdb(opts = {}) opts[:async] ? run(:FLUSHDB, :ASYNC) : run(:FLUSHDB) end
Returns information and statistics about the server in a format that is simple to parse by computers and easy to read by humans. @see redis.io/commands/info
@param [String] section used to select a specific section of information
@return [String] raw redis server response as a collection of text lines.
# File lib/oxblood/commands/server.rb, line 214 def info(section = nil) section ? run(:INFO, section) : run(:INFO) end
Get the UNIX timestamp of the last successful save to disk. @see redis.io/commands/lastsave
@return [Integer] an UNIX timestamp.
# File lib/oxblood/commands/server.rb, line 222 def lastsave run(:LASTSAVE) end
Return the role of the instance in the context of replication. @see redis.io/commands/role
@return [Array] where the first element is one of master, slave,
sentinel and the additional elements are role-specific as illustrated above.
# File lib/oxblood/commands/server.rb, line 232 def role run(:ROLE) end
Synchronously save the dataset to disk. @see redis.io/commands/save
@return [String] 'OK'
# File lib/oxblood/commands/server.rb, line 240 def save run(:SAVE) end
Synchronously save the dataset to disk and then shutdown the server. @see redis.io/commands/shutdown
@param [Hash] opts
@option opts [Boolean] :save truthy value acts as SAVE and explicit
`false` value acts as NOSAVE. `nil` or absence of option don't add anything.
@return [RError] in case of failure and nothing @return [nil] in case of success
# File lib/oxblood/commands/server.rb, line 254 def shutdown(opts = {}) case opts[:save] when nil run(:SHUTDOWN) when false run(:SHUTDOWN, :NOSAVE) else run(:SHUTDOWN, :SAVE) end rescue Errno::ECONNRESET nil end
Make the server a slave of another instance, or promote it as master. @see redis.io/commands/slaveof
@example Make server slave
session.slaveof('localhost', 7777)
@example Promote to master
session.slaveof(:NO, :ONE)
@param [String] host @param [String] port
@return [String] 'OK'
# File lib/oxblood/commands/server.rb, line 279 def slaveof(host, port) run(:SLAVEOF, host, port) end
Manages the Redis
slow queries log. @see redis.io/commands/slowlog
@param [Symbol] subcommand For example :len, :reset, :get @param [String] argument
@return [Integer] for :len subcommand @return [String] 'OK' for :reset subcommand @return [Array] for :get subcommand
# File lib/oxblood/commands/server.rb, line 292 def slowlog(subcommand, argument = nil) args = [:SLOWLOG, subcommand] args << argument if argument run(*args) end
Returns the current server time. @see redis.io/commands/time
@return [Array<String, String>] unix time in seconds and microseconds.
# File lib/oxblood/commands/server.rb, line 302 def time run(:TIME) end