Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
vicmargar  
View profile  
 More options Apr 27 2012, 9:50 pm
From: vicmargar <vicmar...@gmail.com>
Date: Fri, 27 Apr 2012 18:50:24 -0700 (PDT)
Local: Fri, Apr 27 2012 9:50 pm
Subject: Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6
Hello, I've been trying to implement a use case for Redis sorted sets
using Lua scripting in Redis 2.6 and after a lot of time without being
able to make it work I've managed to reproduce my problem in a simple
scenario. I'm still not sure if I'm doing something wrong but
basically I can't get ZUNIONSTORE to work if i'm using unpack and
'AGGREGATE' 'MIN' at the same time:

redis 127.0.0.1:6379> zadd set1 1 key1
(integer) 1
redis 127.0.0.1:6379> zadd set1 1 key2
(integer) 1
redis 127.0.0.1:6379> zadd set2 2 key1
(integer) 1
redis 127.0.0.1:6379> zadd set2 1 key3
(integer) 1
redis 127.0.0.1:6379> eval "return redis.call('zunionstore', 'tmp', 3,
unpack(KEYS))" 3 set1 set2 set3
(integer) 3
redis 127.0.0.1:6379> zrange tmp 0 -1 WITHSCORES
1) "key2"
2) "1"
3) "key3"
4) "1"
5) "key1"
6) "3"
redis 127.0.0.1:6379> eval "return redis.call('zunionstore', 'tmp', 3,
unpack(KEYS), 'AGGREGATE', 'MIN')" 3 set1 set2 set3
(integer) 2
redis 127.0.0.1:6379> zrange tmp 0 -1 WITHSCORES
1) "key1"
2) "1"
3) "key2"
4) "1"
redis 127.0.0.1:6379> eval "return redis.call('zunionstore', 'tmp', 3,
'set1', 'set2', 'set3', 'AGGREGATE', 'MIN')" 0
(integer) 3
redis 127.0.0.1:6379> zrange tmp 0 -1 WITHSCORES
1) "key1"
2) "1"
3) "key2"
4) "1"
5) "key3"
6) "1"

Thank you for your help!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ziyan Zhou  
View profile  
 More options Jul 22 2012, 7:14 pm
From: Ziyan Zhou <ziyan....@gmail.com>
Date: Sun, 22 Jul 2012 16:14:46 -0700 (PDT)
Local: Sun, Jul 22 2012 7:14 pm
Subject: Re: Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6

Just ran into this issue too.

Your problem lies in upack(KEYS).

Your "return redis.call('zunionstore', 'tmp', 3, unpack(KEYS), 'AGGREGATE',
'MIN')" is actually equivalent to "return redis.call('zunionstore', 'tmp',
3, KEYS[1], 'AGGREGATE', 'MIN')"

In general if you do
local a = {100, 200, 300}

{1, unpack(a), 2} will give you {1, 100, 2}

My solution:

local args = {'zunionstore', 'tmp', 3, unpack(KEYS)}
args[#args + 1] = 'AGGREGATE'
args[#args + 1] = 'MIN'
redis.call(unpack(args))

I am not sure why lua is so retarded.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Javier Guerra Giraldez  
View profile  
 More options Jul 23 2012, 10:20 am
From: Javier Guerra Giraldez <jav...@guerrag.com>
Date: Mon, 23 Jul 2012 09:20:46 -0500
Local: Mon, Jul 23 2012 10:20 am
Subject: Re: Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6

On Sun, Jul 22, 2012 at 6:14 PM, Ziyan Zhou <ziyan....@gmail.com> wrote:
> I am not sure why lua is so retarded.

to keep consistency to the arguments list.

the (fixed) 'AGGREGATE' and 'MIN' arguments are guaranteed to stay at
the same position, that is fifth and sixth.

multiple-returns are only allowed to expand fully at the end of an
argument list, so that subsequent arguments are not pushed around
unpredictably

--
Javier


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ziyan Zhou  
View profile   Translate to Translated (View Original)
 More options Jul 24 2012, 4:57 pm
From: Ziyan Zhou <ziyan....@gmail.com>
Date: Tue, 24 Jul 2012 13:57:52 -0700 (PDT)
Local: Tues, Jul 24 2012 4:57 pm
Subject: Re: Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6

Problem is there is no clear indication of what went wrong, it is hard to
debug especially in vicmargar's case where the number of arguments stayed
the same. His bug caused strange outcome, yet there is nothing to indicate
an error, just hard to debug in general.

Also the code can be changed to:

local args = {'zunionstore', 'tmp', #KEYS, unpack(KEYS)}
args[#args + 1] = 'AGGREGATE'
args[#args + 1] = 'MIN'
redis.call(unpack(args))

To accommodate any number of KEYS, so 'AGGREGATE' and 'MIN' are not
guaranteed to stay at 5th or 6th, instead, they are guaranteed to stay at
the end.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Javier Guerra Giraldez  
View profile  
 More options Jul 24 2012, 5:07 pm
From: Javier Guerra Giraldez <jav...@guerrag.com>
Date: Tue, 24 Jul 2012 16:07:36 -0500
Local: Tues, Jul 24 2012 5:07 pm
Subject: Re: Error in Lua script (ZUNIONSTORE + unpack(KEYS) + AGGREGATE MIN) - Redis 2.6

On Tue, Jul 24, 2012 at 3:57 PM, Ziyan Zhou <ziyan....@gmail.com> wrote:
> Also the code can be changed to:

> local args = {'zunionstore', 'tmp', #KEYS, unpack(KEYS)}
> args[#args + 1] = 'AGGREGATE'
> args[#args + 1] = 'MIN'
> redis.call(unpack(args))

sure, that's the way to do it

> To accommodate any number of KEYS, so 'AGGREGATE' and 'MIN' are not
> guaranteed to stay at 5th or 6th, instead, they are guaranteed to stay at
> the end.

this is appropriate for a command line, or a data description language
(like Redis commands); but for a programming language, functions tend
to pick arguments at fixed positions in the arguments list, and that's
why Lua is designed like this.

--
Javier


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »