[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Error handling strategy for Redis multi-bulk replies, in context of Lua bindings
- From: Alexander Gladysh <agladysh@...>
- Date: Thu, 24 Mar 2011 04:32:07 +0300
I'm working on bindings for hiredis Redis client library.
Here is the library: https://github.com/antirez/hiredis
Here is my module: https://github.com/agladysh/lua-hiredis (WARNING:
work in progress.)
I have question about error handling. (Sorry, I have to give some
1. In Redis one can do a transaction — atomically execute multiple
commands, using MULTI/EXEC commands.
More info here: http://redis.io/topics/transactions
2. If a command inside a transaction fails — all other commands are
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: http://bit.ly/fDE5mc
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
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?
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).