Redis Client Connection

Jedis.ClientType
Client([; host="127.0.0.1", port=6379, database=0, password="", username="", ssl_config=nothing, retry_when_closed=true, retry_max_attemps=1, retry_backoff=(x) -> 2^x, keepalive_enable=false, keepalive_delay=60]) -> Client

Creates a Client instance connecting and authenticating to a Redis host, provide an MbedTLS.SSLConfig (see get_ssl_config) for a secured Redis connection (SSL/TLS).

Fields

  • host::AbstractString: Redis host.
  • port::Integer: Redis port.
  • database::Integer: Redis database index.
  • password::AbstractString: Redis password if any.
  • username::AbstractString: Redis username if any.
  • socket::Union{TCPSocket,MbedTLS.SSLContext}: Socket used for sending and reveiving from Redis host.
  • lock::Base.AbstractLock: Lock for atomic reads and writes from client socket.
  • ssl_config::Union{MbedTLS.SSLConfig,Nothing}: Optional ssl config for secured redis connection.
  • is_subscribed::Bool: Whether this Client is actively subscribed to any channels or patterns.
  • subscriptions::AbstractSet{<:AbstractString}: Set of channels currently subscribed on.
  • psubscriptions::AbstractSet{<:AbstractString}: Set of patterns currently psubscribed on.
  • retry_when_closed::Bool: Set true to try and reconnect when client socket status is closed, defaults to true.
  • retry_max_attempts::Int: Maximum number of retries for reconnection, defaults to1`.
  • retry_backoff::Function: Retry backoff function, called after each retry and must return a single number, where that number is the sleep time (in seconds) until the next retry, accepts a single argument, the number of retries attempted.
  • keepalive_enable::Bool=false: Set true to enable TCP keep-alive.
  • keepalive_delay::Int=60: Initial delay in seconds, defaults to 60s, ignored when keepalive_enable is false. After delay has been reached, 10 successive probes, each spaced 1 second from the previous one, will still happen. If the connection is still lost at the end of this procedure, then the handle is destroyed with a UV_ETIMEDOUT error passed to the corresponding callback.

Note

  • Connection parameters host, port, database, password, username will not change after

client istance is constructed, even with SELECT or CONFIG SET commands.

Examples

Basic connection:

julia> client = Client();

julia> set("key", "value"; client=client)
"OK"

julia> get("key"; client=client)
"value"

julia> execute(["DEL", "key"], client)
1

SSL/TLS connection:

julia> ssl_config = get_ssl_config(ssl_certfile="redis.crt", ssl_keyfile="redis.key", ssl_ca_certs="ca.crt");

julia> client = Client(ssl_config=ssl_config);
source
Jedis.get_ssl_configFunction
get_ssl_config([; ssl_certfile=nothing, ssl_keyfile=nothing, ssl_ca_certs=nothing]) -> MbedTLS.SSLConfig

Loads ssl cert, key and ca cert files from provided directories into MbedTLS.SSLConfig object.

Examples

julia> ssl_config = get_ssl_config(ssl_certfile="redis.crt", ssl_keyfile="redis.key", ssl_ca_certs="ca.crt");
source
Jedis.ssl_connectFunction
ssl_connect(host::AbstractString, port::Integer, ssl_config::MbedTLS.SSLConfig) -> MbedTLS.SSLContext

Connects to the redis host and port, returns a socket connection with ssl context.

source
Jedis.executeMethod
execute(command[; client::Client=get_global_client()])

Sends a RESP compliant command to the Redis host and returns the result. The command is either an array of command keywords, or a single command string. Defaults to using the globally set Client.

Examples

julia> execute(["SET", "key", "value"])
"OK"
julia> execute("GET key")
"value"
source
Jedis.set_global_clientFunction
set_global_client(client::Client)
set_global_client([; host="127.0.0.1", port=6379, database=0, password="", username="", ssl_config=nothing, retry_when_closed=true, retry_max_attemps=1, retry_backoff=(x) -> 2^x, keepalive_enable=false, keepalive_delay=60])

Sets a Client object as the GLOBAL_CLIENT[] instance.

source
Jedis.get_global_clientFunction
get_global_client() -> Client

Retrieves the GLOBAL_CLIENT[] instance, if unassigned then initialises it with default values host="127.0.0.1", port=6379, database=0, password="", username="".

source
Base.copyFunction
copy(client::Client) -> Client

Creates a new Client instance, copying the connection parameters of the input.

source
Jedis.isclosedFunction
isclosed(client::Client)

Returns true if client socket status is Base.StatusClosing, Base.StatusClosed or Base.StatusOpen, false otherwise. It turns out when status is Base.StatusOpen the socket is already unusable. Base.StatusPaused is the true ready state.

source
Jedis.disconnect!Function
disconnect!(client::Client)

Closes the client socket connection, it will be rendered unusable.

source
Jedis.reconnect!Function
reconnect!(client::Client) -> Client

Reconnects the input client socket connection.

source
Jedis.wait_until_channel_unsubscribedFunction
wait_until_channel_unsubscribed(client::Client[, channels...])

Blocks until client is unsubscribed from channel(s), leave empty to wait until unsubscribed from all channels.

source
Jedis.wait_until_pattern_unsubscribedFunction
wait_until_pattern_unsubscribed(client::Client[, patterns...])

Blocks until client is unsubscribed from pattern(s), leave empty to wait until unsubscribed from all patterns.

source