Module: Oxblood::Commands::Server

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/server.rb

Instance Method Summary collapse

Instance Method Details

#bgrewriteaofString

Asynchronously rewrite the append-only file.

Returns:

  • (String)

    always 'OK'

See Also:


8
9
10
# File 'lib/oxblood/commands/server.rb', line 8

def bgrewriteaof
  run(:BGREWRITEAOF)
end

#bgsaveString

Asynchronously save the dataset to disk

Returns:

  • (String)

    command status message

See Also:


16
17
18
# File 'lib/oxblood/commands/server.rb', line 16

def bgsave
  run(:BGSAVE)
end

#client_getnamenil, String

Get the current conneciton name.

Returns:

  • (nil, String)

    client name

See Also:


24
25
26
# File 'lib/oxblood/commands/server.rb', line 24

def client_getname
  run(:CLIENT, :GETNAME)
end

#client_kill(opts_or_addr = {}) ⇒ String, Integer

Kill the connection of a client.

Parameters:

  • opts_or_addr (Hash, String) (defaults to: {})

    hash of options or addr in an addr:port form.

Options Hash (opts_or_addr):

  • :id (Integer)

    unique client ID.

  • :type (Symbol)

    Close connections of all the clients of specified type (for example: `normal`, `master`, `slave`, `pubsub`).

  • :addr (String)

    ip:port which matches a line returned by CLIENT LIST command (addr field).

  • :skipme (Boolean)

    Skip client that is calling this command (enabled by default).

Returns:

  • (String)

    'OK'

  • (Integer)

    the number of clients killed when called with the filter/value format

See Also:


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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_listString

Get the list of client connections.

Returns:

  • (String)

    client list in the formatted string

See Also:


32
33
34
# File 'lib/oxblood/commands/server.rb', line 32

def client_list
  run(:CLIENT, :LIST)
end

#client_pause(timeout) ⇒ String

Stop processing commands from clients for some time.

Parameters:

  • timeout (Integer)

    in milliseconds

Returns:

  • (String)

    'OK' in case of success.

See Also:


100
101
102
# File 'lib/oxblood/commands/server.rb', line 100

def client_pause(timeout)
  run(:CLIENT, :PAUSE, timeout)
end

#client_setname(connection_name) ⇒ String

Set the current connection name.

Parameters:

  • connection_name (String)

Returns:

  • (String)

    'OK' in case of success.

See Also:


90
91
92
# File 'lib/oxblood/commands/server.rb', line 90

def client_setname(connection_name)
  run(:CLIENT, :SETNAME, connection_name)
end

#commandArray

Get array of Redis command details.

Returns:

  • (Array)

    nested list of command details

See Also:


108
109
110
# File 'lib/oxblood/commands/server.rb', line 108

def command
  run(:COMMAND)
end

#command_countInteger

Get total number of Redis commands.

Returns:

  • (Integer)

    number of commands returned by COMMAND

See Also:


116
117
118
# File 'lib/oxblood/commands/server.rb', line 116

def command_count
  run(:COMMAND, :COUNT)
end

#command_getkeys(*args) ⇒ Array

Extract keys given a full Redis command

Returns:

  • (Array)

    list of keys from your command

See Also:


124
125
126
# File 'lib/oxblood/commands/server.rb', line 124

def command_getkeys(*args)
  run(*args.unshift(:COMMAND, :GETKEYS))
end

#command_info(*command_names) ⇒ Array

Get array of specific Redis command details.

Parameters:

  • command_names (String, Array<String>)

Returns:

  • (Array)

    nested list of command details.

See Also:


134
135
136
# File 'lib/oxblood/commands/server.rb', line 134

def command_info(*command_names)
  run(*command_names.unshift(:COMMAND, :INFO))
end

#config_get(parameter) ⇒ Array

Get the value of a configuration parameter

Parameters:

  • parameter (String)

Returns:

  • (Array)

    parameters with values

See Also:


144
145
146
# File 'lib/oxblood/commands/server.rb', line 144

def config_get(parameter)
  run(:CONFIG, :GET, parameter)
end

#config_resetstatString

Reset the stats returned by INFO

Returns:

  • (String)

    'OK'

See Also:


171
172
173
# File 'lib/oxblood/commands/server.rb', line 171

def config_resetstat
  run(:CONFIG, :RESETSTAT)
end

#config_rewriteString

Rewrite the configuration file with the in memory configuration

Returns:

  • (String)

    'OK'

See Also:


