Example #1
0
    def test_get_key(self):
        h = db.Hash('h1')
        h['hk1'] = 'v1'

        l = db.List('l1')
        l.append('i1')

        s = db.Set('s1')
        s.add('k1')

        zs = db.ZSet('z1')
        zs.add({'i1': 1., 'i2': 2.})

        h_db = db.get_key('h1')
        self.assertTrue(isinstance(h_db, Hash))
        self.assertEqual(h_db['hk1'], b'v1')

        l_db = db.get_key('l1')
        self.assertTrue(isinstance(l_db, List))
        self.assertEqual(l_db[0], b'i1')

        s_db = db.get_key('s1')
        self.assertTrue(isinstance(s_db, Set))
        self.assertEqual(s_db.members(), set((b'k1', )))

        z_db = db.get_key('z1')
        self.assertTrue(isinstance(z_db, ZSet))
        self.assertEqual(z_db.score('i1'), 1.)
Example #2
0
    def test_combine_store(self):
        zs2 = db.ZSet('my-zset2')
        self.zs.add(1, 1, 2, 2, 3, 3)
        zs2.add(3, 3, 4, 4, 5, 5)

        zs3 = self.zs.unionstore('my-zset3', zs2)
        self.assertEqual(list(zs3), [(b'1', 1.), (b'2', 2.), (b'4', 4.),
                                     (b'5', 5.), (b'3', 6.)])

        zs3 = self.zs.interstore('my-zset3', zs2)
        self.assertEqual(list(zs3), [(b'3', 6.)])

        self.zs |= zs2
        self.assertZSet([(b'1', 1.), (b'2', 2.), (b'4', 4.), (b'5', 5.),
                         (b'3', 6.)])

        zs3 &= zs2
        self.assertEqual(list(zs3), [(b'3', 9.)])
Example #3
0
 def test_as_items(self):
     self.zs.add('foo', 3, 'bar', 1, 'baz', 2)
     self.assertEqual(self.zs.as_items(True), [('bar', 1.), ('baz', 2.),
                                               ('foo', 3.)])
     self.assertEqual(db.ZSet('test').as_items(), [])
Example #4
0
 def setUp(self):
     super(TestZSet, self).setUp()
     self.zs = db.ZSet('my-zset')