Module: Redis::Commands::Server
- Included in:
- Redis::Commands
- Defined in:
- lib/redis/commands/server.rb
Instance Method Summary collapse
-
#bgrewriteaof ⇒ String
Asynchronously rewrite the append-only file.
-
#bgsave ⇒ String
Asynchronously save the dataset to disk.
-
#client(subcommand = nil, *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.
9 10 11 |
# File 'lib/redis/commands/server.rb', line 9 def bgrewriteaof send_command([:bgrewriteaof]) end |
#bgsave ⇒ String
Asynchronously save the dataset to disk.
16 17 18 |
# File 'lib/redis/commands/server.rb', line 16 def bgsave send_command([:bgsave]) end |
#client(subcommand = nil, *args) ⇒ String, Hash
Manage client connections.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/redis/commands/server.rb', line 39 def client(subcommand = nil, *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.
25 26 27 28 29 30 31 32 33 |
# 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.
55 56 57 |
# File 'lib/redis/commands/server.rb', line 55 def dbsize send_command([:dbsize]) end |
#debug(*args) ⇒ Object
183 184 185 |
# File 'lib/redis/commands/server.rb', line 183 def debug(*args) send_command([:debug] + args) end |
#flushall(options = nil) ⇒ String
Remove all keys from all databases.
64 65 66 67 68 69 70 |
# 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.
77 78 79 80 81 82 83 |
# 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(cmd = nil) ⇒ Hash<String, String>
Get information and statistics about the server.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/redis/commands/server.rb', line 89 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.
110 111 112 |
# File 'lib/redis/commands/server.rb', line 110 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.
120 121 122 123 124 |
# File 'lib/redis/commands/server.rb', line 120 def monitor(&block) synchronize do |client| client.call_loop([:monitor], &block) end end |
#save ⇒ String
Synchronously save the dataset to disk.
129 130 131 |
# File 'lib/redis/commands/server.rb', line 129 def save send_command([:save]) end |
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/redis/commands/server.rb', line 134 def shutdown synchronize do |client| client.with_reconnect(false) do begin client.call([:shutdown]) rescue ConnectionError # This means Redis has probably exited. nil end end end end |
#slaveof(host, port) ⇒ Object
Make the server a slave of another instance, or promote it as master.
148 149 150 |
# File 'lib/redis/commands/server.rb', line 148 def slaveof(host, port) send_command([:slaveof, host, port]) end |
#slowlog(subcommand, length = nil) ⇒ Array<String>, ...
Interact with the slowlog (get, len, reset)
157 158 159 160 161 162 163 |
# File 'lib/redis/commands/server.rb', line 157 def slowlog(subcommand, length = nil) synchronize do |client| args = [:slowlog, subcommand] args << length if length client.call args end end |
#sync ⇒ Object
Internal command used for replication.
166 167 168 |
# File 'lib/redis/commands/server.rb', line 166 def sync send_command([:sync]) end |
#time ⇒ Array<Integer>
Return the server time.
177 178 179 180 181 |
# File 'lib/redis/commands/server.rb', line 177 def time send_command([:time]) do |reply| reply&.map(&:to_i) end end |