当前位置: 首页>>代码示例>>Python>>正文


Python sentinel.Sentinel方法代码示例

本文整理汇总了Python中redis.sentinel.Sentinel方法的典型用法代码示例。如果您正苦于以下问题:Python sentinel.Sentinel方法的具体用法?Python sentinel.Sentinel怎么用?Python sentinel.Sentinel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.sentinel的用法示例。


在下文中一共展示了sentinel.Sentinel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def __init__(self, connection_str, db=0, project=None,
                 service=None, host=None, conf=cfg.CONF, **kwargs):
        """Redis driver for OSProfiler."""

        super(RedisSentinel, self).__init__(connection_str, project=project,
                                            service=service, host=host,
                                            conf=conf, **kwargs)
        try:
            from redis.sentinel import Sentinel
        except ImportError:
            raise exc.CommandError(
                "To use this command, you should install "
                "'redis' manually. Use command:\n "
                "'pip install redis'.")

        self.conf = conf
        socket_timeout = self.conf.profiler.socket_timeout
        parsed_url = parser.urlparse(self.connection_str)
        sentinel = Sentinel([(parsed_url.hostname, int(parsed_url.port))],
                            password=parsed_url.password,
                            socket_timeout=socket_timeout)
        self.db = sentinel.master_for(self.conf.profiler.sentinel_service_name,
                                      socket_timeout=socket_timeout) 
开发者ID:openstack,项目名称:osprofiler,代码行数:25,代码来源:redis_driver.py

示例2: sentinel_connect

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def sentinel_connect(self, master_name):
        url = urlparse.urlparse(self.schedule_url)

        def parse_host(s):
            if ':' in s:
                host, port = s.split(':', 1)
                port = int(port)
            else:
                host = s
                port = 26379

            return host, port

        if '@' in url.netloc:
            auth, hostspec = url.netloc.split('@', 1)
        else:
            auth = None
            hostspec = url.netloc

        if auth and ':' in auth:
            _, password = auth.split(':', 1)
        else:
            password = None
        path = url.path
        if path.startswith('/'):
            path = path[1:]
        hosts = [parse_host(s) for s in hostspec.split(',')]
        sentinel = Sentinel(hosts, password=password, db=path)
        master = sentinel.master_for(master_name)
        return master 
开发者ID:liuliqiang,项目名称:redisbeat,代码行数:32,代码来源:scheduler.py

示例3: get_database

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def get_database(config, master=True):
    if config['sentinel']:
        sentinal = Sentinel(config['sentinel'], socket_timeout=0.1,
                            password=config['redis_password'], db=config['redis_database'])
        if master:
            return sentinal.master_for(config['sentinel_cluster_name'])
        else:
            return sentinal.slave_for(config['sentinel_cluster_name'])
    else:
        return Redis.from_url(config['redis']) 
开发者ID:openprocurement,项目名称:openprocurement.auction,代码行数:12,代码来源:utils.py

示例4: setUp

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def setUp(self):
        """ Clear all spans before a test run """
        self.recorder = tracer.recorder
        self.recorder.clear_spans()

        # self.sentinel = Sentinel([(testenv['redis_host'], 26379)], socket_timeout=0.1)
        # self.sentinel_master = self.sentinel.discover_master('mymaster')
        # self.client = redis.Redis(host=self.sentinel_master[0])

        self.client = redis.Redis(host=testenv['redis_host']) 
开发者ID:instana,项目名称:python-sensor,代码行数:12,代码来源:test_redis.py

示例5: get_connection

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def get_connection(self, is_read_only=False) -> redis.StrictRedis:
        """
        Gets a StrictRedis connection for normal redis or for redis sentinel
         based upon redis mode in configuration.

        :type is_read_only: bool
        :param is_read_only: In case of redis sentinel, it returns connection
         to slave

        :return: Returns a StrictRedis connection
        """
        if self.connection is not None:
            return self.connection

        if self.is_sentinel:
            kwargs = dict()
            if self.password:
                kwargs["password"] = self.password
            sentinel = Sentinel([(self.host, self.port)], **kwargs)
            if is_read_only:
                connection = sentinel.slave_for(self.sentinel_service,
                                                decode_responses=True)
            else:
                connection = sentinel.master_for(self.sentinel_service,
                                                 decode_responses=True)
        else:
            connection = redis.StrictRedis(host=self.host, port=self.port,
                                           decode_responses=True,
                                           password=self.password)
        self.connection = connection
        return connection 
