redis — lilu API

←index

Overview

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.

Functions

NameSignature
client:cmdclient:cmd(...) -> result, err
client:readclient:read() -> response, err
client:closeclient:close(no_keepalive) -> ok
connectconnect(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:

Pool size is controlled by the REDIS_CLIENT_SOCKET_POOL_SIZE environment variable (default: 20).