Example #1
0
    def test_basic(self):
        h = cont.Hash('hkey')
        self.assertEqual(0, len(h))
        h['name'] = "Richard Cypher"
        h['real_name'] = "Richard Rahl"

        pulled = self.client.hgetall('hkey')
        self.assertEqual(
            {
                'name': "Richard Cypher",
                'real_name': "Richard Rahl"
            }, pulled)

        self.assertEqual(
            {
                'name': "Richard Cypher",
                'real_name': "Richard Rahl"
            }, h.dict)

        self.assertEqual(['name', 'real_name'], list(h.keys()))
        self.assertEqual(["Richard Cypher", "Richard Rahl"], list(h.values()))

        del h['name']
        pulled = self.client.hgetall('hkey')
        self.assertEqual({'real_name': "Richard Rahl"}, pulled)
        self.assert_('real_name' in h)
        h.dict = {"new_hash": "YEY"}
        self.assertEqual({"new_hash": "YEY"}, h.dict)
Example #2
0
 def test_delegateable_methods(self):
     h = cont.Hash('my_hash')
     h.hincrby('Red', 1)
     h.hincrby('Red', 1)
     h.hincrby('Red', 2)
     self.assertEqual(4, int(h.hget('Red')))
     h.hmset({'Blue': 100, 'Green': 19, 'Yellow': 1024})
     self.assertEqual(['100', '19'], h.hmget(['Blue', 'Green']))
def get_auto_id(id_type, id_group="auto_id_hash"):
    auto_id_hash = cont.Hash(id_group)
    auto_id_hash.hincrby(id_type, 1)
    return auto_id_hash.hget(id_type)