Ini adalah kode saya telah diuji:
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'])