Redis Client Connection
Jedis.Client — TypeClient([; 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]) -> ClientCreates 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: Settrueto try and reconnect when client socket status is closed, defaults totrue.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: Settrueto enable TCP keep-alive.keepalive_delay::Int=60: Initial delay in seconds, defaults to 60s, ignored whenkeepalive_enableisfalse. 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,usernamewill 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)
1SSL/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);Jedis.get_ssl_config — Functionget_ssl_config([; ssl_certfile=nothing, ssl_keyfile=nothing, ssl_ca_certs=nothing]) -> MbedTLS.SSLConfigLoads 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");Jedis.ssl_connect — Functionssl_connect(host::AbstractString, port::Integer, ssl_config::MbedTLS.SSLConfig) -> MbedTLS.SSLContextConnects to the redis host and port, returns a socket connection with ssl context.
Jedis.execute — Methodexecute(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"Jedis.GLOBAL_CLIENT — ConstantGLOBAL_CLIENT = Ref{Client}()Reference to a global Client object.
Jedis.set_global_client — Functionset_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.
Jedis.get_global_client — Functionget_global_client() -> ClientRetrieves the GLOBAL_CLIENT[] instance, if unassigned then initialises it with default values host="127.0.0.1", port=6379, database=0, password="", username="".
Base.copy — Functioncopy(client::Client) -> ClientCreates a new Client instance, copying the connection parameters of the input.
Jedis.isclosed — Functionisclosed(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.
Jedis.disconnect! — Functiondisconnect!(client::Client)Closes the client socket connection, it will be rendered unusable.
Jedis.reconnect! — Functionreconnect!(client::Client) -> ClientReconnects the input client socket connection.
Jedis.wait_until_subscribed — Functionwait_until_subscribed(client::Client)Blocks until client changes to a subscribed state.
Jedis.wait_until_unsubscribed — Functionwait_until_unsubscribed(client::Client)Blocks until client changes to a unsubscribed state.
Jedis.wait_until_channel_unsubscribed — Functionwait_until_channel_unsubscribed(client::Client[, channels...])Blocks until client is unsubscribed from channel(s), leave empty to wait until unsubscribed from all channels.
Jedis.wait_until_pattern_unsubscribed — Functionwait_until_pattern_unsubscribed(client::Client[, patterns...])Blocks until client is unsubscribed from pattern(s), leave empty to wait until unsubscribed from all patterns.