1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# frozen_string_literal: true
class Redis
module Commands
module Connection
# Authenticate to the server.
#
# @param [Array<String>] args includes both username and password
# or only password
# @return [String] `OK`
# @see https://redis.io/commands/auth AUTH command
def auth(*args)
send_command([:auth, *args])
end
# Ping the server.
#
# @param [optional, String] message
# @return [String] `PONG`
def ping(message = nil)
send_command([:ping, message].compact)
end
# Echo the given string.
#
# @param [String] value
# @return [String]
def echo(value)
send_command([:echo, value])
end
# Change the selected database for the current connection.
#
# @param [Integer] db zero-based index of the DB to use (0 to 15)
# @return [String] `OK`
def select(db)
send_command([:select, db])
end
# Close the connection.
#
# @return [String] `OK`
def quit
synchronize do |client|
client.call_v([:quit])
rescue ConnectionError
ensure
client.close
end
end
end
end
end
|