module Oxblood::Commands::Server

Public Instance Methods

bgrewriteaof() click to toggle source

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
bgsave() click to toggle source

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
client_getname() click to toggle source

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
client_kill(opts_or_addr = {}) click to toggle source

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
client_list() click to toggle source

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
client_pause(timeout) click to toggle source

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
client_setname(connection_name) click to toggle source

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
command() click to toggle source

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
command_count() click to toggle source

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
command_getkeys(*args) click to toggle source

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
command_info(*command_names) click to toggle source

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
config_get(parameter) click to toggle source

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
config_resetstat() click to toggle source

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
config_rewrite() click to toggle source

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
config_set(parameter, value) click to toggle source

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
dbsize() click to toggle source

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
flushall(opts = {}) click to toggle source

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
flushdb(opts = {}) click to toggle source

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
info(section = nil) click to toggle source

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
lastsave() click to toggle source

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
role() click to toggle source

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
save() click to toggle source

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
shutdown(opts = {}) click to toggle source

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
slaveof(host, port) click to toggle source

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
slowlog(subcommand, argument = nil) click to toggle source

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
time() click to toggle source

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