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


Python redis.StrictRedis方法代碼示例

本文整理匯總了Python中redis.StrictRedis方法的典型用法代碼示例。如果您正苦於以下問題:Python redis.StrictRedis方法的具體用法?Python redis.StrictRedis怎麽用?Python redis.StrictRedis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis的用法示例。


在下文中一共展示了redis.StrictRedis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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 
開發者ID:BigBrotherTrade,項目名稱:trader,代碼行數:20,代碼來源:__init__.py

示例2: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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 
開發者ID:binux,項目名稱:pyspider,代碼行數:21,代碼來源:redis_queue.py

示例3: reset_cached_search_results

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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)) 
開發者ID:macarthur-lab,項目名稱:seqr,代碼行數:19,代碼來源:variant_utils.py

示例4: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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() 
開發者ID:neka-nat,項目名稱:distributed_rl,代碼行數:22,代碼來源:learner.py

示例5: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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) 
開發者ID:neka-nat,項目名稱:distributed_rl,代碼行數:25,代碼來源:actor.py

示例6: _setup_redis

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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 
開發者ID:istresearch,項目名稱:scrapy-cluster,代碼行數:21,代碼來源:rest_service.py

示例7: setup_once

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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") 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:21,代碼來源:redis.py

示例8: init

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
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 
開發者ID:cgwire,項目名稱:zou,代碼行數:20,代碼來源:publisher_store.py

示例9: __init__

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def __init__(self, channel, address, port):
        self.redis_client = redis.StrictRedis(host=address, port=port)
        self.channel = channel 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:5,代碼來源:replay.py

示例10: REDIS

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def REDIS(self):
        return redis.StrictRedis(host="localhost", port=6379, db=0) 
開發者ID:friendly-telegram,項目名稱:friendly-telegram,代碼行數:4,代碼來源:raphielgang.py

示例11: get_redis

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def get_redis():
    if 'redis' not in __dbctx:
        if config['redis'].get('unix_socket_path') is not None:
            redis_client = redis.StrictRedis(
                unix_socket_path=config['redis']['unix_socket_path'])
        else:
            redis_client = redis.StrictRedis(
                host=config['redis']['host'], port=config['redis']['port'])

        __dbctx['redis'] = redis_client
    return __dbctx['redis']


# vim: ts=4 sw=4 sts=4 expandtab 
開發者ID:tuna,項目名稱:fishroom,代碼行數:16,代碼來源:db.py

示例12: is_trading_day

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def is_trading_day(day: datetime.datetime):
    s = redis.StrictRedis(
        host=config.get('REDIS', 'host', fallback='localhost'),
        db=config.getint('REDIS', 'db', fallback=1), decode_responses=True)
    return day, day.strftime('%Y%m%d') in (s.get('TradingDay'), s.get('LastTradingDay'))
    # async with aiohttp.ClientSession() as session:
    #     await max_conn_cffex.acquire()
    #     async with session.get(
    #             'http://{}/fzjy/mrhq/{}/index.xml'.format(cffex_ip, day.strftime('%Y%m/%d')),
    #             allow_redirects=False) as response:
    #         max_conn_cffex.release()
    #         return day, response.status != 302 
開發者ID:BigBrotherTrade,項目名稱:trader,代碼行數:14,代碼來源:__init__.py

示例13: setUp

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def setUp(self):
        self.redis_client = redis.StrictRedis(
            host=config.get('REDIS', 'host', fallback='localhost'),
            db=config.getint('REDIS', 'db', fallback=1), decode_responses=True)
        self.api = CTPTrader(io_loop=self.loop) 
開發者ID:BigBrotherTrade,項目名稱:trader,代碼行數:7,代碼來源:test_api.py

示例14: retry_connect

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def retry_connect(redis_cfg, tries=300, base_delay=4.):
    for i in range(tries):
        try:
            r = redis.StrictRedis(**redis_cfg)
            r.ping()
            return r
        except redis.ConnectionError as e:
            if i == tries - 1:
                raise
            else:
                delay = base_delay * (1 + (os.getpid() % 10) / 9)
                logger.warning('Could not connect to {}. Retrying after {:.2f} sec ({}/{}). Error: {}'.format(
                    redis_cfg, delay, i + 2, tries, e))
                time.sleep(delay) 
開發者ID:openai,項目名稱:evolution-strategies-starter,代碼行數:16,代碼來源:dist.py

示例15: test_basic

# 需要導入模塊: import redis [as 別名]
# 或者: from redis import StrictRedis [as 別名]
def test_basic(self):
        r = redis.StrictRedis()
        r.set('foo', 'bar')
        self.assertEquals(b'bar', r.get('foo')) 
開發者ID:seppo0010,項目名稱:rlite-py,代碼行數:6,代碼來源:patch.py


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