Redis client with RESP protocol support, connection pooling, optional
TLS, and authentication. Returns client objects with a generic cmd
method that accepts any Redis command as variadic arguments.
| Name | Signature |
|---|---|
client:cmd | client:cmd(...) -> result, err |
client:read | client:read() -> response, err |
client:close | client:close(no_keepalive) -> ok |
connect | connect(config) -> client, err |
client:cmd(
...) ->result,err
Execute a Redis command and return the parsed response
Sends an arbitrary Redis command and reads the RESP response. Arguments are encoded as RESP bulk strings. Returns the parsed response value on success, or nil and an error string on failure.
local val, err = client:cmd("GET", "mykey")
local ok, err = client:cmd("SET", "mykey", "hello")
local list = client:cmd("LRANGE", "queue", 0, -1)
client:read() ->
response,err
Read a raw RESP response from the connection
Low-level response reader that returns the raw RESP response table
with type and value fields. Useful for pipelining or pub/sub
scenarios where responses arrive asynchronously.
client:close(
no_keepalive) ->ok
Close the Redis connection
Closes the connection. By default the underlying socket is returned
to the connection pool for reuse. Pass no_keepalive = true to
force-close the socket instead of pooling it. The socket is also
force-closed when the pool exceeds its size limit.
connect(
config) ->client,err
Connect to a Redis server
Establishes a connection to a Redis server, returning a client object. Reuses pooled connections when available (validated with PING).
config can be:
nil — connects to 127.0.0.1:6379
string — parsed as "host:port" or "host:port/db"
table with fields:
host — server hostname (required)
port — server port, default 6379
db — database index
timeout — connection timeout in seconds
ssl — enable TLS
auth — {user=..., pass=...} for AUTH
Pool size is controlled by the REDIS_CLIENT_SOCKET_POOL_SIZE
environment variable (default: 20).