本文整理汇总了Python中pylibmc.Client方法的典型用法代码示例。如果您正苦于以下问题:Python pylibmc.Client方法的具体用法?Python pylibmc.Client怎么用?Python pylibmc.Client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylibmc
的用法示例。
在下文中一共展示了pylibmc.Client方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_preferred_memcache_lib
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def import_preferred_memcache_lib(self, servers):
"""Returns an initialized memcache client. Used by the constructor."""
try:
import pylibmc
except ImportError:
pass
else:
return pylibmc.Client(servers)
try:
from google.appengine.api import memcache
except ImportError:
pass
else:
return memcache.Client()
try:
import memcache
except ImportError:
pass
else:
return memcache.Client(servers)
# backwards compatibility
示例2: clear_database
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def clear_database() -> None:
# Hacky function only for use inside populate_db. Designed to
# allow running populate_db repeatedly in series to work without
# flushing memcached or clearing the database manually.
# With `zproject.test_settings`, we aren't using real memcached
# and; we only need to flush memcached if we're populating a
# database that would be used with it (i.e. zproject.dev_settings).
if default_cache['BACKEND'] == 'django_pylibmc.memcached.PyLibMCCache':
pylibmc.Client(
[default_cache['LOCATION']],
binary=True,
username=default_cache["USERNAME"],
password=default_cache["PASSWORD"],
behaviors=default_cache["OPTIONS"],
).flush_all()
model: Any = None # Hack because mypy doesn't know these are model classes
for model in [Message, Stream, UserProfile, Recipient,
Realm, Subscription, Huddle, UserMessage, Client,
DefaultStream]:
model.objects.all().delete()
Session.objects.all().delete()
# Suppress spammy output from the push notifications logger
示例3: _imports
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def _imports(self):
global bmemcached
import bmemcached
class RepairBMemcachedAPI(bmemcached.Client):
"""Repairs BMemcached's non-standard method
signatures, which was fixed in BMemcached
ef206ed4473fec3b639e.
"""
def add(self, key, value):
try:
return super(RepairBMemcachedAPI, self).add(key, value)
except ValueError:
return False
self.Client = RepairBMemcachedAPI
示例4: _setup_bytecode_cache
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def _setup_bytecode_cache(cls):
cache_type = config.get('jinja_bytecode_cache_type')
bcc = None
try:
if cache_type == 'memcached' and config.get('memcached_host'):
import pylibmc
from jinja2 import MemcachedBytecodeCache
client = pylibmc.Client([config['memcached_host']])
bcc_prefix = 'jinja2/{}/'.format(jinja2.__version__)
if six.PY3:
bcc_prefix += 'py{}{}/'.format(sys.version_info.major, sys.version_info.minor)
bcc = MemcachedBytecodeCache(client, prefix=bcc_prefix)
elif cache_type == 'filesystem':
from jinja2 import FileSystemBytecodeCache
bcc = FileSystemBytecodeCache(pattern='__jinja2_{}_%s.cache'.format(jinja2.__version__))
except:
log.exception("Error encountered while setting up a" +
" %s-backed bytecode cache for Jinja" % cache_type)
return bcc
示例5: import_preferred_memcache_lib
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def import_preferred_memcache_lib(self, servers):
"""Returns an initialized memcache client. Used by the constructor."""
try:
import pylibmc
except ImportError:
pass
else:
return pylibmc.Client(servers)
try:
from google.appengine.api import memcache
except ImportError:
pass
else:
return memcache.Client()
try:
import memcache
except ImportError:
pass
else:
return memcache.Client(servers)
try:
import libmc
except ImportError:
pass
else:
return libmc.Client(servers)
# backwards compatibility
示例6: import_preferred_memcache_lib
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def import_preferred_memcache_lib(self, servers):
"""Returns an initialized memcache client. Used by the constructor."""
try:
import pylibmc
except ImportError:
pass
else:
return pylibmc.Client(servers)
try:
from google.appengine.api import memcache
except ImportError:
pass
else:
return memcache.Client()
try:
import memcache
except ImportError:
pass
else:
return memcache.Client(servers)
try:
import libmc
except ImportError:
pass
else:
return libmc.Client(servers)
示例7: _setup
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def _setup(self, *args, **kw):
super(MemcachedCacheHandler, self)._setup(*args, **kw)
self._fix_hosts()
self.mc = pylibmc.Client(self._config('hosts'))
示例8: _create_client
# 需要导入模块: import pylibmc [as 别名]
# 或者: from pylibmc import Client [as 别名]
def _create_client(self):
"""Creation of a Client instance goes here."""
raise NotImplementedError()