开发者ID:biplap-sarkar,项目名称:pylimit,代码行数:33,代码来源:redis_helper.py

示例6: client

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def client(self):
        if not self._redis_connection:
            sentinel = Sentinel(
                self.sentinel_conf.get('sentinels'),
                min_other_sentinels=self.sentinel_conf.get("min_other_sentinels", 0),
                password=self.sentinel_conf.get("password"),
                socket_timeout=self.sentinel_conf.get("sentinel_timeout", None)
            )
            redis_connection = sentinel.master_for(self.sentinel_conf.get("service_name"), Redis,
                                                   socket_timeout=self.sentinel_conf.get("socket_timeout"))
            self._redis_connection.append(redis_connection)
        return self._redis_connection[0] 
开发者ID:tsuru,项目名称:rpaas,代码行数:14,代码来源:celery_sentinel.py

示例7: patch_flower_broker

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def patch_flower_broker():
    import tornado.web  # NOQA
    from flower.views.broker import Broker
    from flower.utils.broker import Redis as RedisBroker
    from urlparse import urlparse

    old_new = Broker.__new__

    def new_new(_, cls, broker_url, *args, **kwargs):
        scheme = urlparse(broker_url).scheme
        if scheme == 'redis-sentinel':
            from rpaas.tasks import app
            opts = app.conf.BROKER_TRANSPORT_OPTIONS
            s = Sentinel(
                opts['sentinels'],
                password=opts['password'],
            )
            host, port = s.discover_master(opts['service_name'])
            return RedisBroker('redis://:{}@{}:{}'.format(opts['password'], host, port))
        else:
            old_new(cls, broker_url, *args, **kwargs)
    Broker.__new__ = classmethod(new_new)

    from flower.command import settings
    from flower.views.tasks import TasksView
    from rpaas import flower_uimodules
    settings['ui_modules'] = flower_uimodules

    def new_render(self, *args, **kwargs):
        self._ui_module('FixTasks', self.application.ui_modules['FixTasks'])(self)
        super(TasksView, self).render(*args, **kwargs)

    TasksView.render = new_render 
开发者ID:tsuru,项目名称:rpaas,代码行数:35,代码来源:celery_sentinel.py

示例8: get_client

# 需要导入模块: from redis import sentinel [as 别名]
# 或者: from redis.sentinel import Sentinel [as 别名]
def get_client(conf, scripts=None):
    if redis is None:
        raise RuntimeError("Redis Python module is unavailable")
    parsed_url = parse.urlparse(conf.redis_url)
    options = parse.parse_qs(parsed_url.query)

    kwargs = {}
    if parsed_url.hostname:
        kwargs['host'] = parsed_url.hostname
        if parsed_url.port:
            kwargs['port'] = parsed_url.port
    else:
        if not parsed_url.path:
            raise ValueError("Expected socket path in parsed urls path")
        kwargs['unix_socket_path'] = parsed_url.path
    if parsed_url.password:
        kwargs['password'] = parsed_url.password

    for a in CLIENT_ARGS:
        if a not in options:
            continue
        if a in CLIENT_BOOL_ARGS:
            v = utils.strtobool(options[a][-1])
        elif a in CLIENT_LIST_ARGS:
            v = options[a]
        elif a in CLIENT_INT_ARGS:
            v = int(options[a][-1])
        else:
            v = options[a][-1]
        kwargs[a] = v

    # Ask the sentinel for the current master if there is a
    # sentinel arg.
    if 'sentinel' in kwargs:
        sentinel_hosts = [
            tuple(fallback.split(':'))
            for fallback in kwargs.get('sentinel_fallback', [])
        ]
        sentinel_hosts.insert(0, (kwargs['host'], kwargs['port']))
        sentinel_server = sentinel.Sentinel(
            sentinel_hosts,
            socket_timeout=kwargs.get('socket_timeout'))
        sentinel_name = kwargs['sentinel']
        del kwargs['sentinel']
        if 'sentinel_fallback' in kwargs:
            del kwargs['sentinel_fallback']
        # The client is a redis.StrictRedis using a
        # Sentinel managed connection pool.
        client = sentinel_server.master_for(sentinel_name, **kwargs)
    else:
        client = redis.StrictRedis(**kwargs)

    if scripts is not None:
        scripts = {
            name: client.register_script(code)
            for name, code in six.iteritems(scripts)
        }

    return client, scripts 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:61,代码来源:redis.py


注:本文中的redis.sentinel.Sentinel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。