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_reply(mode) ⇒ String
Configure client reply mode.
-
#client_set_info(attr, value) ⇒ String
Set client connection information.
-
#client_set_name(name) ⇒ String
Set the current client's name.
-
#client_unblock(client_id, unblock_type = nil) ⇒ Integer
Unblock a client blocked in a blocking operation.
-
#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.
-
#quit ⇒ String
deprecated
Deprecated.
The QUIT command is deprecated since Redis 7.2.0 / Valkey 7.2+. Clients should use the
closemethod directly instead. This avoids lingering TIME_WAIT sockets on the server side. -
#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.
103 104 105 |
# File 'lib/valkey/commands/connection_commands.rb', line 103 def client(subcommand, *args) public_send("client_#{subcommand.to_s.downcase}", *args) end |
#client_get_name ⇒ String?
Get the current client's name.
118 119 120 |
# File 'lib/valkey/commands/connection_commands.rb', line 118 def client_get_name send_command(RequestType::CLIENT_GET_NAME) end |
#client_id(route: nil) ⇒ Integer
Get the current client's ID.
111 112 113 |
# File 'lib/valkey/commands/connection_commands.rb', line 111 def client_id(route: nil) send_command(RequestType::CLIENT_ID, [], route: route) end |
#client_info ⇒ String
Get information about the current client connection.
158 159 160 |
# File 'lib/valkey/commands/connection_commands.rb', line 158 def client_info send_command(RequestType::CLIENT_INFO) end |
#client_kill(addr = nil, **options) ⇒ Integer
Kill client connections.
167 168 169 170 171 172 173 |
# File 'lib/valkey/commands/connection_commands.rb', line 167 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).
179 180 181 |
# File 'lib/valkey/commands/connection_commands.rb', line 179 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/valkey/commands/connection_commands.rb', line 135 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.
292 293 294 |
# File 'lib/valkey/commands/connection_commands.rb', line 292 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.
300 301 302 |
# File 'lib/valkey/commands/connection_commands.rb', line 300 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.
208 209 210 211 212 |
# File 'lib/valkey/commands/connection_commands.rb', line 208 def client_pause(timeout, mode = nil) args = [timeout] args << mode if mode send_command(RequestType::CLIENT_PAUSE, args) end |
#client_reply(mode) ⇒ String
Configure client reply mode.
226 227 228 |
# File 'lib/valkey/commands/connection_commands.rb', line 226 def client_reply(mode) send_command(RequestType::CLIENT_REPLY, [mode]) end |
#client_set_info(attr, value) ⇒ String
Set client connection information.
246 247 248 |
# File 'lib/valkey/commands/connection_commands.rb', line 246 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.
126 127 128 |
# File 'lib/valkey/commands/connection_commands.rb', line 126 def client_set_name(name) send_command(RequestType::CLIENT_SET_NAME, [name]) end |
#client_unblock(client_id, unblock_type = nil) ⇒ Integer
Unblock a client blocked in a blocking operation.
235 236 237 238 239 |
# File 'lib/valkey/commands/connection_commands.rb', line 235 def client_unblock(client_id, unblock_type = nil) args = [client_id] args << unblock_type if unblock_type send_command(RequestType::CLIENT_UNBLOCK, args) end |
#client_unpause(route: nil) ⇒ String
Unpause client processing.
218 219 220 |
# File 'lib/valkey/commands/connection_commands.rb', line 218 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.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/valkey/commands/connection_commands.rb', line 74 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 |
#quit ⇒ String
The QUIT command is deprecated since Redis 7.2.0 / Valkey 7.2+.
Clients should use the close method directly instead.
This avoids lingering TIME_WAIT sockets on the server side.
Close the connection.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/valkey/commands/connection_commands.rb', line 58 def quit # For compatibility, we still support QUIT but recommend using close() instead send_command(RequestType::QUIT) rescue ConnectionError # Server closes connection immediately after QUIT nil ensure # Clean up our side of the connection close if respond_to?(:close) end |
#reset ⇒ String
Reset the connection state.
90 91 92 |
# File 'lib/valkey/commands/connection_commands.rb', line 90 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 |