示例#1
0
    def get_stats(host, port):
        if not host:
            return ''

        try:
            r_c = redis.get_connection(host, int(port))
            info = r_c.info()
            info['dbsize'] = r_c.dbsize()
            return info
        except Exception, e:
            return None
def comparison_test(redis, dynomite, debug):
    r_c = redis.get_connection()
    d_c = dynomite.get_connection()
    c = dual_run(r_c, d_c, debug)
    run_key_value_tests(c)

    # XLarge payloads
    run_key_value_tests(c, max_keys=10, max_payload=5 * 1024 * 1024)
    run_multikey_test(c)
    run_hash_tests(c, max_keys=10, max_fields=100)
    print("All test ran fine")
示例#3
0
def stop_node(node):
    """Stops `node`
    """
    pid = get_port_pid(node)

    if pid:
        r_c = redis.get_connection(node['host'], node['port'])
        print 'Saving data...'
        r_c.save()
        os.popen('kill %s' % pid)

    print 'Stopping node %s on: %s. Master node: %s' %\
            (node['name'], node['full_host'], node['master'])
示例#4
0
    def call_db(self, key, operation, *k, **kw):
        key_hash = hash(key)

        def pick_server(skey, servers):
            index = key_hash % len(servers)
            host, port = servers.pop(index)
            return host, port

        servers = list(self.servers)

        exp = Exception("unknown")

        while len(servers) > 0:
            host, port = pick_server(key, servers)

            try:
                db = get_connection(host, port)
                return getattr(db, operation)(*k, **kw)
            except Exception, e:
                print e
                exp = e
                continue
示例#5
0
    def call_db(self, key, operation, *k, **kw):
        key_hash = hash(key)

        def pick_server(skey, servers):
            index = key_hash % len(servers)
            host, port = servers.pop(index)
            return host, port

        servers = list(self.servers)

        exp = Exception("unknown")

        while len(servers) > 0:
            host, port = pick_server(key, servers)

            try:
                db = get_connection(host, port)
                return getattr(db, operation)(*k, **kw)
            except Exception, e:
                print e
                exp = e
                continue
示例#6
0
                host=cfs.get("HOST"),
                port=int(cfs.get("PORT")),
                db=cfs.get("DB"),
                password=cfs.get("PASSWORD"),
                max_connections=int(cfs.get("MAX_CONNECTIONS"))
            )
        return cls.__pool

    def __init__(self, cfs):
        super(RedisPool, self).__init__(cfs)

    def get_connection(self):
        return redis.StrictRedis(connection_pool=RedisPool.__pool.pool)

    def __getattr__(self, conn):
        return redis.StrictRedis(connection_pool=RedisPool.__pool.pool)


if __name__ = "__main__":
    redis_config = {
        "HOST": "192.168.10.53",
        "PORT": 6002,
        "DB": 3,
        "MAX_CONNECTIONS": 20,
        "PASSWORD": "******"}
    redis = RedisPool(redis_config)
    # 这里conn和redis.conn是等价的,用完之后都会被redispool 自动回收
    conn = redis.get_connection()
    print(redis.conn.dbsize())
    print(conn.dbsize())