Module: Valkey::Commands::ServerCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/server_commands.rb
Overview
this module contains commands related to server management.
Instance Method Summary collapse
-
#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) ⇒ Object
RequestType::DEBUG not exist.
-
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
-
#flushdb(options = nil) ⇒ String
Remove all keys from the current database.
-
#info(cmd = nil) ⇒ 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| ... } ⇒ Object
Listen for all requests received by the server in real time.
-
#save ⇒ String
Synchronously save the dataset to disk.
-
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
-
#slaveof(host, port) ⇒ Object
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 ⇒ Object
Internal command used for replication.
-
#time ⇒ Array<Integer>
Return the server time.
Instance Method Details
#bgrewriteaof ⇒ String
Asynchronously rewrite the append-only file.
13 14 15 |
# File 'lib/valkey/commands/server_commands.rb', line 13 def bgrewriteaof send_command(RequestType::BG_REWRITE_AOF) end |
#bgsave ⇒ String
Asynchronously save the dataset to disk.
20 21 22 |
# File 'lib/valkey/commands/server_commands.rb', line 20 def bgsave send_command(RequestType::BG_SAVE) end |
#client(subcommand, *args) ⇒ String, Hash
Manage client connections.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/valkey/commands/server_commands.rb', line 45 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.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/valkey/commands/server_commands.rb', line 29 def config(action, *args) # TODO: not implemented yet # 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.
61 62 63 |
# File 'lib/valkey/commands/server_commands.rb', line 61 def dbsize send_command(RequestType::DB_SIZE) end |
#debug(*args) ⇒ Object
RequestType::DEBUG not exist
188 189 190 |
# File 'lib/valkey/commands/server_commands.rb', line 188 def debug(*args) send_command(RequestType::DEBUG, args) end |
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
70 71 72 73 74 75 76 |
# File 'lib/valkey/commands/server_commands.rb', line 70 def flushall( = nil) if && [:async] send_command(RequestType::FLUSH_ALL, ["async"]) else send_command(RequestType::FLUSH_ALL) end end |
#flushdb(options = nil) ⇒ String
Remove all keys from the current database.
83 84 85 86 87 88 89 |
# File 'lib/valkey/commands/server_commands.rb', line 83 def flushdb( = nil) if && [:async] send_command(RequestType::FLUSH_DB, ["async"]) else send_command(RequestType::FLUSH_DB) end end |
#info(cmd = nil) ⇒ Hash<String, String>
Get information and statistics about the server.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/valkey/commands/server_commands.rb', line 95 def info(cmd = nil) send_command(RequestType::INFO, [cmd].compact) do |reply| if reply.is_a?(String) reply = Utils::HashifyInfo.call(reply) if cmd && cmd.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.
116 117 118 |
# File 'lib/valkey/commands/server_commands.rb', line 116 def lastsave send_command(RequestType::LAST_SAVE) end |
#monitor {|line| ... } ⇒ Object
Listen for all requests received by the server in real time.
There is no way to interrupt this command.
126 127 128 129 130 131 132 133 134 |
# File 'lib/valkey/commands/server_commands.rb', line 126 def monitor synchronize do |client| client = client.pubsub client.call_v([:monitor]) loop do yield client.next_event end end end |
#save ⇒ String
Synchronously save the dataset to disk.
139 140 141 |
# File 'lib/valkey/commands/server_commands.rb', line 139 def save send_command(RequestType::SAVE) end |
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/valkey/commands/server_commands.rb', line 144 def shutdown synchronize do |client| client.disable_reconnection do client.call_v([:shutdown]) rescue ConnectionError # This means Redis has probably exited. nil end end end |
#slaveof(host, port) ⇒ Object
Make the server a slave of another instance, or promote it as master.
156 157 158 |
# File 'lib/valkey/commands/server_commands.rb', line 156 def slaveof(host, port) send_command(RequestType::SLAVE_OF, [host, port]) end |
#slowlog(subcommand, length = nil) ⇒ Array<String>, ...
Interact with the slowlog (get, len, reset)
165 166 167 168 169 |
# File 'lib/valkey/commands/server_commands.rb', line 165 def slowlog(subcommand, length = nil) args = [:slowlog, subcommand] args << Integer(length) if length send_command(args) end |
#sync ⇒ Object
Internal command used for replication.
172 173 174 |
# File 'lib/valkey/commands/server_commands.rb', line 172 def sync send_command(RequestType::SYNC) end |
#time ⇒ Array<Integer>
Return the server time.
183 184 185 |
# File 'lib/valkey/commands/server_commands.rb', line 183 def time send_command(RequestType::TIME) end |