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_caching(mode) ⇒ String
Enable/disable client caching.
-
#client_get_name ⇒ String?
Get the current client’s name.
-
#client_getredir ⇒ Integer
Get the client ID used for tracking redirection.
-
#client_id ⇒ 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_tracking(status, *args, **options) ⇒ String
Configure client tracking.
-
#client_tracking_info ⇒ Array
Get client tracking information.
-
#client_unblock(client_id, unblock_type = nil) ⇒ Integer
Unblock a client blocked in a blocking operation.
-
#client_unpause ⇒ String
Unpause client processing.
-
#echo(value) ⇒ String
Echo the given string.
-
#hello(protover = 3, **options) ⇒ Array
Switch to a different protocol version and handshake with the server.
-
#ping(message = 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 ‘close` method 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.
96 97 98 |
# File 'lib/valkey/commands/connection_commands.rb', line 96 def client(subcommand, *args) send("client_#{subcommand.to_s.downcase}", *args) end |
#client_caching(mode) ⇒ String
Enable/disable client caching.
243 244 245 |
# File 'lib/valkey/commands/connection_commands.rb', line 243 def client_caching(mode) send_command(RequestType::CLIENT_CACHING, [mode]) end |
#client_get_name ⇒ String?
Get the current client’s name.
110 111 112 |
# File 'lib/valkey/commands/connection_commands.rb', line 110 def client_get_name send_command(RequestType::CLIENT_GET_NAME) end |
#client_getredir ⇒ Integer
Get the client ID used for tracking redirection.
273 274 275 |
# File 'lib/valkey/commands/connection_commands.rb', line 273 def client_getredir send_command(RequestType::CLIENT_GET_REDIR) end |
#client_id ⇒ Integer
Get the current client’s ID.
103 104 105 |
# File 'lib/valkey/commands/connection_commands.rb', line 103 def client_id send_command(RequestType::CLIENT_ID) end |
#client_info ⇒ String
Get information about the current client connection.
148 149 150 |
# File 'lib/valkey/commands/connection_commands.rb', line 148 def client_info send_command(RequestType::CLIENT_INFO) end |
#client_kill(addr = nil, **options) ⇒ Integer
Kill client connections.
157 158 159 160 161 162 163 |
# File 'lib/valkey/commands/connection_commands.rb', line 157 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).
169 170 171 |
# File 'lib/valkey/commands/connection_commands.rb', line 169 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.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/valkey/commands/connection_commands.rb', line 127 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| entries = line.chomp.split(/[ =]/) entries.each_slice(2).to_a.to_h end end end |
#client_no_evict(mode) ⇒ String
Enable/disable client no-evict mode.
281 282 283 |
# File 'lib/valkey/commands/connection_commands.rb', line 281 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.
289 290 291 |
# File 'lib/valkey/commands/connection_commands.rb', line 289 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.
198 199 200 201 202 |
# File 'lib/valkey/commands/connection_commands.rb', line 198 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.
215 216 217 |
# File 'lib/valkey/commands/connection_commands.rb', line 215 def client_reply(mode) send_command(RequestType::CLIENT_REPLY, [mode]) end |
#client_set_info(attr, value) ⇒ String
Set client connection information.
235 236 237 |
# File 'lib/valkey/commands/connection_commands.rb', line 235 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.
118 119 120 |
# File 'lib/valkey/commands/connection_commands.rb', line 118 def client_set_name(name) send_command(RequestType::CLIENT_SET_NAME, [name]) end |
#client_tracking(status, *args, **options) ⇒ String
Configure client tracking.
257 258 259 260 261 |
# File 'lib/valkey/commands/connection_commands.rb', line 257 def client_tracking(status, *args, **) cmd_args = [status] cmd_args.concat(args.any? ? args : build_client_tracking_args()) send_command(RequestType::CLIENT_TRACKING, cmd_args) end |
#client_tracking_info ⇒ Array
Get client tracking information.
266 267 268 |
# File 'lib/valkey/commands/connection_commands.rb', line 266 def client_tracking_info send_command(RequestType::CLIENT_TRACKING_INFO) end |
#client_unblock(client_id, unblock_type = nil) ⇒ Integer
Unblock a client blocked in a blocking operation.
224 225 226 227 228 |
# File 'lib/valkey/commands/connection_commands.rb', line 224 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 ⇒ String
Unpause client processing.
207 208 209 |
# File 'lib/valkey/commands/connection_commands.rb', line 207 def client_unpause send_command(RequestType::CLIENT_UNPAUSE) end |
#echo(value) ⇒ String
Echo the given string.
31 32 33 |
# File 'lib/valkey/commands/connection_commands.rb', line 31 def echo(value) send_command(RequestType::ECHO, [value]) end |
#hello(protover = 3, **options) ⇒ Array
Switch to a different protocol version and handshake with the server.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/valkey/commands/connection_commands.rb', line 67 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) ⇒ String
Ping the server.
23 24 25 |
# File 'lib/valkey/commands/connection_commands.rb', line 23 def ping( = nil) send_command(RequestType::PING, [].compact) 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.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/valkey/commands/connection_commands.rb', line 51 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.
83 84 85 |
# File 'lib/valkey/commands/connection_commands.rb', line 83 def reset send_command(RequestType::RESET) end |
#select(db) ⇒ String
Change the selected database for the current connection.
39 40 41 |
# File 'lib/valkey/commands/connection_commands.rb', line 39 def select(db) send_command(RequestType::SELECT, [db]) end |