See the copyright information in the file named COPYRIGHT
.
-
hiredis.connect(host : string, port : number) : conn / nil, err, error_code
-
hiredis.unwrap_reply(reply) : reply / name, hiredis.REPLY_STATUS / nil, err
- If
reply
is ahiredis.REPLY_ERROR
object, returnsnil, reply.name
. - If
reply
is ahiredis.REPLY_STATUS
object, returnsreply.name, hiredis.REPLY_STATUS
(It is guaranteed thatreply.name
is notnil
orfalse
.) - Returns
reply
itself otherwise (note thathiredis.REPLY_NIL
object 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_IO
ishiredis.ERR_IO
,REDIS_ERR_EOF
ishiredis.ERR_EOF
,REDIS_ERR_PROTOCOL
ishiredis.ERR_PROTOCOL
,REDIS_ERR_OTHER
ishiredis.ERR_OTHER
.
-
REDIS_REPLY_STATUS
is a const-object (see below) with typehiredis.REPLY_STATUS
. Common status objects are available in hiredis module table:hiredis.OK
hiredis.QUEUED
hiredis.PONG
It is guaranteed that these object instances are always used for their corresponding statuses (so you can make a simple equality check).
-
REDIS_REPLY_ERROR
is a const-object with typehiredis.REPLY_ERROR
. Note that Redis server errors are returned asREDIS_REPLY_ERROR
values, not asnil, err, error_code
triplet. See tests for example. -
REDIS_REPLY_INTEGER
is a Lua number. -
REDIS_REPLY_NIL
is a const-object with typehiredis.REPLY_NIL
. -
REDIS_REPLY_STRING
is a binary-safe Lua string. -
REDIS_REPLY_ARRAY
is 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_ERROR
hiredis.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.
Read test/test.lua
for examples. Read hiredis README for API motivation.