def test_load(self): def load(val): return 'foo' accessor = zktx.RedisKeyValue(self.redis_cli, load=load) accessor.set('xx', 'xx') val = accessor.get('xx') self.assertEqual('foo', val)
def test_kv_hget_hset(self): accessor = zktx.RedisKeyValue(self.redis_cli) cases = ( ('h1', 'k1', 1), ('h2', 'k2', {}), ('h3', 'k3', []), ('h4', 'k4', 'foo'), ('h5', 'k5', { "xx": "xx" }), ('h6', 'k6', [1, 2]), ) for h, k, v in cases: accessor.hset(h, k, v) actual = accessor.hget(h, k) self.assertEqual(v, actual)
def test_kv_get_set(self): accessor = zktx.RedisKeyValue(self.redis_cli) cases = ( ('k1', 1), ('k2', {}), ('k3', []), ('k4', 'foo'), ('k5', { "xx": "xx" }), ('k6', [1, 2]), ) for k, v in cases: accessor.set(k, v) actual = accessor.get(k) self.assertEqual(v, actual)
def test_kv_get_path(self): def get_path(k): return 'foo/' + k accessor = zktx.RedisKeyValue(self.redis_cli, get_path=get_path) cases = ( ('k1', 1), ('k2', {}), ('k3', []), ('k4', 'foo'), ('k5', { "xx": "xx" }), ('k6', [1, 2]), ) for k, v in cases: accessor.set(k, v) actual = self.redis_cli.get(get_path(k)) self.assertEqual(v, utfjson.load(actual))