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.


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

def bgrewriteaof
  run(:BGREWRITEAOF)
end

#bgsaveString

Asynchronously save the dataset to disk


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

def bgsave
  run(:BGSAVE)
end

#client_getnamenil, String

Get the current conneciton name.


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.

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).

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.


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.


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.


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.


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

def command
  run(:COMMAND)
end

#command_countInteger

Get total number of Redis commands.


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


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.


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


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


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


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


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


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.

Options Hash (opts):

  • :async (Boolean)

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.

Options Hash (opts):

  • :async (Boolean)

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.


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.


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.


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

def role
  run(:ROLE)
end

#saveString

Synchronously save the dataset to disk.


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.

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.

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)

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.


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.


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

def time
  run(:TIME)
end