本文整理汇总了Python中redis.ConnectionPool方法的典型用法代码示例。如果您正苦于以下问题:Python redis.ConnectionPool方法的具体用法?Python redis.ConnectionPool怎么用?Python redis.ConnectionPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis
的用法示例。
在下文中一共展示了redis.ConnectionPool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: patch_connection
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def patch_connection(filename=':memory:'):
"""
``filename``: rlite filename to store db in, or memory
Patch the redis-py Connection and the
static from_url() of Redis and StrictRedis to use RliteConnection
"""
if no_redis:
raise Exception("redis package not found, please install redis-py via 'pip install redis'")
RliteConnection.set_file(filename)
global orig_classes
# already patched
if orig_classes:
return
orig_classes = (redis.connection.Connection,
redis.connection.ConnectionPool)
_set_classes(RliteConnection, RliteConnectionPool)
# ============================================================================
示例2: __init__
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def __init__(self, env, host: str, port: int = 6379, db: int = 0):
if env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
from fakeredis import FakeStrictRedis
self.redis_pool = None
self.redis_instance = FakeStrictRedis(host=host, port=port, db=db)
else:
self.redis_pool = redis.ConnectionPool(host=host, port=port, db=db)
self.redis_instance = None
self.cache = MemoryCache()
args = sys.argv
for a in ['--bind', '-b']:
bind_arg_pos = [i for i, x in enumerate(args) if x == a]
if len(bind_arg_pos) > 0:
bind_arg_pos = bind_arg_pos[0]
break
self.listen_port = 'standalone'
if bind_arg_pos is not None and not isinstance(bind_arg_pos, list):
self.listen_port = args[bind_arg_pos + 1].split(':')[1]
self.listen_host = socket.gethostname().split('.')[0]
示例3: connect_to_redis
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def connect_to_redis():
from diskover import config
global redis_conn
# use connection pools
# use socket
if config['redis_socket']:
pool = ConnectionPool(connection_class=UnixDomainSocketConnection, path=config['redis_socket'],
password=config['redis_password'], db=config['redis_db'])
redis_conn = Redis(connection_pool=pool)
# use host/port
else:
pool = ConnectionPool(host=config['redis_host'], port=config['redis_port'],
password=config['redis_password'], db=config['redis_db'])
redis_conn = Redis(connection_pool=pool)
示例4: __init__
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def __init__(self, osim_rl_redis_service_id='osim_rl_redis_service_id', seed_map=False, max_steps=1000, remote_host='127.0.0.1', remote_port=6379, remote_db=0, remote_password=None, visualize=False, verbose=False):
"""
TODO: Expose more RunEnv related variables
"""
print("Attempting to connect to redis server at {}:{}/{}".format(remote_host, remote_port, remote_db))
self.redis_pool = redis.ConnectionPool(host=remote_host, port=remote_port, db=remote_db, password=remote_password)
self.namespace = "osim-rl"
self.service_id = osim_rl_redis_service_id
self.command_channel = "{}::{}::commands".format(self.namespace, self.service_id)
self.env = False
self.env_available = False
self.reward = 0
self.simulation_count = 0
self.simualation_rewards = []
self.simulation_times = []
self.begin_simulation = False
self.current_step = 0
self.verbose = verbose
self.visualize = visualize
self.max_steps = max_steps
self.initalize_seed_map(seed_map)
示例5: connect
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def connect(self):
if not REDIS_URL:
logger.info('No brain on this bot.')
return
logger.info('Brain Connecting...')
try:
pool = redis.ConnectionPool(
host=REDIS_URL, port=REDIS_PORT,
max_connections=MAX_CONNECTION, db=0
)
self.redis = redis.Redis(connection_pool=pool)
self.redis.set('foo', 'bar')
logger.info('Brain Connected: {}'.format(REDIS_URL))
except Exception as e:
logger.error(traceback.format_exc())
raise e
示例6: __init__
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def __init__(self):
session = requests.Session()
if not self.__class__._cache:
if self.backend == "RedisCache":
pool = redis.ConnectionPool(host=self.redis_host, port=self.redis_port, db=0)
r = redis.Redis(connection_pool=pool)
self.__class__._cache = RedisCache(r)
elif self.backend == "FileCache":
self.__class__._cache = FileCache(self.file_cache_path)
else:
self.__class__._cache = DictCache()
session = CacheControl(session, heuristic=DefaultHeuristic(self.expire_after), cache=self.__class__._cache)
super(CachedRemoteResource, self).__init__(session)
示例7: cache_conn
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def cache_conn(key=None, db=None):
redis_configs = configs[const.REDIS_CONFIG_ITEM]
if not key:
key = const.DEFAULT_RD_KEY
for config_key, redis_config in redis_configs.items():
auth = redis_config[const.RD_AUTH_KEY]
host = redis_config[const.RD_HOST_KEY]
port = redis_config[const.RD_PORT_KEY]
password = redis_config[const.RD_PASSWORD_KEY]
if db:
db = db
else:
db = redis_config[const.RD_DB_KEY]
return_utf8 = False
if const.RD_DECODE_RESPONSES in redis_config:
return_utf8 = redis_config[const.RD_DECODE_RESPONSES]
if auth:
redis_pool = redis.ConnectionPool(host=host, port=port, db=db, password=password,
decode_responses=return_utf8)
else:
redis_pool = redis.ConnectionPool(host=host, port=port, db=db, decode_responses=return_utf8)
cache_conns[config_key] = redis.StrictRedis(connection_pool=redis_pool)
return cache_conns[key]
示例8: connect
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def connect(self, host="localhost", port=6379, password=None):
"""Connect to a specific redis server
Args:
host (str): The host name or IP address
port (int): The port
password (str): The password
"""
kwargs = dict()
kwargs['host'] = host
kwargs['port'] = port
if password and password is not None:
kwargs['password'] = password
self.connection_pool = redis.ConnectionPool(**kwargs)
del kwargs
self.redis_server = redis.StrictRedis(connection_pool=self.connection_pool)
try:
self.redis_server.ping()
except redis.exceptions.ResponseError as e:
print('ERROR: Could not connect to redis with ' + host, port, password, str(e))
示例9: connect
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def connect(self, host, port, password=None):
"""Connect to a specific redis server
Args:
host (str): The host name or IP address
port (int): The port
password (str): The password
"""
kwargs = dict()
kwargs['host'] = host
kwargs['port'] = port
if password and password is not None:
kwargs['password'] = password
self.connection_pool = redis.ConnectionPool(**kwargs)
del kwargs
self.redis_server = redis.StrictRedis(connection_pool=self.connection_pool)
# Register the resource lock scripts in Redis
self.call_lock_resource = self.redis_server.register_script(self.lua_lock_resource)
self.call_extend_resource_lock = self.redis_server.register_script(self.lua_extend_resource_lock)
self.call_unlock_resource = self.redis_server.register_script(self.lua_unlock_resource)
示例10: wait_parse_result
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def wait_parse_result(keys):
pool = redis.ConnectionPool(host = REDIS_SERVER , port = 6379, db = 0)
r = redis.Redis(connection_pool = pool)
spider_json_content = None
while True:
#TODO timeout is need
try:
_ = r.get(keys)
if _ is not None:
spider_content = eval(_)
if isinstance(spider_content, dict) and spider_content.haskey('GET') and spider_content['GET'] is not None:
spider_json_content = spider_content['GET']
break
except Exception:
time.sleep(1)
return spider_json_content
示例11: POC
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def POC(ip,port=6379):
try:
#首先判断是否可访问
socket.setdefaulttimeout(2)
poc=b"\x2a\x31\x0d\x0a\x24\x34\x0d\x0a\x69\x6e\x66\x6f\x0d\x0a"
s=socket.socket()
s.connect((ip,port))
s.send(poc)
rec=s.recv(1024)
s.close()
if "redis" in rec.decode():
pool=redis.ConnectionPool(host=ip,port=port,decode_responses=True)
r=redis.Redis(connection_pool=pool)
if r:
r.set("abcdefgqwertyuiop","ABCDEFGQWERTYUIOP")
if(r.get("abcdefgqwertyuiop")=="ABCDEFGQWERTYUIOP"):
return True
else:
return False
except:
return False
示例12: get_sysinfo
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def get_sysinfo(self):
sysinfo = self.rpc.sysinfo(RPC_PWD)
return sysinfo
# client = queues.get_redis_client(QUEUE_REDIS_TYPE, QUEUE_REDIS_HOST, QUEUE_REDIS_PORT, QUEUE_REDIS_DB, QUEUE_REDIS_PWD, QUEUE_REDIS_NODES)
# queues = queues.RedisQueues(conn=client)
# pool = redis.ConnectionPool(host=QUEUE_REDIS_HOST, port=QUEUE_REDIS_PORT, db=QUEUE_REDIS_DB, password=QUEUE_REDIS_PWD)
# client = redis.StrictRedis(connection_pool=pool)
# qi = QueueInfo()
# qi.taskfail_rpush({'taskid': '27050696', 'error': "module 'tasks.spider' has no attribute 'save'"})
# ni = NodeInfo()
# ni.task_list()
示例13: setup
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def setup(self, **options):
self.options = options
if log.isEnabledFor(logging.DEBUG):
log.debug("Creating Redis connection pool")
self.conn_pool = redis.ConnectionPool(**options.get("redis", {k.replace("redis_", "", 1): v for k, v in options.iteritems() if k.startswith("redis_")}))
self.client = redis.StrictRedis(connection_pool=self.conn_pool)
if log.isEnabledFor(logging.DEBUG):
log.debug("Loading Redis LUA scripts")
self.scripts = {
self.DEQUEUE_BATCH_SCRIPT: self.client.register_script(self.DEQUEUE_BATCH_LUA)
}
return self
示例14: _set_classes
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def _set_classes(conn_class, pool_class):
redis.connection.Connection = conn_class
redis.Connection = conn_class
redis.connection.ConnectionPool = pool_class
redis.client.ConnectionPool = pool_class
redis.ConnectionPool = pool_class
示例15: __init__
# 需要导入模块: import redis [as 别名]
# 或者: from redis import ConnectionPool [as 别名]
def __init__(self, host: str, port: int = 6379, db: int = 0, env=None):
if env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
from fakeredis import FakeStrictRedis
self.redis_pool = None
self.redis_instance = FakeStrictRedis(host=host, port=port, db=db)
else:
self.redis_pool = redis.ConnectionPool(host=host, port=port, db=db)
self.redis_instance = None
if env is None:
from dino import environ
self.env = environ.env
else:
self.env = env