當前位置: 首頁>>代碼示例>>Python>>正文


Python redis.ConnectionPool方法代碼示例

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


# ============================================================================ 
開發者ID:seppo0010,項目名稱:rlite-py,代碼行數:27,代碼來源:patch_conn.py

示例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] 
開發者ID:thenetcircle,項目名稱:dino,代碼行數:26,代碼來源:redis.py

示例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) 
開發者ID:shirosaidev,項目名稱:diskover,代碼行數:18,代碼來源:diskover_connections.py

示例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) 
開發者ID:AdamStelmaszczyk,項目名稱:learning2run,代碼行數:23,代碼來源:service.py

示例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 
開發者ID:haandol,項目名稱:honey,代碼行數:19,代碼來源:brain.py

示例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) 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:19,代碼來源:remote_resource.py

示例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] 
開發者ID:ss1917,項目名稱:ops_sdk,代碼行數:26,代碼來源:cache_context.py

示例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)) 
開發者ID:mundialis,項目名稱:actinia_core,代碼行數:23,代碼來源:redis_base.py

示例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) 
開發者ID:mundialis,項目名稱:actinia_core,代碼行數:24,代碼來源:redis_lock.py

示例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 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:19,代碼來源:run.py

示例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 
開發者ID:tiaotiaolong,項目名稱:TTLScan,代碼行數:24,代碼來源:redis_getshell.py

示例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() 
開發者ID:HatBoy,項目名稱:RTask,代碼行數:18,代碼來源:control.py

示例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 
開發者ID:autopi-io,項目名稱:autopi-core,代碼行數:18,代碼來源:cloud_cache.py

示例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 
開發者ID:seppo0010,項目名稱:rlite-py,代碼行數:9,代碼來源:patch_conn.py

示例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 
開發者ID:thenetcircle,項目名稱:dino,代碼行數:17,代碼來源:redis.py


注:本文中的redis.ConnectionPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。