lua-users home
lua-l archive

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


On Thu, Mar 24, 2011 at 17:09, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
> 2011/3/24 Alexander Gladysh <agladysh@gmail.com>:

>> 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.)

>> To give some concrete example:
>>
>> MULTI
>> SET a 3
>> LPOP a
>> INCR a
>> EXEC
>>
>> Returns:
>>
>> 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?
>>
>> {
>>  "OK",
>>  -- how to express error message here?
>>  4
>> }
>>
>> Any hints?

> How do you call the functions ? Assuming you have Lua calls mapping
> directly to redis wire requests, maybe you can return some opaque
> mutable object, that will be updated by the exec call, like :

> multi()
> local res1 = set('a', 3)
> local res2 = lpop('a')
> local res3 = incr('a')
> -- using resx before calling exec would throw an error
> exec()

> print(res1.status, res1.value)
> print(res2.status, res2.value)
> print(res3.status, res3.value)

I just bind hiredis redisCommandArgv function directly. All higher
level stuff (like actual command names and argument validation) is
outside of the scope of this particular module. (I do want to write a
convenience high level Lua wrapper module later, but that is another
story.)

I would like to avoid creating an userdata per request, as I feel that
it would be too much overhead in both speed and code complexity
(complexity being the main reason here). So, unless there is some
clever way to do what you suggest that I do not see, I guess, I have
to stick to returning all data from exec() call.

Alexander.