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


Python rediscluster.StrictRedisCluster方法代码示例

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


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

示例1: __init__

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [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

示例2: get_redis_client

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def get_redis_client(redis_type='single', host='127.0.0.1', port=6379, db=0, pwd=None, nodes=None, timeout=3):
    if redis_type == 'single':
        pool = redis.ConnectionPool(host=host, port=port, db=db, password=pwd, socket_timeout=timeout, socket_connect_timeout=timeout, encoding='utf-8', decode_responses=True)
        client = redis.StrictRedis(connection_pool=pool)
    else:
        client = rediscluster.StrictRedisCluster(startup_nodes=nodes, decode_responses=True, socket_timeout=timeout, socket_connect_timeout=timeout)
    return client 
开发者ID:HatBoy,项目名称:RTask,代码行数:9,代码来源:queues.py

示例3: test_api

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def test_api(self):
        comm.start_cluster('127.0.0.1', 7100)
        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        comm.replicate('127.0.0.1', 7100, '127.0.0.1', 7102)
        time.sleep(1)

        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)

        for i in range(20):
            rc.set('key_%s' % i, 'value_%s' % i)
        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(3, len(nodes))
        self.assertEqual(
            list(range(8192)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8192, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)

        comm.quit_cluster('127.0.0.1', 7101)

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(
            list(range(16384)), nodes[('127.0.0.1', 7100)].assigned_slots)

        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        for i in range(20):
            rc.delete('key_%s' % i)

        comm.quit_cluster('127.0.0.1', 7102)
        comm.shutdown_cluster('127.0.0.1', 7100) 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:42,代码来源:replicates.py

示例4: test_quit_problems

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def test_quit_problems(self):
        comm.start_cluster('127.0.0.1', 7100)
        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        comm.replicate('127.0.0.1', 7100, '127.0.0.1', 7102)
        time.sleep(1)

        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)

        for i in range(20):
            rc.set('key_%s' % i, 'value_%s' % i)
        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(3, len(nodes))
        self.assertEqual(
            list(range(8192)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8192, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)
        for i in range(20):
            rc.delete('key_%s' % i)

        six.assertRaisesRegex(self, ValueError,
                              '^The master still has slaves$',
                              comm.quit_cluster, '127.0.0.1', 7100)
        comm.quit_cluster('127.0.0.1', 7102)
        comm.quit_cluster('127.0.0.1', 7101)
        six.assertRaisesRegex(self, ValueError, '^This is the last node',
                              comm.quit_cluster, '127.0.0.1', 7100)
        comm.shutdown_cluster('127.0.0.1', 7100) 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:38,代码来源:replicates.py

示例5: test_start_with_max_slots_set

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def test_start_with_max_slots_set(self):
        comm.create([('127.0.0.1', 7100)], max_slots=7000)
        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))
        rc.delete('key')
        comm.shutdown_cluster('127.0.0.1', 7100)

        comm.start_cluster_on_multi(
            [('127.0.0.1', 7100), ('127.0.0.1', 7101)], max_slots=7000)
        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))
        rc.delete('key')
        comm.quit_cluster('127.0.0.1', 7101)
        comm.shutdown_cluster('127.0.0.1', 7100) 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:28,代码来源:basic_api.py

示例6: _initialize

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def _initialize(self):
        """Read the SharQ configuration and set appropriate
        variables. Open a redis connection pool and load all
        the Lua scripts.
        """
        self._key_prefix = self._config.get('redis', 'key_prefix')
        self._job_expire_interval = int(
            self._config.get('sharq', 'job_expire_interval')
        )
        self._default_job_requeue_limit = int(
            self._config.get('sharq', 'default_job_requeue_limit')
        )

        # initalize redis
        redis_connection_type = self._config.get('redis', 'conn_type')
        db = self._config.get('redis', 'db')
        if redis_connection_type == 'unix_sock':
            self._r = redis.StrictRedis(
                db=db,
                unix_socket_path=self._config.get('redis', 'unix_socket_path')
            )
        elif redis_connection_type == 'tcp_sock':
            isclustered = False    
            if self._config.has_option('redis', 'clustered'):
                isclustered = self._config.getboolean('redis', 'clustered')
                
            if isclustered:
                startup_nodes = [{"host":self._config.get('redis', 'host'), "port":self._config.get('redis', 'port')}]
                self._r = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=False, skip_full_coverage_check=True)
            else:
                self._r = redis.StrictRedis(
                    db=db,
                    host=self._config.get('redis', 'host'),
                    port=self._config.get('redis', 'port')
                )
        self._load_lua_scripts() 
开发者ID:plivo,项目名称:sharq,代码行数:38,代码来源:queue.py

