python类StrictRedis()的实例源码

test-redis.py 文件源码 项目:dash-ticker 作者: chaeplin 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def check_redis():
    if HOST_ROLE == 'MASTER':
        SETINEL_HOST = MASTER_SETINEL_HOST
        REDIS_MASTER = MASTER_REDIS_MASTER

    else:
        SETINEL_HOST = SLAVE_SETINEL_HOST
        REDIS_MASTER = SLAVE_REDIS_MASTER      

    s = redis.StrictRedis(host=SETINEL_HOST, port=26379, socket_timeout=0.1)
    try:
        h = s.execute_command("SENTINEL get-master-addr-by-name mymaster")[0].decode("utf-8")
        print(h)
        if h == REDIS_MASTER:
            print('Other host is redis master')
            sys.exit()

        else:
            pass

    except Exception as e:
        print(e.args[0])
        sys.exit()
ticker-explorer.py 文件源码 项目:dash-ticker 作者: chaeplin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def check_redis():
    if HOST_ROLE == 'MASTER':
        SETINEL_HOST = MASTER_SETINEL_HOST
        REDIS_MASTER = MASTER_REDIS_MASTER

    else:
        SETINEL_HOST = SLAVE_SETINEL_HOST
        REDIS_MASTER = SLAVE_REDIS_MASTER

    s = redis.StrictRedis(host=SETINEL_HOST, port=26379, socket_timeout=0.1)
    try:
        h = s.execute_command("SENTINEL get-master-addr-by-name mymaster")[0].decode("utf-8")
        print(h)
        if h == REDIS_MASTER:
            print('Other host is redis master')
            sys.exit()

        else:
            pass

    except Exception as e:
        print(e.args[0])
        sys.exit()

#--------------
utils.py 文件源码 项目:socialhome 作者: jaywink 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_redis_connection():
    return redis.StrictRedis(
        host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=settings.REDIS_DB, password=settings.REDIS_PASSWORD,
    )
test_queue_store.py 文件源码 项目:dsq 作者: baverman 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def store(request):
    cl = redis.StrictRedis()
    cl.flushdb()
    return QueueStore(cl)
test_http.py 文件源码 项目:dsq 作者: baverman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def app(request):
    cl = redis.StrictRedis()
    cl.flushdb()
    return Application(Manager(QueueStore(cl), ResultStore(cl)))
test_manager.py 文件源码 项目:dsq 作者: baverman 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def manager(request):
    cl = redis.StrictRedis()
    cl.flushdb()
    return Manager(QueueStore(cl), ResultStore(cl))
test_result_store.py 文件源码 项目:dsq 作者: baverman 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def store(request):
    cl = redis.StrictRedis()
    cl.flushdb()
    return ResultStore(cl)
tools.py 文件源码 项目:openedoo 作者: openedoo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_redis(key,data,secnd):
    try:
        r = redis.StrictRedis()
        data = json.dumps(data)
        dataset = (str(key),str(data))
        a = r.set('%s' %key,'%s' %data)
        #rdis.bgsave()
        b = r.expire('%s' %key, secnd)
        return a
    except Exception:
        return False
tools.py 文件源码 项目:openedoo 作者: openedoo 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_redis(key):
    try:
        r = redis.StrictRedis()
        data = r.get(key)
        return json.loads(data)
    except Exception:
        return False
datacache.py 文件源码 项目:headers 作者: oshp 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, settings):
        self.r = redis.StrictRedis(
            host=settings['redis']['host'],
            port=settings['redis']['port'],
            db=settings['redis']['db'])
__init__.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, app=None):
        self.app = app
        self.master = StrictRedis()
        self.slave = self.master
        if app is not None: # pragma: no cover
            self.init_app(app)
test_news.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def setUp(self):
        super(TestNews, self).setUp()
        self.connection = StrictRedis()
        self.connection.flushall()
test_contributions_guard.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setUp(self):
        self.connection = StrictRedis()
        self.connection.flushall()
        self.guard = ContributionsGuard(self.connection)
        self.anon_user = {'user_id': None, 'user_ip': '127.0.0.1'}
        self.auth_user = {'user_id': 33, 'user_ip': None}
        self.task = Task(id=22)
test_maintenance.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def setUp(self):
        super(TestMaintenance, self).setUp()
        self.connection = StrictRedis()
        self.connection.flushall()
test_webhooks.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setUp(self):
        super(TestWebHooks, self).setUp()
        self.connection = StrictRedis()
        self.connection.flushall()
        self.project = ProjectFactory.create()
        self.webhook_payload = dict(project_id=self.project.id,
                                    project_short_name=self.project.short_name)
stats.py 文件源码 项目:lopocs 作者: Oslandia 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init(cls):
        cls.r = redis.StrictRedis(host='127.0.0.1',
                                  port=Config.STATS_SERVER_PORT, db=0)
        cls.r.set('rate', str(0.0).encode('utf-8'))
        cls.r.set('npoints', str(0).encode('utf-8'))
        cls.r.set('time_msec', str(0).encode('utf-8'))
redisutil.py 文件源码 项目:pykit 作者: baishancloud 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_client(ip_port):

    ip_port = normalize_ip_port(ip_port)

    pid = os.getpid()

    with _lock:
        o = _pid_client[ip_port]

        if pid not in o:
            o[pid] = redis.StrictRedis(*ip_port)

    return _pid_client[ip_port][pid]
redis_strategy.py 文件源码 项目:gemstone 作者: vladcalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_connection(self):
        conn = getattr(_thread_local, "_redisconn", None)
        if conn:
            return conn

        conn = redis.StrictRedis(host=self.host, port=self.port, db=self.db)
        setattr(_thread_local, "_redisconn", conn)
        return conn
redis_transport.py 文件源码 项目:gemstone 作者: vladcalin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def get_redis_connection(self):
        return redis.StrictRedis(connection_pool=self.connection_pool)
subscription_manager.py 文件源码 项目:graphql-python-subscriptions 作者: hballard 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, *args, **kwargs):
        redis.connection.socket = gevent.socket
        self.redis = redis.StrictRedis(host, port, *args, **kwargs)
        self.pubsub = self.redis.pubsub()
        self.subscriptions = {}
        self.sub_id_counter = 0
        self.greenlet = None


问题


面经


文章

微信
公众号

扫码关注公众号