lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi, all!

I'm working on bindings for hiredis Redis client library.

Here is the library:

Here is my module: (WARNING:
work in progress.)

I have question about error handling. (Sorry, I have to give some
context first.)

1. In Redis one can do a transaction — atomically execute multiple
commands, using MULTI/EXEC commands.

More info here:

2. If a command inside a transaction fails — all other commands are
still executed.

3. On transport protocol level, MULTI/EXEC transaction results are
transmitted to client as a reply to EXEC command.

4. This reply is in "multibulk" format (REDIS_REPLY_ARRAY) — an array
of arrays (nesting level is not limited).

5. Command execution errors are encoded as a distinct transport
protocol type. In hiredis — REDIS_REPLY_ERR.

More info on hiredis API here:

My question: How to expose command execution errors to Lua code?

See my current prototype implementation here:

Now, whenever I see REDIS_REPLY_ERR redisResponse, I abort everything
and just return nil, error_message.

For multibulk replies it is plain wrong — user does want to see
results of execution of other commands in MULTI/EXEC.

To give some concrete example:

SET a 3


1. OK
2. (error) ERR Operation against a key holding the wrong kind of value
3. (integer) 4

How should this result be returned to Lua?

  -- how to express error message here?

Any hints?


P.S. Note that "OK" is a status reply (REDIS_REPLY_STATUS), not a
string (REDIS_REPLY_STRING). I'd like to separate those two as well,
but this is of much less priority (I think).