Python redis.ConnectionPool() Examples
The following are 30
code examples of redis.ConnectionPool().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
redis
, or try the search function
.
Example #1
Source File: brain.py From honey with MIT License | 7 votes |
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
Example #2
Source File: cache_context.py From ops_sdk with GNU General Public License v3.0 | 6 votes |
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]
Example #3
Source File: redis.py From LuWu with Apache License 2.0 | 6 votes |
def __new__(cls, *args, **kwargs): redis_host = REDIS.get('host', 'localhost') redis_port = REDIS.get('port', 6379) redis_db = REDIS.get('db', 0) redis_password = REDIS.get('password', None) if cls._pool_instance is None: cls._pool_instance = redis.ConnectionPool( host=redis_host, port=redis_port, db=redis_db, password=redis_password, *args, **kwargs ) return super().__new__(cls, *args, **kwargs)
Example #4
Source File: control.py From RTask with GNU General Public License v3.0 | 6 votes |
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()
Example #5
Source File: service.py From learning2run with MIT License | 6 votes |
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)
Example #6
Source File: remote_resource.py From insights-core with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: cloud_cache.py From autopi-core with Apache License 2.0 | 6 votes |
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
Example #8
Source File: diskover_connections.py From diskover with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: patch_conn.py From rlite-py with BSD 2-Clause "Simplified" License | 6 votes |
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) # ============================================================================
Example #10
Source File: redis_base.py From actinia_core with GNU General Public License v3.0 | 6 votes |
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))
Example #11
Source File: redis_lock.py From actinia_core with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: redis_getshell.py From TTLScan with MIT License | 6 votes |
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
Example #13
Source File: redis.py From dino with Apache License 2.0 | 6 votes |
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]
Example #14
Source File: run.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
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
Example #15
Source File: redispool.py From xunfengES with GNU General Public License v3.0 | 5 votes |
def getPoolBR(): try: poolBR = redis.ConnectionPool(host=RedisConfig.HOST, port=RedisConfig.PORT, password=RedisConfig.PASSWORD, db=RedisConfig.BR) return redis.Redis(connection_pool=poolBR) except Exception as e: print 'redis connect error' return 'None'
Example #16
Source File: auto_complete.py From redisearch-py with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, key, host='localhost', port=6379, conn = None): """ Create a new AutoCompleter client for the given key, and optional host and port If conn is not None, we employ an already existing redis connection """ self.key = key self.redis = conn if conn is not None else Redis( connection_pool = ConnectionPool(host=host, port=port))
Example #17
Source File: bot.py From feedforbot with MIT License | 5 votes |
def __init__(self, settings: Settings, loop: AbstractEventLoop = None): self.settings = settings self.loop = loop self.redis_pool = ConnectionPool(host=self.settings.redis_host, port=self.settings.redis_port) self.listeners: List[Listener] = self.read_listeners(self.settings.feeds_path)
Example #18
Source File: client.py From redisearch-py with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, index_name, host='localhost', port=6379, conn=None, password=None): """ Create a new Client for the given index_name, and optional host and port If conn is not None, we employ an already existing redis connection """ self.index_name = index_name self.redis = conn if conn is not None else Redis( connection_pool=ConnectionPool(host=host, port=port, password=password))
Example #19
Source File: ProxyHelper.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def _get_proxy(): pool = redis.ConnectionPool(host='172.26.253.91', port=6379) r = redis.StrictRedis(connection_pool=pool, charset='utf-8') proxys_str = r.get("0") print proxys_str return eval(proxys_str)
Example #20
Source File: ProxyHelper.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def _get_proxy(): pool = redis.ConnectionPool(host='172.26.253.91', port=6379) r = redis.StrictRedis(connection_pool=pool, charset='utf-8') proxys_str = r.get("0") print proxys_str return eval(proxys_str)
Example #21
Source File: redis.py From IBATS_HuobiFeeder_old with GNU General Public License v3.0 | 5 votes |
def get_redis(db=0) -> StrictRedis: """ get StrictRedis object :param db: :return: """ if db in _redis_client_dic: redis_client = _redis_client_dic[db] else: conn = ConnectionPool(host=Config.REDIS_INFO_DIC['REDIS_HOST'], port=Config.REDIS_INFO_DIC['REDIS_PORT'], db=db) redis_client = StrictRedis(connection_pool=conn) _redis_client_dic[db] = redis_client return redis_client
Example #22
Source File: server.py From RTask with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.pool = redis.ConnectionPool(host=RTASK_REDIS_HOST, port=RTASK_REDIS_POST, db=RTASK_REDIS_DB, password=RTASK_REDIS_PWD, encoding='utf-8', decode_responses=True) self.client = redis.StrictRedis(connection_pool=self.pool) self.macid = sysinfo.get_macid() self.ips = sysinfo.get_ips() self.hostname = sysinfo.get_hostname() self.platform = sysinfo.get_platform()
Example #23
Source File: ProxyHelper.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def _get_proxy(): pool = redis.ConnectionPool(host='172.26.253.91', port=6379) r = redis.StrictRedis(connection_pool=pool, charset='utf-8') proxys_str = r.get("0") print proxys_str return eval(proxys_str)
Example #24
Source File: CoperProxy.py From Ugly-Distributed-Crawler with Mozilla Public License 2.0 | 5 votes |
def connect_redis_server(self): pool = redis.ConnectionPool(host=r_server['ip'], port=r_server['port'], password=['passwd']) return redis.Redis(connection_pool=pool)
Example #25
Source File: test_unitest.py From wrapcache with MIT License | 5 votes |
def setUp(self): self.test_class = TestRedisInstance() import redis #init redis instance REDIS_CACHE_POOL = redis.ConnectionPool(host = '162.211.225.209', port = 6739, password = 'wzwacxl', db = 2) REDIS_CACHE_INST = redis.Redis(connection_pool = REDIS_CACHE_POOL, charset = 'utf8') RedisAdapter.db = REDIS_CACHE_INST #初始化装饰器缓存
Example #26
Source File: RedisAdapter.py From wrapcache with MIT License | 5 votes |
def test_memory_adapter(self): # test redis error self.assertRaises(DBNotSetException, self.test_class.get, 'test_key') REDIS_CACHE_POOL = redis.ConnectionPool(host = '162.211.225.208', port = 6739, password = '123456', db = 2) REDIS_CACHE_INST = redis.Redis(connection_pool = REDIS_CACHE_POOL, charset = 'utf8') RedisAdapter.db = REDIS_CACHE_INST #初始化装饰器缓存 self.assertRaises(ConnectionError, self.test_class.get, 'test_key') REDIS_CACHE_POOL = redis.ConnectionPool(host = '162.211.225.209', port = 6739, password = 'wzwacxl', db = 2) REDIS_CACHE_INST = redis.Redis(connection_pool = REDIS_CACHE_POOL, charset = 'utf8') RedisAdapter.db = REDIS_CACHE_INST #初始化装饰器缓存 key = 'test_key_1' value = str(time.time()) #test set / get self.test_class.set(key, value) self.assertEqual(self.test_class.get(key).decode('utf-8'), value) #test remove self.test_class.set(key, value) self.test_class.remove(key) self.assertRaises(CacheExpiredException, self.test_class.get, key) #test flush self.test_class.set(key, value) self.test_class.flush() self.assertRaises(CacheExpiredException, self.test_class.get, key)
Example #27
Source File: database.py From magnet-dht with MIT License | 5 votes |
def __init__(self, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD): conn_pool = redis.ConnectionPool( host=host, port=port, password=password, max_connections=REDIS_MAX_CONNECTION, ) self.redis = redis.Redis(connection_pool=conn_pool)
Example #28
Source File: RedisCon.py From imoocc with GNU General Public License v2.0 | 5 votes |
def getRedisConnection(db): '''根据数据源标识获取Redis连接池''' if db==RedisConPool.REDSI_POOL: args = settings.REDSI_KWARGS_LPUSH if settings.REDSI_LPUSH_POOL == None: settings.REDSI_LPUSH_POOL = redis.ConnectionPool(host=args.get('host'), port=args.get('port'), db=args.get('db')) pools = settings.REDSI_LPUSH_POOL connection = redis.Redis(connection_pool=pools) return connection
Example #29
Source File: redissession.py From torndsession with MIT License | 5 votes |
def __create_redis_client(self): if not hasattr(self, 'client'): if 'max_connections' in self.settings: connection_pool = redis.ConnectionPool(**self.settings) settings = copy(self.settings) del settings['max_connections'] settings['connection_pool'] = connection_pool else: settings = self.settings self.client = redis.Redis(**settings)
Example #30
Source File: GrafanaDatastoreServer.py From grafana-redistimeseries with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): global REDIS_POOL parser = argparse.ArgumentParser() parser.add_argument("--host", help="server address to listen to", default="0.0.0.0") parser.add_argument("--port", help="port number to listen to", default=8080, type=int) parser.add_argument("--redis-server", help="redis server address", default="localhost") parser.add_argument("--redis-port", help="redis server port", default=6379, type=int) args = parser.parse_args() REDIS_POOL = redis.ConnectionPool(host=args.redis_server, port=args.redis_port) http_server = WSGIServer(('', args.port), app) http_server.serve_forever()