I'm using redis-py and want to use -inf and inf with ZRANGEBYSCORE. I tried to do this using string and float of inf but those return an empty set. How can I do this?
EDIT
I tried doing the following command:
redis.StrictRedis.ZRANGEBYSCORE("SORTEDSET", "-inf", "inf")
or
redis.StrictRedis.ZRANGEBYSCORE("SORTEDSET", float("-inf"), float("inf"))
UPDATE My error was that my abstraction for zrangebyscore was using zrange by mistake...inf works as stated below.
If you want to test redis connection once at startup, use the ping() command. The command ping() checks the connection and if invalid will raise an exception.
This is my code has been tested:
import unittest
from redis import Redis
class RedisTest(unittest.TestCase):
def setUp(self):
self.redis = Redis()
def test_zrangebyscore(self):
r = self.redis
name = 'myset'
r.zadd(name, 'one', 1)
r.zadd(name, 'two', 2)
r.zadd(name, 'three', 3)
r.zadd(name, 'four', 4)
self.assertTrue(r.zrangebyscore(name, '-inf', '+inf') == ['one', 'two', 'three', 'four'])
self.assertTrue(r.zrangebyscore(name, 1, 1) == ['one'])
self.assertTrue(r.zrangebyscore(name, 1, 2) == ['one', 'two'])
self.assertTrue(r.zrangebyscore(name, 2, 3) == ['two', 'three'])
self.assertTrue(r.zrangebyscore(name, '(1', '(2') == [])
self.assertTrue(r.zrangebyscore(name, '(1', '(3') == ['two'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With