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

Instance Method Details

#auth(*args) ⇒ String

Authenticate to the server.

Parameters:

  • args (Array<String>)

    includes both username and password or only password

Returns:

  • (String)

    ‘OK`



15
16
17
# File 'lib/valkey/commands/connection_commands.rb', line 15

def auth(*args)
  send_command(RequestType::AUTH, args)
end

#echo(value) ⇒ String

Echo the given string.

Parameters:

  • value (String)

Returns:

  • (String)


31
32
33
# File 'lib/valkey/commands/connection_commands.rb', line 31

def echo(value)
  send_command(RequestType::ECHO, [value])
end

#ping(message = nil) ⇒ String

Ping the server.

Parameters:

  • message (optional, String) (defaults to: nil)

Returns:

  • (String)

    ‘PONG`



23
24
25
# File 'lib/valkey/commands/connection_commands.rb', line 23

def ping(message = nil)
  send_command(RequestType::PING, [message].compact)
end

#quitString

Close the connection.

Returns:

  • (String)

    ‘OK`



46
47
48
49
50
51
52
53
54
# File 'lib/valkey/commands/connection_commands.rb', line 46

def quit
  # TODO: Implement a proper quit command
  # synchronize do |client|
  #   client.call_v([:quit])
  # rescue ConnectionError
  # ensure
  #   client.close
  # end
end

#select(db) ⇒ String

Change the selected database for the current connection.

Parameters:

  • db (Integer)

    zero-based index of the DB to use (0 to 15)

Returns:

  • (String)

    ‘OK`



39
40
41
# File 'lib/valkey/commands/connection_commands.rb', line 39

def select(db)
  send_command(RequestType::SELECT, [db])
end