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 ⇒ 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 ⇒ 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
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.
96 97 98 |
# File 'lib/valkey/commands/connection_commands.rb', line 96 def client(subcommand, *args) public_send("client_#{subcommand.to_s.downcase}", *args) 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_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.
150 151 152 |
# File 'lib/valkey/commands/connection_commands.rb', line 150 def client_info send_command(RequestType::CLIENT_INFO) end |
#client_kill(addr = nil, **options) ⇒ Integer
Kill client connections.
159 160 161 162 163 164 165 |
# File 'lib/valkey/commands/connection_commands.rb', line 159 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).
171 172 173 |
# File 'lib/valkey/commands/connection_commands.rb', line 171 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 144 145 |
# 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| 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.
283 284 285 |
# File 'lib/valkey/commands/connection_commands.rb', line 283 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.
291 292 293 |
# File 'lib/valkey/commands/connection_commands.rb', line 291 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.
200 201 202 203 204 |
# File 'lib/valkey/commands/connection_commands.rb', line 200 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.
217 218 219 |
# File 'lib/valkey/commands/connection_commands.rb', line 217 def client_reply(mode) send_command(RequestType::CLIENT_REPLY, [mode]) end |
#client_set_info(attr, value) ⇒ String
Set client connection information.
237 238 239 |
# File 'lib/valkey/commands/connection_commands.rb', line 237 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_unblock(client_id, unblock_type = nil) ⇒ Integer
Unblock a client blocked in a blocking operation.
226 227 228 229 230 |
# File 'lib/valkey/commands/connection_commands.rb', line 226 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.
209 210 211 |
# File 'lib/valkey/commands/connection_commands.rb', line 209 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 |