Python redis.StrictRedis() Examples
The following are 30
code examples of redis.StrictRedis().
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: rest_service.py From scrapy-cluster with MIT License | 6 votes |
def _setup_redis(self): """Returns a Redis Client""" if not self.closed: try: self.logger.debug("Creating redis connection to host " + str(self.settings['REDIS_HOST'])) self.redis_conn = redis.StrictRedis(host=self.settings['REDIS_HOST'], port=self.settings['REDIS_PORT'], db=self.settings['REDIS_DB']) self.redis_conn.info() self.redis_connected = True self.logger.info("Successfully connected to redis") except KeyError as e: self.logger.error('Missing setting named ' + str(e), {'ex': traceback.format_exc()}) except: self.logger.error("Couldn't initialize redis client.", {'ex': traceback.format_exc()}) raise
Example #2
Source File: actor.py From distributed_rl with MIT License | 6 votes |
def __init__(self, actor_no, env, policy_net, vis, hostname='localhost', batch_size=50, nstep_return=3, gamma=0.999, clip=lambda x: min(max(-1.0, x), 1.0), target_update=200, num_total_actors=4, device=torch.device("cuda" if torch.cuda.is_available() else "cpu")): self._env = env self._actor_no = actor_no self._name = "actor_" + str(actor_no) self._vis = vis self._batch_size = batch_size self._nstep_return = nstep_return self._gamma = gamma self._clip = clip self._target_update = target_update self._num_total_actors = num_total_actors self._policy_net = policy_net self._policy_net.eval() self._device = device self._win1 = self._vis.image(utils.preprocess(self._env.env._get_image())) self._win2 = self._vis.line(X=np.array([0]), Y=np.array([0.0]), opts=dict(title='Score %s' % self._name)) self._local_memory = replay_memory.ReplayMemory(1000) self._connect = redis.StrictRedis(host=hostname)
Example #3
Source File: variant_utils.py From seqr with GNU Affero General Public License v3.0 | 6 votes |
def reset_cached_search_results(project): try: redis_client = redis.StrictRedis(host=REDIS_SERVICE_HOSTNAME, socket_connect_timeout=3) keys_to_delete = [] if project: result_guids = [res.guid for res in VariantSearchResults.objects.filter(families__project=project)] for guid in result_guids: keys_to_delete += redis_client.keys(pattern='search_results__{}*'.format(guid)) else: keys_to_delete = redis_client.keys(pattern='search_results__*') if keys_to_delete: redis_client.delete(*keys_to_delete) logger.info('Reset {} cached results'.format(len(keys_to_delete))) else: logger.info('No cached results to reset') except Exception as e: logger.error("Unable to reset cached search results: {}".format(e))
Example #4
Source File: learner.py From distributed_rl with MIT License | 6 votes |
def __init__(self, policy_net, target_net, optimizer, vis, replay_size=30000, hostname='localhost', beta_decay=1000000, use_memory_compress=False): self._vis = vis self._policy_net = policy_net self._target_net = target_net self._target_net.load_state_dict(self._policy_net.state_dict()) self._target_net.eval() self._beta_decay = beta_decay self._connect = redis.StrictRedis(host=hostname) self._connect.delete('params') self._optimizer = optimizer self._win = self._vis.line(X=np.array([0]), Y=np.array([0]), opts=dict(title='Memory size')) self._win2 = self._vis.line(X=np.array([0]), Y=np.array([0]), opts=dict(title='Q loss')) self._memory = replay.Replay(replay_size, self._connect, use_compress=use_memory_compress) self._memory.start()
Example #5
Source File: redis_queue.py From pyspider with Apache License 2.0 | 6 votes |
def __init__(self, name, host='localhost', port=6379, db=0, maxsize=0, lazy_limit=True, password=None, cluster_nodes=None): """ Constructor for RedisQueue maxsize: an integer that sets the upperbound limit on the number of items that can be placed in the queue. lazy_limit: redis queue is shared via instance, a lazy size limit is used for better performance. """ self.name = name if(cluster_nodes is not None): from rediscluster import StrictRedisCluster self.redis = StrictRedisCluster(startup_nodes=cluster_nodes) else: self.redis = redis.StrictRedis(host=host, port=port, db=db, password=password) self.maxsize = maxsize self.lazy_limit = lazy_limit self.last_qsize = 0
Example #6
Source File: redis.py From sentry-python with BSD 2-Clause "Simplified" License | 6 votes |
def setup_once(): # type: () -> None import redis patch_redis_client(redis.StrictRedis) try: import rb.clients # type: ignore except ImportError: pass else: patch_redis_client(rb.clients.FanoutClient) patch_redis_client(rb.clients.MappingClient) patch_redis_client(rb.clients.RoutingClient) try: _patch_rediscluster() except Exception: logger.exception("Error occured while patching `rediscluster` library")
Example #7
Source File: __init__.py From trader with Apache License 2.0 | 6 votes |
def __init__(self, io_loop: asyncio.AbstractEventLoop = None): super().__init__() self.io_loop = io_loop or asyncio.get_event_loop() self.sub_client = self.io_loop.run_until_complete( aioredis.create_redis((config.get('REDIS', 'host', fallback='localhost'), config.getint('REDIS', 'port', fallback=6379)), db=config.getint('REDIS', 'db', fallback=1))) self.redis_client = redis.StrictRedis( host=config.get('REDIS', 'host', fallback='localhost'), db=config.getint('REDIS', 'db', fallback=1), decode_responses=True) self.initialized = False self.sub_tasks = list() self.sub_channels = list() self.channel_router = dict() self.crontab_router = defaultdict(dict) self.datetime = None self.time = None self.loop_time = None
Example #8
Source File: publisher_store.py From zou with GNU Affero General Public License v3.0 | 6 votes |
def init(): """ Initialize key value store that will be used for the event publishing. That way the main API takes advantage of Redis pub/sub capabilities to push events to the event stream API. """ global socketio try: publisher_store = redis.StrictRedis( host=host, port=port, db=redis_db, decode_responses=True ) publisher_store.get("test") socketio = SocketIO(message_queue=redis_url) except redis.ConnectionError: pass return socketio
Example #9
Source File: tests.py From redis-lru with BSD 2-Clause "Simplified" License | 5 votes |
def get_cache(cls, **kwargs): client = redis.StrictRedis('127.0.0.1', 6379) return RedisLRU(client, clear_on_exit=True, **kwargs)
Example #10
Source File: test_ft_redis.py From minemeld-core with Apache License 2.0 | 5 votes |
def test_uw(self): config = {} chassis = mock.Mock() chassis.request_sub_channel.return_value = None ochannel = mock.Mock() chassis.request_pub_channel.return_value = ochannel chassis.request_rpc_channel.return_value = None rpcmock = mock.Mock() rpcmock.get.return_value = {'error': None, 'result': 'OK'} chassis.send_rpc.return_value = rpcmock b = minemeld.ft.redis.RedisSet(FTNAME, chassis, config) inputs = ['a', 'b', 'c'] output = False b.connect(inputs, output) b.mgmtbus_initialize() b.start() time.sleep(1) SR = redis.StrictRedis() b.filtered_update('a', indicator='testi', value={'test': 'v'}) sm = SR.zrange(FTNAME, 0, -1) self.assertEqual(len(sm), 1) self.assertIn('testi', sm) b.filtered_withdraw('a', indicator='testi') sm = SR.zrange(FTNAME, 0, -1) self.assertEqual(len(sm), 0) b.stop() self.assertNotEqual(b.SR, None)
Example #11
Source File: redis_client.py From aswan with GNU Lesser General Public License v2.1 | 5 votes |
def get_log_redis_client(): return redis.StrictRedis(**conf.LOG_REDIS_CONFIG)
Example #12
Source File: test_ft_redis.py From minemeld-core with Apache License 2.0 | 5 votes |
def tearDown(self): SR = redis.StrictRedis() SR.delete(FTNAME)
Example #13
Source File: views.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def municipality_data(request): # r = redis.StrictRedis(host=settings.REDIS_HOST, port=6379, db=3) # data = r.hgetall("municipality") data = generate_municipality_data() return Response(data.values())
Example #14
Source File: session.py From minemeld-core with Apache License 2.0 | 5 votes |
def init_app(app, redis_url): redis_cp = redis.ConnectionPool.from_url( redis_url, max_connections=int(os.environ.get('REDIS_SESSIONS_MAX_CONNECTIONS', 20)) ) app.session_interface = RedisSessionInterface( redis_=redis.StrictRedis(connection_pool=redis_cp) ) app.config.update( SESSION_COOKIE_NAME='mm-session', SESSION_COOKIE_SECURE=True )
Example #15
Source File: session.py From minemeld-core with Apache License 2.0 | 5 votes |
def __init__(self, redis_=None, prefix='mm-session:'): if redis_ is None: redis_ = redis.StrictRedis() self.redis = redis_ self.prefix = prefix self.expirtaion_delta = timedelta( minutes=int(os.environ.get( SESSION_EXPIRATION_ENV, DEFAULT_SESSION_EXPIRATION )) )
Example #16
Source File: tracker_store.py From rasa_wechat with Apache License 2.0 | 5 votes |
def __init__(self, domain, mock=False, host='localhost', port=6379, db=0, password=None): if mock: import fakeredis self.red = fakeredis.FakeStrictRedis() else: # pragma: no cover import redis self.red = redis.StrictRedis(host=host, port=port, db=db, password=password) super(RedisTrackerStore, self).__init__(domain)
Example #17
Source File: rediscache.py From torngas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _init(self, server, params): super(RedisClient, self).__init__(params) self._server = server self._params = params unix_socket_path = None if ':' in self.server: host, port = self.server.rsplit(':', 1) try: port = int(port) except (ValueError, TypeError): raise ConfigError("port value must be an integer") else: host, port = None, None unix_socket_path = self.server kwargs = { 'db': self.db, 'password': self.password, 'host': host, 'port': port, 'unix_socket_path': unix_socket_path, } connection_pool = pool.get_connection_pool( parser_class=self.parser_class, connection_pool_class=self.connection_pool_class, connection_pool_class_kwargs=self.connection_pool_class_kwargs, **kwargs ) self._client = redis.StrictRedis( connection_pool=connection_pool, **kwargs )
Example #18
Source File: utils.py From voicetools with Apache License 2.0 | 5 votes |
def __init__(self): self.client = redis.StrictRedis( connection_pool=conn_pool, socket_timeout=RC.SOCKET_TIMEOUT)
Example #19
Source File: jobs.py From minemeld-core with Apache License 2.0 | 5 votes |
def __init__(self, connection_pool): self.SR = redis.StrictRedis(connection_pool=connection_pool) self.running_jobs = defaultdict(dict)
Example #20
Source File: redis_client.py From aswan with GNU Lesser General Public License v2.1 | 5 votes |
def get_report_redis_client(): return redis.StrictRedis(**conf.REPORT_REDIS_CONFIG)
Example #21
Source File: zmqredis.py From minemeld-core with Apache License 2.0 | 5 votes |
def connect(self): subscribers_key = '{}:subscribers'.format(self.prefix) SR = redis.StrictRedis( connection_pool=self.connection_pool ) self.sub_number = SR.rpush( subscribers_key, 0 ) self.sub_number -= 1 LOG.debug('Sub Number {} on {}'.format(self.sub_number, subscribers_key))
Example #22
Source File: redis_client.py From aswan with GNU Lesser General Public License v2.1 | 5 votes |
def get_config_redis_client(): return redis.StrictRedis(**conf.REDIS_CONFIG)
Example #23
Source File: redis_get_set.py From redis-load-test with Apache License 2.0 | 5 votes |
def __init__(self, host=configs["redis_host"], port=configs["redis_port"], password=configs["redis_password"]): self.rc = redis.StrictRedis(host=host, port=port, password=password)
Example #24
Source File: redis_read.py From redis-load-test with Apache License 2.0 | 5 votes |
def __init__(self, host=configs["redis_host"], port=configs["redis_port"]): self.rc = redis.StrictRedis(host=host, port=port) print(host, port)
Example #25
Source File: redis_set.py From redis-load-test with Apache License 2.0 | 5 votes |
def redis_populate(filepath): """Function to populate keys in Redis Server""" configs = load_config(filepath) client = redis.StrictRedis(host=configs["redis_host"], port=configs["redis_port"]) for i in range(100000): key='key'+str(i) value='value'+str(i) client.set(key,value) print(key,value)
Example #26
Source File: subscribe.py From codo-admin with GNU General Public License v3.0 | 5 votes |
def __init__(self, channel='gw', **settings): ### 订阅日志使用默认redis 如果有需求 请自行修改配置 redis_info = settings.get(const.REDIS_CONFIG_ITEM, None).get(const.DEFAULT_RD_KEY, None) if not redis_info: exit('not redis') self.pool = redis.ConnectionPool(host=redis_info.get(const.RD_HOST_KEY), port=redis_info.get(const.RD_PORT_KEY, 6379), db=redis_info.get(const.RD_DB_KEY, 0), password=redis_info.get(const.RD_PASSWORD_KEY, None)) self.conn = redis.StrictRedis(connection_pool=self.pool) self.channel = channel # 定义频道名称 self.__settings = settings
Example #27
Source File: lru.py From redis-lru with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, client: redis.StrictRedis, max_size=2 ** 20, default_ttl=15 * 60, key_prefix='RedisLRU', clear_on_exit=False, exclude_values=None): self.client = client self.max_size = max_size self.key_prefix = key_prefix self.default_ttl = default_ttl self.exclude_values = exclude_values if type(exclude_values) is set else set() if clear_on_exit: atexit.register(self.clear_all_cache)
Example #28
Source File: _3_properties.py From Clean-code-in-Python with MIT License | 5 votes |
def __init__(self): self.redis_connection = redis.StrictRedis() self.key = "score_1"
Example #29
Source File: RedisConnector.py From sprutio with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.r = redis.StrictRedis(host=server.REDIS_DEFAULT_HOST, port=server.REDIS_DEFAULT_PORT, decode_responses=True) self.timeout = server.REDIS_DEFAULT_EXPIRE
Example #30
Source File: context.py From panoptes with Apache License 2.0 | 5 votes |
def get_redis_connection(self, group, shard=0, fallback_to_default=True): """ Returns a Redis connection for the given group and shard Args: group (str): The name of the group for which to return the Redis connection shard (int): The number of the shard for which to return the Redis connection fallback_to_default (bool): If we can't find a connection for given group, whether to fallback to the \ 'default` group name Returns: redis.StrictRedis: The Redis connection """ def _inner_get_redis_connection(): try: connection = self._get_redis_connection(group, shard) self.__redis_connections[group][shard] = connection except: if (group != const.DEFAULT_REDIS_GROUP_NAME) and fallback_to_default: self.__redis_connections[group][shard] = self.redis_pool else: raise if group not in self.__redis_connections: self.__redis_connections[group] = dict() _inner_get_redis_connection() elif shard not in self.__redis_connections[group]: _inner_get_redis_connection() return self.__redis_connections[group][shard]