本文整理汇总了Python中pymemcache.client.hash.HashClient.delete方法的典型用法代码示例。如果您正苦于以下问题:Python HashClient.delete方法的具体用法?Python HashClient.delete怎么用?Python HashClient.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymemcache.client.hash.HashClient
的用法示例。
在下文中一共展示了HashClient.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemcachedDriver
# 需要导入模块: from pymemcache.client.hash import HashClient [as 别名]
# 或者: from pymemcache.client.hash.HashClient import delete [as 别名]
#.........这里部分代码省略.........
return utils.dumps(value), 2
@staticmethod
def _msgpack_deserializer(key, value, flags):
if flags == 1:
return value
if flags == 2:
return utils.loads(value)
raise coordination.SerializationError("Unknown serialization"
" format '%s'" % flags)
@_translate_failures
def _start(self):
#self.client = pymemcache_client.PooledClient(
from pymemcache.client.hash import HashClient
self.client = HashClient(
self.host,
serializer=self._msgpack_serializer,
deserializer=self._msgpack_deserializer,
timeout=self.timeout,
connect_timeout=self.timeout,
max_pool_size=self.max_pool_size)
# Run heartbeat here because pymemcache use a lazy connection
# method and only connect once you do an operation.
self.heartbeat()
self._group_members = collections.defaultdict(set)
self._executor.start()
@_translate_failures
def _stop(self):
for lock in list(self._acquired_locks):
lock.release()
self.client.delete(self._encode_member_id(self._member_id))
for g in list(self._joined_groups):
try:
self.leave_group(g).get()
except (coordination.MemberNotJoined,
coordination.GroupNotCreated):
# Guess we got booted out/never existed in the first place...
pass
except coordination.ToozError:
LOG.warning("Unable to leave group '%s'", g, exc_info=True)
self._executor.stop()
# self.client.close()
def _encode_group_id(self, group_id):
return self.GROUP_PREFIX + group_id
def _encode_member_id(self, member_id):
return self.MEMBER_PREFIX + member_id
def _encode_group_leader(self, group_id):
return self.GROUP_LEADER_PREFIX + group_id
@_retry.retry()
def _add_group_to_group_list(self, group_id):
"""Add group to the group list.
:param group_id: The group id
"""
group_list, cas = self.client.gets(self.GROUP_LIST_KEY)
if cas:
group_list = set(group_list)
group_list.add(group_id)
if not self.client.cas(self.GROUP_LIST_KEY,
示例2: MemcacheService
# 需要导入模块: from pymemcache.client.hash import HashClient [as 别名]
# 或者: from pymemcache.client.hash.HashClient import delete [as 别名]
#.........这里部分代码省略.........
INVALID_VALUE, 'All CAS items must have a cas_id')
for item in request.item_list():
try:
encoded_key = encode_key(self._project_id, namespace, item.key())
except apiproxy_errors.ApplicationError:
response.add_set_status(MemcacheSetResponse.ERROR)
continue
args = {'key': encoded_key,
'value': (item.value(), item.flags()),
'expire': int(item.expiration_time())}
is_cas = item.set_policy() == MemcacheSetRequest.CAS
if is_cas:
args['cas'] = six.binary_type(item.cas_id())
try:
backend_response = self._methods[item.set_policy()](**args)
except (TRANSIENT_ERRORS + (MemcacheClientError,)):
response.add_set_status(MemcacheSetResponse.ERROR)
continue
if backend_response:
response.add_set_status(MemcacheSetResponse.STORED)
continue
if is_cas and backend_response is False:
response.add_set_status(MemcacheSetResponse.EXISTS)
continue
response.add_set_status(MemcacheSetResponse.NOT_STORED)
def _Dynamic_Delete(self, request, response):
"""Implementation of delete in memcache.
Args:
request: A MemcacheDeleteRequest protocol buffer.
response: A MemcacheDeleteResponse protocol buffer.
"""
for item in request.item_list():
encoded_key = encode_key(self._project_id, request.name_space(),
item.key())
try:
key_existed = self._memcache.delete(encoded_key)
except MemcacheClientError as error:
raise apiproxy_errors.ApplicationError(INVALID_VALUE, str(error))
except TRANSIENT_ERRORS as error:
raise apiproxy_errors.ApplicationError(
UNSPECIFIED_ERROR, 'Transient memcache error: {}'.format(error))
response.add_delete_status(MemcacheDeleteResponse.DELETED if key_existed
else MemcacheDeleteResponse.NOT_FOUND)
def _Increment(self, namespace, request):
"""Internal function for incrementing from a MemcacheIncrementRequest.
Args:
namespace: A string containing the namespace for the request,
if any. Pass an empty string if there is no namespace.
request: A MemcacheIncrementRequest instance.
Returns:
An integer indicating the new value.
Raises:
ApplicationError if unable to perform the mutation.
"""
示例3: CouchbaseMemcacheMirror
# 需要导入模块: from pymemcache.client.hash import HashClient [as 别名]
# 或者: from pymemcache.client.hash.HashClient import delete [as 别名]
#.........这里部分代码省略.........
keys_err = set(keys) - set(ok)
ok.update(self._cb_mget(list(keys_err))[0])
return ok
def gets(self, key):
"""
Get an item with its CAS. The item will always be fetched from the primary
data store.
:param key: the key to get
:return: the value of the key, or None if no such value
"""
if self._primary == PRIMARY_COUCHBASE:
try:
rv = self.cb.get(key)
return key, rv.cas
except NotFoundError:
return None, None
else:
return self.mc.gets(key)
def gets_multi(self, keys):
if self._primary == PRIMARY_COUCHBASE:
try:
rvs = self.cb.get_multi(keys)
except NotFoundError as e:
rvs, _ = e.split_results()
return {k: (v.value, v.cas) for k, v in rvs}
else:
# TODO: I'm not sure if this is implemented in HasClient :(
return self.mc.gets_many(keys)
def delete(self, key):
st = Status()
try:
self.cb.remove(key)
except NotFoundError as e:
st.cb_error = e
st.mc_status = self.mc.delete(key)
return st
def delete_multi(self, keys):
st = Status()
try:
self.cb.remove_multi(keys)
except NotFoundError as e:
st.cb_error = e
st.mc_status = self.mc.delete_many(keys)
def _do_incrdecr(self, key, value, is_incr):
cb_value = value if is_incr else -value
mc_meth = self.mc.incr if is_incr else self.mc.decr
st = Status()
try:
self.cb.counter(key, delta=cb_value)
except NotFoundError as e:
st.cb_error = e
st.mc_status = mc_meth(key, value)
def incr(self, key, value):
return self._do_incrdecr(key, value, True)
开发者ID:couchbaselabs,项目名称:sk-python-couchbase-memcache-mirror,代码行数:69,代码来源:couchbase_memcache_mirror.py