示例7: test_join_no_load

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def test_join_no_load(self):
        comm.create([('127.0.0.1', 7100)])

        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)
        rc.set('x-{h-893}', 'y')
        rc.set('y-{h-893}', 'zzZ')
        rc.set('z-{h-893}', 'w')
        rc.incr('h-893')

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7101)
        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]

        self.assertEqual(16384, len(n7100.assigned_slots))
        self.assertEqual(0, len(n7101.assigned_slots))

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7102)
        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [0])

        nodes = base.list_nodes('127.0.0.1', 7102)
        self.assertEqual(3, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]
        n7102 = nodes[('127.0.0.1', 7102)]

        self.assertEqual(16383, len(n7100.assigned_slots))
        self.assertEqual(1, len(n7101.assigned_slots))
        self.assertEqual(0, len(n7102.assigned_slots))

        try:
            t = n7101.get_conn()
            m = t.execute('get', 'h-893')
            self.assertEqual('1', m)

            m = t.execute('get', 'y-{h-893}')
            self.assertEqual('zzZ', m)

            comm.quit_cluster('127.0.0.1', 7102)
            comm.quit_cluster('127.0.0.1', 7101)
            t = n7100.get_conn()

            rc.delete('x-{h-893}')
            rc.delete('y-{h-893}')
            rc.delete('z-{h-893}')
            rc.delete('h-893')
            comm.shutdown_cluster('127.0.0.1', 7100)
        finally:
            n7100.close()
            n7101.close() 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:58,代码来源:basic_api.py

示例8: __init__

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def __init__(self, cfg, kind=None, logger=None):
        try:
            self.__type = cfg.get("TYPE", "Redis")
            self.__db = cfg.get("DATABASE", 0)
            if not self.__type:
                self.__r = redis.StrictRedis(host='localhost', port=6379, db=self.__db)
                self.__type = 'TCP_SOCKET'

            if self.__type == "UNIX_DOMAIN":
                self.__r = redis.Redis(unix_socket_path='/tmp/redis.sock', db=self.__db)

            elif self.__type == "REDIS_CLUSTER":
                from rediscluster import StrictRedisCluster
                from ast import literal_eval
                if kind.upper() == "JAVA":
                    nodes = literal_eval(cfg.get("JAVA_NODES", "RedisCluster"))
                elif kind.upper() == "NATIVE":
                    nodes = literal_eval(cfg.get("NATIVE_NODES", "RedisCluster"))
                elif kind.upper() == "RESULT":
                    nodes = literal_eval(cfg.get("RESULT_NODES", "RedisCluster"))
                else:
                    logger.error("Unknown kind of REDIS_CLUSTER: %s", kind)
                self.__r = StrictRedisCluster(startup_nodes=nodes, decode_responses=True)

            elif self.__type == "TCP_SOCKET":
                port = cfg.get("PORT", "Redis")
                host = cfg.get("HOST", "Redis")
                self.__r = redis.StrictRedis(host=host, port=port, db=self.__db)

            else:
                if logger:
                    logger.error("Invalid redis cfg type %s", self.__type)
                print("Invalid redis cfg type %s" % (self.__type))
                return None

            # check if Redis server is available
            response = self.__r.client_list()

        except (redis.exceptions.ConnectionError,
                redis.exceptions.BusyLoadingError):
            if logger:
                logger.error("Redis connection error")
            print("Redis connection error")
            return None

        except ImportError as e:
            if logger:
                logger.error("Redis module not available. Please install.")
            print("Redis module not available. Please install.")
            return None 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:52,代码来源:gpl.plugin.py

示例9: __init__

# 需要导入模块: import rediscluster [as 别名]
# 或者: from rediscluster import StrictRedisCluster [as 别名]
def __init__(self, cfg, kind=None, logger=None):
        try:
            self.__type = cfg.get("TYPE", "Redis")
            self.__db = cfg.get("DATABASE", 0)
            if not self.__type:
                self.__r = redis.StrictRedis(host='localhost', port=6379, db=self.__db)
                self.__type = 'TCP_SOCKET'

            if self.__type == "UNIX_DOMAIN":
                self.__r = redis.Redis(unix_socket_path='/tmp/redis.sock', db=self.__db)

            elif self.__type == "REDIS_CLUSTER":
                from rediscluster import StrictRedisCluster
                import json
                if kind.upper() == "JAVA":
                    nodes = json.loads(cfg.get("JAVA_NODES", "RedisCluster"))
                elif kind.upper() == "NATIVE":
                    nodes = json.loads(cfg.get("NATIVE_NODES", "RedisCluster"))
                elif kind.upper() == "RESULT":
                    nodes = json.loads(cfg.get("RESULT_NODES", "RedisCluster"))
                else:
                    logger.error("Unknown kind of REDIS_CLUSTER: %s", kind)
                self.__r = StrictRedisCluster(startup_nodes=nodes, decode_responses=True)

            elif self.__type == "TCP_SOCKET":
                port = cfg.get("PORT", "Redis")
                host = cfg.get("HOST", "Redis")
                self.__r = redis.StrictRedis(host=host, port=port, db=self.__db)

            else:
                if logger:
                    logger.error("Invalid redis cfg type %s", self.__type)
                print("Invalid redis cfg type %s" % (self.__type))
                return None

            # check if Redis server is available
            response = self.__r.client_list()

        except (redis.exceptions.ConnectionError,
                redis.exceptions.BusyLoadingError):
            if logger:
                logger.error("Redis connection error")
            print("Redis connection error")
            return None

        except ImportError as e:
            if logger:
                logger.error("Redis module not available. Please install.")
            print("Redis module not available. Please install.")
            return None 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:52,代码来源:redisclient.py


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