Exemple #1
0
 async def test_zrange(self):
     key = self.randomkey()
     eq = self.assertEqual
     c = self.client
     eq(await c.zadd(key, a1=1, a2=2, a3=3), 3)
     eq(await c.zrange(key, 0, 1), [b'a1', b'a2'])
     eq(await c.zrange(key, 1, 2), [b'a2', b'a3'])
     eq(await c.zrange(key, 0, 1, withscores=True),
        Zset([(1, b'a1'), (2, b'a2')]))
     eq(await c.zrange(key, 1, 2, withscores=True),
        Zset([(2, b'a2'), (3, b'a3')]))
Exemple #2
0
 async def test_zrangebyscore(self):
     key = self.randomkey()
     eq = self.assertEqual
     c = self.client
     eq(await c.zadd(key, a1=1, a2=2, a3=3, a4=4, a5=5), 5)
     eq(await c.zrangebyscore(key, 2, 4), [b'a2', b'a3', b'a4'])
     # slicing with start/num
     eq(await c.zrangebyscore(key, 2, 4, offset=1, count=2), [b'a3', b'a4'])
     # withscores
     eq(await c.zrangebyscore(key, 2, 4, withscores=True),
        Zset([(2.0, b'a2'), (3.0, b'a3'), (4.0, b'a4')]))
Exemple #3
0
 async def test_zinterstore_sum(self):
     des = self.randomkey()
     key1 = des + '1'
     key2 = des + '2'
     key3 = des + '3'
     eq = self.assertEqual
     c = self.client
     eq(await c.zadd(key1, a1=1, a2=2, a3=1), 3)
     eq(await c.zadd(key2, a1=2, a2=2, a3=2), 3)
     eq(await c.zadd(key3, a1=6, a3=5, a4=4), 3)
     eq(await c.zinterstore(des, (key1, key2, key3)), 2)
     eq(await c.zrange(des, 0, -1, withscores=True),
        Zset(((8.0, b'a3'), (9.0, b'a1'))))
Exemple #4
0
 def test_zinterstore_with_weights(self):
     des = self.randomkey()
     key1 = des + '1'
     key2 = des + '2'
     key3 = des + '3'
     eq = self. async .assertEqual
     c = self.client
     yield eq(c.zadd(key1, a1=1, a2=2, a3=1), 3)
     yield eq(c.zadd(key2, a1=2, a2=2, a3=2), 3)
     yield eq(c.zadd(key3, a1=6, a3=5, a4=4), 3)
     yield eq(c.zinterstore(des, (key1, key2, key3), weights=(1, 2, 3)), 2)
     yield eq(c.zrange(des, 0, -1, withscores=True),
              Zset(((20.0, b'a3'), (23.0, b'a1'))))
Exemple #5
0
 def test_zinterstore_min(self):
     des = self.randomkey()
     key1 = des + '1'
     key2 = des + '2'
     key3 = des + '3'
     eq = self. async .assertEqual
     c = self.client
     yield eq(c.zadd(key1, a1=1, a2=2, a3=1), 3)
     yield eq(c.zadd(key2, a1=2, a2=2, a3=2), 3)
     yield eq(c.zadd(key3, a1=6, a3=5, a4=4), 3)
     yield eq(c.zinterstore(des, (key1, key2, key3), aggregate='min'), 2)
     yield eq(c.zrange(des, 0, -1, withscores=True),
              Zset(((1.0, b'a3'), (1.0, b'a1'))))
Exemple #6
0
def values_to_zset(response, withscores=False, **kw):
    if withscores:
        it = iter(response)
        return Zset(((float(score), value) for value, score in zip(it, it)))
    else:
        return response