本文整理匯總了Python中redis.client.Pipeline方法的典型用法代碼示例。如果您正苦於以下問題:Python client.Pipeline方法的具體用法?Python client.Pipeline怎麽用?Python client.Pipeline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.client
的用法示例。
在下文中一共展示了client.Pipeline方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: pipeline
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def pipeline(self, transaction=True, shard_hint=None):
"""
Return a new pipeline object that can queue multiple commands for
later execution. ``transaction`` indicates whether all commands
should be executed atomically. Apart from making a group of operations
atomic, pipelines are useful for reducing the back-and-forth overhead
between the client and server.
Overridden in order to provide the right client through the pipeline.
"""
p = Pipeline(
connection_pool=self.connection_pool,
response_callbacks=self.response_callbacks,
transaction=transaction,
shard_hint=shard_hint)
p.setEncoder(self._encoder)
p.setDecoder(self._decoder)
return p
示例2: restore_redis
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def restore_redis():
"""Restores the redis client"""
try:
from redis.client import Pipeline, Redis
except ImportError: # pragma: no cover
pass
else:
if hasattr(Redis.execute_command, "__wrapped__"):
setattr(Redis, "execute_command", Redis.execute_command.__wrapped__)
for class_method in ["execute", "immediate_execute_command"]:
if hasattr(getattr(Pipeline, class_method), "__wrapped__"):
setattr(
Pipeline, class_method, getattr(Pipeline, class_method).__wrapped__
)
示例3: pipeline
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def pipeline(self, transaction=True, shard_hint=None):
"""
Return a new pipeline object that can queue multiple commands for
later execution. ``transaction`` indicates whether all commands
should be executed atomically. Apart from making a group of operations
atomic, pipelines are useful for reducing the back-and-forth overhead
between the client and server.
Overridden in order to provide the right client through the pipeline.
"""
p = Pipeline(
connection_pool=self.connection_pool,
response_callbacks=self.response_callbacks,
transaction=transaction,
shard_hint=shard_hint)
return p
示例4: get_atomic_connection
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def get_atomic_connection(self) -> Pipeline:
"""
Gets a Pipeline for normal redis or for redis sentinel based upon
redis mode in configuration
:return: Returns a Pipeline object
"""
return self.get_connection().pipeline(True)
示例5: save
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def save(self, redis_client=None, inserting=False, relative=False, transactional=False):
u"""
:param redis_client: Redis 連接或 pipeline 對象
:param inserting: 是否為即將插入的對象
:param relative: 是否保存相關的對象
:param transactional: 是否使用事務保存,隻用於主對象,相關對象應設為 False
:return: None
"""
if inserting:
self._check_inserting()
if not redis_client:
redis_client = self.redis_client
if transactional:
watching_keys = self._get_watching_keys(inserting)
if relative:
watching_keys.extend(self._get_relative_keys(inserting))
def insert(pipe):
try:
pipe.watch(*watching_keys)
if inserting:
self._populate_required_attributes(pipe)
pipe.multi()
self._save_self(pipe, inserting)
if relative:
self._save_relative(pipe, inserting)
pipe.execute()
except Exception as e:
logging.exception('failed to save')
self._fail_on_save(e, pipe, inserting)
raise
if isinstance(redis_client, Pipeline):
insert(redis_client)
else:
with redis_client.pipeline(True) as pipe:
insert(pipe)
else:
try:
if relative:
self._populate_required_attributes(redis_client)
self._save_self(redis_client, inserting)
if relative:
self._save_relative(redis_client, inserting)
except Exception as e:
logging.exception('failed to save')
self._fail_on_save(e, redis_client, inserting)
raise
示例6: patch_redis
# 需要導入模塊: from redis import client [as 別名]
# 或者: from redis.client import Pipeline [as 別名]
def patch_redis(context):
"""
Monkey patches redis client, if available. Overloads the
execute methods to add tracing and metrics collection.
"""
def wrapper(wrapped, instance, args, kwargs):
if not hasattr(context, "iopipe") or not hasattr(
context.iopipe, "mark"
): # pragma: no cover
return wrapped(*args, **kwargs)
id = ensure_utf8(str(uuid.uuid4()))
with context.iopipe.mark(id):
response = wrapped(*args, **kwargs)
trace = context.iopipe.mark.measure(id)
context.iopipe.mark.delete(id)
collect_redis_metrics(
context, trace, args, instance.connection_pool.connection_kwargs
)
return response
def pipeline_wrapper(wrapped, instance, args, kwargs): # pragma: no cover
if not hasattr(context, "iopipe") or not hasattr(
context.iopipe, "mark"
): # pragma: no cover
return wrapped(*args, **kwargs)
# We don't need the entire command stack, just collect a stack count
pipeline_args = ("PIPELINE", ensure_utf8(len(instance.command_stack)))
id = ensure_utf8(str(uuid.uuid4()))
with context.iopipe.mark(id):
response = wrapped(*args, **kwargs)
trace = context.iopipe.mark.measure(id)
context.iopipe.mark.delete(id)
collect_redis_metrics(
context, trace, pipeline_args, instance.connection_pool.connection_kwargs
)
return response
for module, attr, _wrapper in [
("redis.client", "Redis.execute_command", wrapper),
("redis.client", "Pipeline.execute", wrapper),
("redis.client", "Pipeline.immediate_execute_command", wrapper),
]:
try:
wrapt.wrap_function_wrapper(module, attr, _wrapper)
except Exception: # pragma: no cover
pass