本文整理匯總了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()