本文整理汇总了Python中pymemcache.client.base.Client.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Client.delete方法的具体用法?Python Client.delete怎么用?Python Client.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymemcache.client.base.Client
的用法示例。
在下文中一共展示了Client.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Memcached
# 需要导入模块: from pymemcache.client.base import Client [as 别名]
# 或者: from pymemcache.client.base.Client import delete [as 别名]
class Memcached(object):
DELAY = 0.5
DEBUG = False
def __init__(self, hostname, port, **params):
self.mc = Client((hostname, port))
def handle(self, topic, message):
"""
"""
if 'cmd' not in message:
raise Exception("Bad message: no command")
cmd = message['cmd']
if not hasattr(self, cmd):
raise Exception("Unknown command: " + cmd)
tryit = True
while tryit:
tryit = False
try:
getattr(self, cmd)(message)
except MemcacheUnexpectedCloseError:
# Server dropped dead - we'll retry
tryit = True
except IOError:
# Something network-related - retry
tryit = True
if tryit:
time.sleep(self.DELAY)
def set(self, message):
text = message['val'].encode('utf-8')
if message.get('sbt', None):
purge_time = time.time() + message.get('uto', 0)
text = text.replace('$UNIXTIME$', '%.6f' % purge_time)
if self.DEBUG:
print("Set {0}-{1}-{2}".format(message['key'].encode('utf-8'), text, int(message['ttl'])))
self.mc.set(message['key'].encode('utf-8'), text, int(message['ttl']))
def delete(self, message):
self.mc.delete(message['key'])