See the copyright information in the file named COPYRIGHT.
The lua-hiredis module is pretty stable. It is heavily used in production under high load by the author and team. There are still some things to do (see TODO file) in the feature completeness field, this is why the module is not 1.0 yet. But all the features necessary for regular usage are here.
-
hiredis.connect(host / socket : string, port : number / nil) : conn / nil, err, error_codehiredis.connect("localhost", 6379)connects to Redis atlocalhost:6379via TCP/IP socket.hiredis.connect("/var/run/redis/redis.sock")connects to Redis at/var/run/redis/redis.sockvia Unix domain socket.
-
hiredis.unwrap_reply(reply) : reply / name, hiredis.REPLY_STATUS / nil, err- If
replyis ahiredis.REPLY_ERRORobject, returnsnil, reply.name. - If
replyis ahiredis.REPLY_STATUSobject, returnsreply.name, hiredis.REPLY_STATUS(It is guaranteed thatreply.nameis notnilorfalse.) - Returns
replyitself otherwise (note thathiredis.REPLY_NILobject is not unwrapped).
- If
-
conn:command(... : string) : reply / nil, err, error_code -
conn:append_command(... : string) : (nothing) -
conn:get_reply() : reply / nil, err, error_code -
conn:close() : (nothing)
Hiredis error codes (see docs), also available as hiredis.ERR_<something>:
REDIS_ERR_IOishiredis.ERR_IO,REDIS_ERR_EOFishiredis.ERR_EOF,REDIS_ERR_PROTOCOLishiredis.ERR_PROTOCOL,REDIS_ERR_OTHERishiredis.ERR_OTHER.
-
REDIS_REPLY_STATUSis a const-object (see below) with typehiredis.REPLY_STATUS. Common status objects are available in hiredis module table:hiredis.status.OKhiredis.status.QUEUEDhiredis.status.PONG
It is guaranteed that these object instances are always used for their corresponding statuses (so you can make a simple equality check). The same is true for any other object in
hiredis.statustable.Examples:
assert(conn:command("PING") == hiredis.status.PONG) assert(conn:command("SET", "NAME", "lua-hiredis") == hiredis.status.OK) assert(conn:command("TYPE", "NAME") == hiredis.status.string) -
REDIS_REPLY_ERRORis a const-object with typehiredis.REPLY_ERROR. Note that Redis server errors are returned asREDIS_REPLY_ERRORvalues, not asnil, err, error_codetriplet. See tests for example. -
REDIS_REPLY_INTEGERis a Lua number. -
REDIS_REPLY_NILis a const-object with typehiredis.REPLY_NIL. -
REDIS_REPLY_STRINGis a binary-safe Lua string. -
REDIS_REPLY_ARRAYis a linear Lua table (nesting is supported).
Const-object is a table with fields name and type.
There are three types of const-objects:
hiredis.REPLY_NIL(only a single instance is ever used:hiredis.NIL)hiredis.REPLY_ERRORhiredis.REPLY_STATUS
Use hiredis.unwrap_reply() to convert const-object to regular Lua value.
Note: Unwrapping is not done automatically to make array reply handling more straightforward.
For backwards compatibility following status const-objects are aliased
in the hiredis module table:
hiredis.OK = hiredis.status.OKhiredis.QUEUED = hiredis.status.QUEUEDhiredis.PONG = hiredis.status.PONG
These aliases will eventually be removed in one of future releases,
so, please, update your code to use hiredis.status.* instead.
Read test/test.lua for examples. Read hiredis README for API motivation.