Skip to content

Instantly share code, notes, and snippets.

@swapab
Last active December 31, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swapab/7943621 to your computer and use it in GitHub Desktop.
Save swapab/7943621 to your computer and use it in GitHub Desktop.
zrangebyscore
# Test Dataset
2.0.0p195 :071 > t10
=> 1386935151
2.0.0p195 :072 > t20
=> 1386934568
2.0.0p195 :073 > t30
=> 1386933971
2.0.0p195 :074 > t40
=> 1386933374
# Redis Sorted Set
2.0.0p195 :075 > redis.zadd 'T_KEY', t10, 'time-10-ago'
=> true
2.0.0p195 :076 > redis.zadd 'T_KEY', t20, 'time-20-ago'
=> true
2.0.0p195 :077 > redis.zadd 'T_KEY', t30, 'time-30-ago'
=> true
2.0.0p195 :078 > redis.zadd 'T_KEY', t40, 'time-40-ago'
=> true
2.0.0p195 :079 > redis.zrangebyscore('T_KEY', 1386933900, 1386936000)
=> ["time-30-ago", "time-20-ago", "time-10-ago"]
#Total count using LUA script and Range By Score
redis.eval("return #redis.call('zrangebyscore', 'T_KEY', 1386933000, 1386936000)")
=> 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment