Module: Valkey::Commands::ConnectionCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/connection_commands.rb
Overview
This module contains commands related to connection management.
Instance Method Summary collapse
-
#auth(*args) ⇒ String
Authenticate to the server.
-
#client(subcommand, *args) ⇒ Object
Send a generic CLIENT subcommand.
-
#client_get_name ⇒ String?
Get the current client's name.
-
#client_id(route: nil) ⇒ Integer
Get the current client's ID.
-
#client_info ⇒ String
Get information about the current client connection.
-
#client_kill(addr = nil, **options) ⇒ Integer
Kill client connections.
-
#client_kill_simple(addr) ⇒ String
Kill a client connection by address (simple form).
-
#client_list(type: nil, ids: nil) ⇒ Array<Hash>
Get a list of client connections.
-
#client_no_evict(mode) ⇒ String
Enable/disable client no-evict mode.
-
#client_no_touch(mode) ⇒ String
Enable/disable client no-touch mode.
-
#client_pause(timeout, mode = nil) ⇒ String
Pause client processing.
-
#client_set_info(attr, value) ⇒ String
Set client connection information.
-
#client_set_name(name) ⇒ String
Set the current client's name.
-
#client_unpause(route: nil) ⇒ String
Unpause client processing.
-
#echo(value, route: nil) ⇒ String
Echo the given string.
-
#hello(protover = 3, **options) ⇒ Hash
Switch to a different protocol version and handshake with the server.
-
#ping(message = nil, route: nil) ⇒ String
Ping the server.
-
#reset ⇒ String
Reset the connection state.
-
#select(db) ⇒ String
Change the selected database for the current connection.
Instance Method Details
#auth(*args) ⇒ String
Authenticate to the server.
15 16 17 |
# File 'lib/valkey/commands/connection_commands.rb', line 15 def auth(*args) send_command(RequestType::AUTH, args) end |
#client(subcommand, *args) ⇒ Object
Send a generic CLIENT subcommand.
84 85 86 |
# File 'lib/valkey/commands/connection_commands.rb', line 84 def client(subcommand, *args) public_send("client_#{subcommand.to_s.downcase}", *args) end |
#client_get_name ⇒ String?
Get the current client's name.
99 100 101 |
# File 'lib/valkey/commands/connection_commands.rb', line 99 def client_get_name send_command(RequestType::CLIENT_GET_NAME) end |
#client_id(route: nil) ⇒ Integer
Get the current client's ID.
92 93 94 |
# File 'lib/valkey/commands/connection_commands.rb', line 92 def client_id(route: nil) send_command(RequestType::CLIENT_ID, [], route: route) end |
#client_info ⇒ String
Get information about the current client connection.
139 140 141 |
# File 'lib/valkey/commands/connection_commands.rb', line 139 def client_info send_command(RequestType::CLIENT_INFO) end |
#client_kill(addr = nil, **options) ⇒ Integer
Kill client connections.
148 149 150 151 152 153 154 |
# File 'lib/valkey/commands/connection_commands.rb', line 148 def client_kill(addr = nil, **) if addr && .empty? send_command(RequestType::CLIENT_KILL_SIMPLE, [addr]) else send_command(RequestType::CLIENT_KILL, build_client_kill_args(addr, )) end end |
#client_kill_simple(addr) ⇒ String
Kill a client connection by address (simple form).
160 161 162 |
# File 'lib/valkey/commands/connection_commands.rb', line 160 def client_kill_simple(addr) send_command(RequestType::CLIENT_KILL_SIMPLE, [addr]) end |
#client_list(type: nil, ids: nil) ⇒ Array<Hash>
Get a list of client connections.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/valkey/commands/connection_commands.rb', line 116 def client_list(type: nil, ids: nil) args = [] args << "TYPE" << type if type if ids args << "ID" args.concat(Array(ids)) end send_command(RequestType::CLIENT_LIST, args) do |reply| reply.lines.map do |line| line.chomp.split.each_with_object({}) do |pair, hash| key, value = pair.split("=", 2) hash[key] = value || "" end end end end |
#client_no_evict(mode) ⇒ String
Enable/disable client no-evict mode.
254 255 256 |
# File 'lib/valkey/commands/connection_commands.rb', line 254 def client_no_evict(mode) send_command(RequestType::CLIENT_NO_EVICT, [mode.to_s.upcase]) end |
#client_no_touch(mode) ⇒ String
Enable/disable client no-touch mode.
262 263 264 |
# File 'lib/valkey/commands/connection_commands.rb', line 262 def client_no_touch(mode) send_command(RequestType::CLIENT_NO_TOUCH, [mode.to_s.upcase]) end |
#client_pause(timeout, mode = nil) ⇒ String
Pause client processing.
189 190 191 192 193 |
# File 'lib/valkey/commands/connection_commands.rb', line 189 def client_pause(timeout, mode = nil) args = [timeout] args << mode if mode send_command(RequestType::CLIENT_PAUSE, args) end |
#client_set_info(attr, value) ⇒ String
Set client connection information.
208 209 210 |
# File 'lib/valkey/commands/connection_commands.rb', line 208 def client_set_info(attr, value) send_command(RequestType::CLIENT_SET_INFO, [attr, value]) end |
#client_set_name(name) ⇒ String
Set the current client's name.
107 108 109 |
# File 'lib/valkey/commands/connection_commands.rb', line 107 def client_set_name(name) send_command(RequestType::CLIENT_SET_NAME, [name]) end |
#client_unpause(route: nil) ⇒ String
Unpause client processing.
199 200 201 |
# File 'lib/valkey/commands/connection_commands.rb', line 199 def client_unpause(route: nil) send_command(RequestType::CLIENT_UNPAUSE, [], route: route) end |
#echo(value, route: nil) ⇒ String
Echo the given string.
38 39 40 |
# File 'lib/valkey/commands/connection_commands.rb', line 38 def echo(value, route: nil) send_command(RequestType::ECHO, [value], route: route) end |
#hello(protover = 3, **options) ⇒ Hash
Switch to a different protocol version and handshake with the server.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/valkey/commands/connection_commands.rb', line 55 def hello(protover = 3, **) args = [protover] if [:auth] args << "AUTH" args.concat(Array([:auth])) end args << "SETNAME" << [:setname] if [:setname] send_command(RequestType::HELLO, args) end |
#ping(message = nil, route: nil) ⇒ String
Ping the server.
29 30 31 |
# File 'lib/valkey/commands/connection_commands.rb', line 29 def ping( = nil, route: nil) send_command(RequestType::PING, [].compact, route: route) end |
#reset ⇒ String
Reset the connection state.
71 72 73 |
# File 'lib/valkey/commands/connection_commands.rb', line 71 def reset send_command(RequestType::RESET) end |
#select(db) ⇒ String
Change the selected database for the current connection.
46 47 48 |
# File 'lib/valkey/commands/connection_commands.rb', line 46 def select(db) send_command(RequestType::SELECT, [db]) end |