152
153
154
# File 'lib/oxblood/commands/server.rb', line 152

def config_rewrite
  run(:CONFIG, :REWRITE)
end

#config_set(parameter, value) ⇒ String

Set a configuration parameter to the given value

Parameters:

  • parameter (String)
  • value (String)

Returns:

  • (String)

    OK if parameter was set properly.

See Also:


163
164
165
# File 'lib/oxblood/commands/server.rb', line 163

def config_set(parameter, value)
  run(:CONFIG, :SET, parameter, value)
end

#dbsizeInteger

Return the number of keys in the selected database

Returns:

  • (Integer)

    selected database size

See Also:


179
180
181
# File 'lib/oxblood/commands/server.rb', line 179

def dbsize
  run(:DBSIZE)
end

#flushall(opts = {}) ⇒ String

Remove all keys from all databases.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :async (Boolean)

Returns:

  • (String)

    'OK'

See Also:


191
192
193
# File 'lib/oxblood/commands/server.rb', line 191

def flushall(opts = {})
  opts[:async] ? run(:FLUSHALL, :ASYNC) : run(:FLUSHALL)
end

#flushdb(opts = {}) ⇒ String

Remove all keys from the current database.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :async (Boolean)

Returns:

  • (String)

    should always return 'OK'

See Also:


203
204
205
# File 'lib/oxblood/commands/server.rb', line 203

def flushdb(opts = {})
  opts[:async] ? run(:FLUSHDB, :ASYNC) : run(:FLUSHDB)
end

#info(section = nil) ⇒ String

Returns information and statistics about the server in a format that is simple to parse by computers and easy to read by humans.

Parameters:

  • section (String) (defaults to: nil)

    used to select a specific section of information

Returns:

  • (String)

    raw redis server response as a collection of text lines.

See Also:


214
215
216
# File 'lib/oxblood/commands/server.rb', line 214

def info(section = nil)
  section ? run(:INFO, section) : run(:INFO)
end

#lastsaveInteger

Get the UNIX timestamp of the last successful save to disk.

Returns:

  • (Integer)

    an UNIX timestamp.

See Also:


222
223
224
# File 'lib/oxblood/commands/server.rb', line 222

def lastsave
  run(:LASTSAVE)
end

#roleArray

Return the role of the instance in the context of replication.

Returns:

  • (Array)

    where the first element is one of master, slave, sentinel and the additional elements are role-specific as illustrated above.

See Also:


232
233
234
# File 'lib/oxblood/commands/server.rb', line 232

def role
  run(:ROLE)
end

#saveString

Synchronously save the dataset to disk.

Returns:

  • (String)

    'OK'

See Also:


240
241
242
# File 'lib/oxblood/commands/server.rb', line 240

def save
  run(:SAVE)
end

#shutdown(opts = {}) ⇒ RError?

Synchronously save the dataset to disk and then shutdown the server.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :save (Boolean)

    truthy value acts as SAVE and explicit `false` value acts as NOSAVE. `nil` or absence of option don't add anything.

Returns:

  • (RError)

    in case of failure and nothing

  • (nil)

    in case of success

See Also:


254
255
256
257
258
259
260
261
262
263
264
265
# 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) ⇒ String

Make the server a slave of another instance, or promote it as master.

Examples:

Make server slave

session.slaveof('localhost', 7777)

Promote to master

session.slaveof(:NO, :ONE)

Parameters:

  • host (String)
  • port (String)

Returns:

  • (String)

    'OK'

See Also:


279
280
281
# File 'lib/oxblood/commands/server.rb', line 279

def slaveof(host, port)
  run(:SLAVEOF, host, port)
end

#slowlog(subcommand, argument = nil) ⇒ Integer, ...

Manages the Redis slow queries log.

Parameters:

  • subcommand (Symbol)

    For example :len, :reset, :get

  • argument (String) (defaults to: nil)

Returns:

  • (Integer)

    for :len subcommand

  • (String)

    'OK' for :reset subcommand

  • (Array)

    for :get subcommand

See Also:


292
293
294
295
296
# File 'lib/oxblood/commands/server.rb', line 292

def slowlog(subcommand, argument = nil)
  args = [:SLOWLOG, subcommand]
  args << argument if argument
  run(*args)
end

#timeArray<String, String>

Returns the current server time.

Returns:

  • (Array<String, String>)

    unix time in seconds and microseconds.

See Also:


302
303
304
# File 'lib/oxblood/commands/server.rb', line 302

def time
  run(:TIME)
end