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) ⇒ Object
Send a generic CLIENT subcommand.
-
#client_caching(*args) ⇒ String
Enable or disable client query caching.
-
#client_get_name ⇒ String?
Get the name of the current connection.
-
#client_getredir ⇒ Integer
Get the client ID that the current client is redirected to.
-
#client_id ⇒ Integer
Get the current connection’s client ID.
-
#client_info ⇒ String
Get information about the current client connection.
-
#client_kill(*args) ⇒ Integer
Kill client connections by address or ID.
-
#client_kill_simple(*args) ⇒ Integer
Simplified client kill command, similar to ‘client_kill`.
-
#client_list ⇒ Array<Hash>
Get a list of client connections.
-
#client_no_evict(*args) ⇒ String
Enable or disable the no-eviction flag for the current client.
-
#client_no_touch(*args) ⇒ String
Enable or disable the no-touch flag for the current client.
-
#client_pause(*args) ⇒ String
Pause processing of commands from clients for a given time.
-
#client_reply(*args) ⇒ String
Control client reply behavior (e.g., ON, OFF, SKIP).
-
#client_set_info(*args) ⇒ String
Set client information fields.
-
#client_set_name(*args) ⇒ String
Set the name of the current connection.
-
#client_tracking(*args) ⇒ String
Enable or disable client tracking.
-
#client_tracking_info ⇒ Array
Get information about client tracking.
-
#client_unblock(*args) ⇒ Integer
Unblock a client by client ID.
-
#client_unpause ⇒ String
Resume processing of commands from clients after a pause.
-
#config(action, *args) ⇒ String, Hash
Get or set server configuration parameters.
-
#config_get(*args) ⇒ Hash, String
Get server configuration parameters.
-
#config_resetstat ⇒ String
Reset the server’s statistics.
-
#config_rewrite ⇒ String
Rewrite the server configuration file.
-
#config_set(*args) ⇒ String
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) ⇒ Object
Send a generic CLIENT subcommand.
100 101 102 |
# File 'lib/valkey/commands/server_commands.rb', line 100 def client(subcommand, *args) send("client_#{subcommand.to_s.downcase}", *args) end |
#client_caching(*args) ⇒ String
Enable or disable client query caching.
237 238 239 |
# File 'lib/valkey/commands/server_commands.rb', line 237 def client_caching(*args) send_command(RequestType::CLIENT_CACHING, args) end |
#client_get_name ⇒ String?
Get the name of the current connection.
124 125 126 |
# File 'lib/valkey/commands/server_commands.rb', line 124 def client_get_name send_command(RequestType::CLIENT_GET_NAME) end |
#client_getredir ⇒ Integer
Get the client ID that the current client is redirected to.
244 245 246 |
# File 'lib/valkey/commands/server_commands.rb', line 244 def client_getredir send_command(RequestType::CLIENT_GET_REDIR) end |
#client_id ⇒ Integer
Get the current connection’s client ID.
161 162 163 |
# File 'lib/valkey/commands/server_commands.rb', line 161 def client_id send_command(RequestType::CLIENT_ID) end |
#client_info ⇒ String
Get information about the current client connection.
221 222 223 |
# File 'lib/valkey/commands/server_commands.rb', line 221 def client_info send_command(RequestType::CLIENT_INFO) end |
#client_kill(*args) ⇒ Integer
Kill client connections by address or ID.
144 145 146 |
# File 'lib/valkey/commands/server_commands.rb', line 144 def client_kill(*args) send_command(RequestType::CLIENT_KILL, args) end |
#client_kill_simple(*args) ⇒ Integer
Simplified client kill command, similar to ‘client_kill`.
152 153 154 |
# File 'lib/valkey/commands/server_commands.rb', line 152 def client_kill_simple(*args) send_command(RequestType::CLIENT_KILL, args) end |
#client_list ⇒ Array<Hash>
Get a list of client connections.
110 111 112 113 114 115 116 117 |
# File 'lib/valkey/commands/server_commands.rb', line 110 def client_list send_command(RequestType::CLIENT_LIST) do |reply| reply.lines.map do |line| entries = line.chomp.split(/[ =]/) Hash[entries.each_slice(2).to_a] end end end |
#client_no_evict(*args) ⇒ String
Enable or disable the no-eviction flag for the current client.
252 253 254 |
# File 'lib/valkey/commands/server_commands.rb', line 252 def client_no_evict(*args) send_command(RequestType::CLIENT_NO_EVICT, args) end |
#client_no_touch(*args) ⇒ String
Enable or disable the no-touch flag for the current client.
260 261 262 |
# File 'lib/valkey/commands/server_commands.rb', line 260 def client_no_touch(*args) send_command(RequestType::CLIENT_NO_TOUCH, args) end |
#client_pause(*args) ⇒ String
Pause processing of commands from clients for a given time.
182 183 184 |
# File 'lib/valkey/commands/server_commands.rb', line 182 def client_pause(*args) send_command(RequestType::CLIENT_PAUSE, args) end |
#client_reply(*args) ⇒ String
Control client reply behavior (e.g., ON, OFF, SKIP).
214 215 216 |
# File 'lib/valkey/commands/server_commands.rb', line 214 def client_reply(*args) send_command(RequestType::CLIENT_REPLY, args) end |
#client_set_info(*args) ⇒ String
Set client information fields.
229 230 231 |
# File 'lib/valkey/commands/server_commands.rb', line 229 def client_set_info(*args) send_command(RequestType::CLIENT_SET_INFO, args) end |
#client_set_name(*args) ⇒ String
Set the name of the current connection.
134 135 136 |
# File 'lib/valkey/commands/server_commands.rb', line 134 def client_set_name(*args) send_command(RequestType::CLIENT_SET_NAME, args) end |
#client_tracking(*args) ⇒ String
Enable or disable client tracking.
199 200 201 |
# File 'lib/valkey/commands/server_commands.rb', line 199 def client_tracking(*args) send_command(RequestType::CLIENT_TRACKING, args) end |
#client_tracking_info ⇒ Array
Get information about client tracking.
206 207 208 |
# File 'lib/valkey/commands/server_commands.rb', line 206 def client_tracking_info send_command(RequestType::CLIENT_TRACKING_INFO) end |
#client_unblock(*args) ⇒ Integer
Unblock a client by client ID.
171 172 173 |
# File 'lib/valkey/commands/server_commands.rb', line 171 def client_unblock(*args) send_command(RequestType::CLIENT_UNBLOCK, args) end |
#client_unpause ⇒ String
Resume processing of commands from clients after a pause.
191 192 193 |
# File 'lib/valkey/commands/server_commands.rb', line 191 def client_unpause send_command(RequestType::CLIENT_UNPAUSE) end |
#config(action, *args) ⇒ String, Hash
Get or set server configuration parameters.
29 30 31 |
# File 'lib/valkey/commands/server_commands.rb', line 29 def config(action, *args) send("config_#{action.to_s.downcase}", *args) end |
#config_get(*args) ⇒ Hash, String
Returns a Hash with parameter names as keys and values as values when multiple params requested.
Get server configuration parameters.
Sends the CONFIG GET command with the given arguments.
48 49 50 51 52 53 54 55 56 |
# File 'lib/valkey/commands/server_commands.rb', line 48 def config_get(*args) send_command(RequestType::CONFIG_GET, args) do |reply| if reply.is_a?(Array) Hash[*reply] else reply end end end |
#config_resetstat ⇒ String
Reset the server’s statistics.
Sends the CONFIG RESETSTAT command.
79 80 81 |
# File 'lib/valkey/commands/server_commands.rb', line 79 def config_resetstat send_command(RequestType::CONFIG_RESET_STAT) end |
#config_rewrite ⇒ String
Rewrite the server configuration file.
Sends the CONFIG REWRITE command.
91 92 93 |
# File 'lib/valkey/commands/server_commands.rb', line 91 def config_rewrite send_command(RequestType::CONFIG_REWRITE) end |
#config_set(*args) ⇒ String
Set server configuration parameters.
Sends the CONFIG SET command with the given key-value pairs.
67 68 69 |
# File 'lib/valkey/commands/server_commands.rb', line 67 def config_set(*args) send_command(RequestType::CONFIG_SET, args) end |
#dbsize ⇒ Integer
Return the number of keys in the selected database.
267 268 269 |
# File 'lib/valkey/commands/server_commands.rb', line 267 def dbsize send_command(RequestType::DB_SIZE) end |
#debug(*args) ⇒ Object
RequestType::DEBUG not exist
394 395 396 |
# File 'lib/valkey/commands/server_commands.rb', line 394 def debug(*args) send_command(RequestType::DEBUG, args) end |
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
276 277 278 279 280 281 282 |
# File 'lib/valkey/commands/server_commands.rb', line 276 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.
289 290 291 292 293 294 295 |
# File 'lib/valkey/commands/server_commands.rb', line 289 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.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/valkey/commands/server_commands.rb', line 301 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.
322 323 324 |
# File 'lib/valkey/commands/server_commands.rb', line 322 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.
332 333 334 335 336 337 338 339 340 |
# File 'lib/valkey/commands/server_commands.rb', line 332 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.
345 346 347 |
# File 'lib/valkey/commands/server_commands.rb', line 345 def save send_command(RequestType::SAVE) end |
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
350 351 352 353 354 355 356 357 358 359 |
# File 'lib/valkey/commands/server_commands.rb', line 350 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.
362 363 364 |
# File 'lib/valkey/commands/server_commands.rb', line 362 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)
371 372 373 374 375 |
# File 'lib/valkey/commands/server_commands.rb', line 371 def slowlog(subcommand, length = nil) args = [:slowlog, subcommand] args << Integer(length) if length send_command(args) end |
#sync ⇒ Object
Internal command used for replication.
378 379 380 |
# File 'lib/valkey/commands/server_commands.rb', line 378 def sync send_command(RequestType::SYNC) end |
#time ⇒ Array<Integer>
Return the server time.
389 390 391 |
# File 'lib/valkey/commands/server_commands.rb', line 389 def time send_command(RequestType::TIME) end |