How to get multiple values via SORT BY NOSORT in lua?

301 views
Skip to first unread message

Duraz

unread,
Mar 5, 2014, 12:38:45 AM3/5/14
to redi...@googlegroups.com

We have several SETs containing KEYS in the form of:

    x:123456789:t
    
    (t values are stringified JSON texts like {"k":"v", "k":"v""k":"v"…})

We intersect 3+ of these SETs with

    local c1 = redis.call('SINTERSTORE', sTemp, unpack(KEYS))
    
Now we'd like to get the t text-values associated with the KEYS in the resulting SET setTemp with
 
 SORT sTemp BY NOSORT GET *:t
    
which gives us something like this via redis-cli

{"k":"v", "k":"v", "k":"v"…}
{"k":"v", "k":"v", "k":"v"…}
{"k":"v", "k":"v", "k":"v"…}…
    
Now how does one represent SORT sTemp BY NOSORT GET *:t in lua?

These random tries give the obvious errors:

c1 = redis.call('SINTERSTORE', sTemp, unpack(KEYS))

1. local c2 = redis.call('SORT sTemp by nosort get *:t') => sTemp is not a local variable

2. local sTemp
    local c2 = redis.call('SORT sTemp by nosort get *:t') => [Error: Unknown Redis command called from Lua script]

3. local c2 = redis.call('SORT', sTemp, 'by nosort get *:t') => [Error: Lua redis() command arguments must be strings or integers]

I don't know if looping through sTemp set with ID KEYS and doing a GET on each would be less performant than SORT in one operation, but I'd like to know if it can be done in lua.

Thanks.

Josiah Carlson

unread,
Mar 5, 2014, 1:02:32 PM3/5/14
to redi...@googlegroups.com
You need to separate all of your arguments into pieces in order to get the Redis call to work.

redis.call('SORT', sTemp, 'by', 'nosort', 'get', '*:t')

 - Josiah


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages