def test_compress(self): client = Client(['127.0.0.1:11211']) key = uuid.uuid4().hex yield client.add(key, '111111111111', 5, min_compress_len=1) res = yield client.get(key) self.assertEqual(res, '111111111111') yield client.replace(key, '222222222', 5, min_compress_len=1) res1 = yield client.get(key) self.assertEqual(res1, '222222222') key2 = uuid.uuid4().hex val2 = { 'foo': 'bar', 'test': 'test', 'ls': [1, 2, 3], 'd': { 'foo': 1, 'bar': 'test' } } yield client.set(key2, val2, 5, min_compress_len=1) res2 = yield client.get(key2) self.assertEqual(res2, val2) yield client.set_multi({ 'foo': 'foo', 'bar': 'bar' }, 5, key_prefix='tc_', min_compress_len=1) res3 = yield client.get_multi(['foo', 'bar'], key_prefix='tc_') self.assertEqual(res3, {'foo': 'foo', 'bar': 'bar'})
def test_multi_cmd(self): key = uuid.uuid4().hex client = Client(['127.0.0.1:11211']) yield client.set(key, {'foo': 1, 'bar': {'test': 'test'}}) res = yield client.get(key) self.assertEqual(res, {'foo': 1, 'bar': {'test': 'test'}}) yield client.delete(key) yield client.set('test1', 'test1') yield client.set('test2', 'test2') res1 = yield client.get('test1') self.assertEqual(res1, 'test1') yield client.set_multi({'foo': 1, 'bar': 'bar'}, 5, key_prefix='test_') yield client.set_multi({'0001': 1, '0002': 2}, 5, key_prefix='test_') yield client.delete('test_foo') res2 = yield client.get_multi(['foo', 'bar', '0001', '0002'], key_prefix='test_') self.assertEqual(res2, {'0001': 1, '0002': 2, 'bar': 'bar'})
def test_get_multi_not_all_exist(self): client = Client(['127.0.0.1:11211']) yield client.set_multi({'foo': 'foo', 'bar': 'bar'}, key_prefix='t_') res = yield client.get_multi(['foo', 'bar', 'fail'], key_prefix='t_') self.assertEqual(res, {'foo': 'foo', 'bar': 'bar'})