本文整理汇总了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