Module: Redis::Commands::Server
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/redis/commands/server.rb |
Instance Method Summary
-
#bgrewriteaof ⇒ String
Asynchronously rewrite the append-only file.
-
#bgsave ⇒ String
Asynchronously save the dataset to disk.
-
#client(subcommand, *args) ⇒ String, Hash
Manage client connections.
-
#config(action, *args) ⇒ String, Hash
Get or set server configuration parameters.
-
#dbsize ⇒ Integer
Return the number of keys in the selected database.
- #debug(*args)
-
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
-
#flushdb(options = nil) ⇒ String
Remove all keys from the current database.
-
#info(*sections) ⇒ Hash<String, String>
Get information and statistics about the server.
-
#lastsave ⇒ Integer
Get the UNIX time stamp of the last successful save to disk.
-
#monitor {|line| ... }
Listen for all requests received by the server in real time.
-
#save ⇒ String
Synchronously save the dataset to disk.
-
#shutdown(save: nil, now: false, force: false, abort: false) ⇒ nil, String
Synchronously save the dataset to disk and then shut down the server.
-
#slaveof(host, port)
Make the server a slave of another instance, or promote it as master.
-
#slowlog(subcommand, length = nil) ⇒ Array<String>, ...
Interact with the slowlog (get, len, reset).
-
#sync
Internal command used for replication.
-
#time ⇒ Array<Integer>
Return the server time.
-
#waitaof(numlocal, numreplicas, timeout) ⇒ Array<Integer>
Block until the write commands previously sent on this connection have been fsynced to the append-only file of the local server and/or of the given number of replicas.
Instance Method Details
#bgrewriteaof ⇒ String
Asynchronously rewrite the append-only file.
# File 'lib/redis/commands/server.rb', line 9
def bgrewriteaof send_command([:bgrewriteaof]) end
#bgsave ⇒ String
Asynchronously save the dataset to disk.
# File 'lib/redis/commands/server.rb', line 16
def bgsave send_command([:bgsave]) end
#client(subcommand, *args) ⇒ String, Hash
Manage client connections.
# File 'lib/redis/commands/server.rb', line 39
def client(subcommand, *args) send_command([:client, subcommand] + args) do |reply| if subcommand.to_s == "list" reply.lines.map do |line| entries = line.chomp.split(/[ =]/) Hash[entries.each_slice(2).to_a] end else reply end end end
#config(action, *args) ⇒ String, Hash
Get or set server configuration parameters.
# File 'lib/redis/commands/server.rb', line 25
def config(action, *args) send_command([:config, action] + args) do |reply| if reply.is_a?(Array) && action == :get Hashify.call(reply) else reply end end end
#dbsize ⇒ Integer
Return the number of keys in the selected database.
# File 'lib/redis/commands/server.rb', line 55
def dbsize send_command([:dbsize]) end
#debug(*args)
[ GitHub ]# File 'lib/redis/commands/server.rb', line 256
def debug(*args) send_command([:debug] + args) end
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
# File 'lib/redis/commands/server.rb', line 64
def flushall( = nil) if && [:async] send_command(%i[flushall async]) else send_command([:flushall]) end end
#flushdb(options = nil) ⇒ String
Remove all keys from the current database.
# File 'lib/redis/commands/server.rb', line 77
def flushdb( = nil) if && [:async] send_command(%i[flushdb async]) else send_command([:flushdb]) end end
#info(*sections) ⇒ Hash<String, String>
Get information and statistics about the server.
# File 'lib/redis/commands/server.rb', line 99
def info(*sections) sections.flatten!(1) sections.compact! send_command([:info].concat(sections)) do |reply| if reply.is_a?(String) reply = HashifyInfo.call(reply) if sections.size == 1 && sections.first.to_s == "commandstats" # Extract nested hashes for INFO COMMANDSTATS reply = Hash[reply.map do |k, v| v = v.split(",").map { |e| e.split("=") } [k[/^cmdstat_(.*)$/, 1], Hash[v]] end] end end reply end end
#lastsave ⇒ Integer
Get the UNIX time stamp of the last successful save to disk.
# File 'lib/redis/commands/server.rb', line 122
def lastsave send_command([:lastsave]) end
#monitor {|line| ... }
Listen for all requests received by the server in real time.
There is no way to interrupt this command.
#save ⇒ String
Synchronously save the dataset to disk.
# File 'lib/redis/commands/server.rb', line 145
def save send_command([:save]) end
#shutdown(save: nil, now: false, force: false, abort: false) ⇒ nil, String
Synchronously save the dataset to disk and then shut down the server.
# File 'lib/redis/commands/server.rb', line 205
def shutdown(save: nil, now: false, force: false, abort: false) args = [:shutdown] args << (save ? "SAVE" : "NOSAVE") unless save.nil? args << "NOW" if now args << "FORCE" if force args << "ABORT" if abort synchronize do |client| client.disable_reconnection do client.call_v(args) rescue ConnectionError # This means Redis has probably exited. nil end end end
#slaveof(host, port)
Make the server a slave of another instance, or promote it as master.
# File 'lib/redis/commands/server.rb', line 223
def slaveof(host, port) send_command([:slaveof, host, port]) end
#slowlog(subcommand, length = nil) ⇒ Array<String>, ...
Interact with the slowlog (get, len, reset)
# File 'lib/redis/commands/server.rb', line 232
def slowlog(subcommand, length = nil) args = [:slowlog, subcommand] args << Integer(length) if length send_command(args) end
#sync
Internal command used for replication.
# File 'lib/redis/commands/server.rb', line 239
def sync send_command([:sync]) end
#time ⇒ Array<Integer>
Return the server time.
# File 'lib/redis/commands/server.rb', line 250
def time send_command([:time]) do |reply| reply&.map(&:to_i) end end
#waitaof(numlocal, numreplicas, timeout) ⇒ Array<Integer>
Block until the write commands previously sent on this connection have been fsynced to the append-only file of the local server and/or of the given number of replicas.
The reply always reports how many local servers and replicas had fsynced the writes when
the command returned, whether or not the requested levels were reached, so compare it
against what you asked for. Inside multi the command does not block.
On Redis::Cluster the command is sent to every primary and each count is the minimum
across them (the server's agg_min policy): local is 1 only if every primary
fsynced, and replicas is the fewest acks any shard received. This per-connection
guarantee does not hold inside pipelined/multi on cluster: WAITAOF carries no
write flag, so the driver routes it to an arbitrary node (a random primary, or a
replica when replica: true) rather than the node(s) that carried the pipeline's
writes, so the reply is shape-correct but unrelated to those writes.
# File 'lib/redis/commands/server.rb', line 179
def waitaof(numlocal, numreplicas, timeout) timeout = Integer(timeout) command = [:waitaof, Integer(numlocal), Integer(numreplicas), timeout] send_blocking_command(command, timeout / 1000.0) end