Skip to content

Instantly share code, notes, and snippets.

@gerhard
Created July 4, 2012 10:17
Show Gist options
  • Select an option

  • Save gerhard/3046550 to your computer and use it in GitHub Desktop.

Select an option

Save gerhard/3046550 to your computer and use it in GitHub Desktop.
redis zrevrange different results. Running v2.4.8
redis 127.0.0.1:6379> zrevrange foo 0 -1
1) "1570995626"
redis 127.0.0.1:6379> zrevrange foo 0 -1 WITHSCORES
1) "1570995626"
2) "1341396994"
# Why am I getting different results?
@TheDeveloper

Copy link
Copy Markdown

zrevrange WITHSCORES prints the member's score after the key in the response. Without WITHSCORES, only the member is printed.

@gerhard

gerhard commented Jul 4, 2012

Copy link
Copy Markdown
Author

Right, but shouldn't there be 2 members in both cases?

@TheDeveloper

Copy link
Copy Markdown

No, because in the second command, the 2) entry is the score, because you ran it with WITHSCORES. In the first command, it only returned the member, because there was no WITHSCORES

@gerhard

gerhard commented Jul 4, 2012

Copy link
Copy Markdown
Author

OK, got it:

redis> ZREVRANGE myzset 0 -1
1) "three"
2) "two"
3) "one"
redis> ZREVRANGE myzset 0 -1 WITHSCORES
1) "three"
2) "3"
3) "two"
4) "2"
5) "one"
6) "1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment