LUA Script returning key and value?

417 views
Skip to first unread message

Kevin Burton

unread,
Mar 3, 2015, 3:43:51 PM3/3/15
to redi...@googlegroups.com
I have the following script (hopefully to return a key AND a value):

var script = @"
local t = {}
for k,v in ipairs(KEYS) do
    if redis.call('exists', v) == 1 then
        t[v] = redis.call('get', v)
    end
end
return t
";

I am using StackExchange.Redis so I am evaluating the return like:

            foreach(RedisResult result in (RedisResult[])cache.ScriptEvaluate(script, newkeys)) {

I see that I can cast the RedisResult to a RedisKey or RedisValue but there doesn't seem to be a way to access both. So my question is twofold. One, can I expect the script to return a key and value? Two, Should I expect an array of RedisResult like I have shown above? If so how do I get the key and value? Ideas?

Thank you.

Kevin Burton

unread,
Mar 5, 2015, 10:26:35 AM3/5/15
to redi...@googlegroups.com
As a corollary, the return from a command like MGET is a list of values. Can I assume that the list returned has a one-to-one correspondence to the list passed at all times? For example can I always be assured that MGET a b c returning 1) 1 2) 2 3) 3 that the key 'a' has a value of '1' etc?

Josiah Carlson

unread,
Mar 6, 2015, 12:24:40 PM3/6/15
to redi...@googlegroups.com
I don't have an answer for the first part of your question regarding StackExchange Redis, but on the MGET side of things: yes, you *can* expect that the returned results are in the exact same order as the keys that you put in. Anything else would be a insanely broken API.

 - 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/d/optout.

Reply all
Reply to author
Forward
0 new messages