Module: Valkey::Commands::Server
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/server.rb
Overview
This module contains commands related to server config.
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
-
#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.
10 11 12 13 |
# File 'lib/valkey/commands/server.rb', line 10 def bgrewriteaof # TODO: # send_command([:bgrewriteaof]) end |
#bgsave ⇒ String
Asynchronously save the dataset to disk.
18 19 20 21 |
# File 'lib/valkey/commands/server.rb', line 18 def bgsave # TODO: # send_command([:bgsave]) end |
#client(subcommand, *args) ⇒ String, Hash
Manage client connections.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/valkey/commands/server.rb', line 42 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.
28 29 30 31 32 33 34 35 36 |
# File 'lib/valkey/commands/server.rb', line 28 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.
58 59 60 |
# File 'lib/valkey/commands/server.rb', line 58 def dbsize send_command([:dbsize]) end |
#debug(*args) ⇒ Object
188 189 190 |
# File 'lib/valkey/commands/server.rb', line 188 def debug(*args) send_command([:debug] + args) end |
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
67 68 69 70 71 72 73 74 |
# File 'lib/valkey/commands/server.rb', line 67 def flushall( = nil) # TODO: # if options && options[:async] # send_command(%i[flushall async]) # else # send_command([:flushall]) # end end |
#flushdb(options = nil) ⇒ String
Remove all keys from the current database.
81 82 83 84 85 86 87 88 |
# File 'lib/valkey/commands/server.rb', line 81 def flushdb( = nil) # TODO: # if options && options[:async] # send_command(%i[flushdb async]) # else # send_command([:flushdb]) # end end |
#info(cmd = nil) ⇒ Hash<String, String>
Get information and statistics about the server.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/valkey/commands/server.rb', line 94 def info(cmd = nil) send_command([:info, cmd].compact) do |reply| if reply.is_a?(String) reply = 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.
115 116 117 |
# File 'lib/valkey/commands/server.rb', line 115 def lastsave send_command([:lastsave]) end |
#monitor {|line| ... } ⇒ Object
Listen for all requests received by the server in real time.
There is no way to interrupt this command.
125 126 127 128 129 130 131 132 133 |
# File 'lib/valkey/commands/server.rb', line 125 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.
138 139 140 |
# File 'lib/valkey/commands/server.rb', line 138 def save send_command([:save]) end |
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/valkey/commands/server.rb', line 143 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.
155 156 157 |
# File 'lib/valkey/commands/server.rb', line 155 def slaveof(host, port) send_command([:slaveof, host, port]) end |
#slowlog(subcommand, length = nil) ⇒ Array<String>, ...
Interact with the slowlog (get, len, reset)
164 165 166 167 168 |
# File 'lib/valkey/commands/server.rb', line 164 def slowlog(subcommand, length = nil) args = [:slowlog, subcommand] args << Integer(length) if length send_command(args) end |
#sync ⇒ Object
Internal command used for replication.
171 172 173 |
# File 'lib/valkey/commands/server.rb', line 171 def sync send_command([:sync]) end |
#time ⇒ Array<Integer>
Return the server time.
182 183 184 185 186 |
# File 'lib/valkey/commands/server.rb', line 182 def time send_command([:time]) do |reply| reply&.map(&:to_i) end end |