コード例 #1
0
def redis_info():
    name = request.args.get('name', None)
    if name == 'queue':
        redis_client = get_redis_client(QUEUE_REDIS_TYPE, QUEUE_REDIS_HOST,
                                        QUEUE_REDIS_PORT, QUEUE_REDIS_DB,
                                        QUEUE_REDIS_PWD, QUEUE_REDIS_NODES)
        redis_type = QUEUE_REDIS_TYPE
    elif name == 'filter':
        redis_client = get_redis_client(FILTER_REDIS_TYPE, FILTER_REDIS_HOST,
                                        FILTER_REDIS_PORT, FILTER_REDIS_DB,
                                        FILTER_REDIS_PWD, FILTER_REDIS_NODES)
        redis_type = FILTER_REDIS_TYPE
    elif name == 'rtask':
        redis_client = get_redis_client('single', RTASK_REDIS_HOST,
                                        RTASK_REDIS_POST, RTASK_REDIS_DB,
                                        RTASK_REDIS_PWD)
        redis_type = 'single'
    else:
        return redirect('/redis/')

    redisinfo = RedisInfo(redis_client)
    redis_info = redisinfo.info()
    redis_config = redisinfo.config_get()
    redis_clients = redisinfo.client_list()
    return render_template('redisinfo.html',
                           redis_info=redis_info,
                           redis_config=redis_config,
                           redis_clients=redis_clients,
                           redis_type=redis_type)
コード例 #2
0
def redis_check():
    redis_errors = list()
    try:
        queue_client = get_redis_client(QUEUE_REDIS_TYPE, QUEUE_REDIS_HOST,
                                        QUEUE_REDIS_PORT, QUEUE_REDIS_DB,
                                        QUEUE_REDIS_PWD, QUEUE_REDIS_NODES)
        queue_client.ping()
    except Exception as e:
        dest = 'Redis任务队列数据库连接失败!请检查Redis连接配置是否正确或者正常运行'
        redis_errors.append({'dest': dest, 'error': str(e)})
    if IS_FILTER:
        try:
            filter_client = get_redis_client(FILTER_REDIS_TYPE,
                                             FILTER_REDIS_HOST,
                                             FILTER_REDIS_PORT,
                                             FILTER_REDIS_DB, FILTER_REDIS_PWD,
                                             FILTER_REDIS_NODES)
            filter_client.ping()
        except Exception as e:
            dest = 'Redis数据去重数据库连接失败!请检查Redis连接配置是否正确或者正常运行'
            redis_errors.append({'dest': dest, 'error': str(e)})
    try:
        rtask_client = get_redis_client('single', RTASK_REDIS_HOST,
                                        RTASK_REDIS_POST, RTASK_REDIS_DB,
                                        RTASK_REDIS_PWD, None)
        rtask_client.ping()
    except Exception as e:
        dest = 'Redis RTask控制数据库连接失败!请检查Redis连接配置是否正确或者正常运行'
        redis_errors.append({'dest': dest, 'error': str(e)})
    return redis_errors
 def __init__(self):
     self.client = queues.get_redis_client(QUEUE_REDIS_TYPE,
                                           QUEUE_REDIS_HOST,
                                           QUEUE_REDIS_PORT, QUEUE_REDIS_DB,
                                           QUEUE_REDIS_PWD,
                                           QUEUE_REDIS_NODES)
     self.queues = queues.RedisQueues(conn=self.client)
コード例 #4
0
def redis_save():
    name = request.args.get('name', None)
    save_type = request.args.get('save_type', None)
    if name == 'queue':
        if QUEUE_REDIS_TYPE == 'single':
            timeout = 3
        else:
            timeout = None
        redis_client = get_redis_client(QUEUE_REDIS_TYPE,
                                        QUEUE_REDIS_HOST,
                                        QUEUE_REDIS_PORT,
                                        QUEUE_REDIS_DB,
                                        QUEUE_REDIS_PWD,
                                        QUEUE_REDIS_NODES,
                                        timeout=timeout)
    elif name == 'filter':
        if FILTER_REDIS_TYPE == 'single':
            timeout = 3
        else:
            timeout = None
        redis_client = get_redis_client(FILTER_REDIS_TYPE,
                                        FILTER_REDIS_HOST,
                                        FILTER_REDIS_PORT,
                                        FILTER_REDIS_DB,
                                        FILTER_REDIS_PWD,
                                        FILTER_REDIS_NODES,
                                        timeout=timeout)
    elif name == 'rtask':
        redis_client = get_redis_client('single', RTASK_REDIS_HOST,
                                        RTASK_REDIS_POST, RTASK_REDIS_DB,
                                        RTASK_REDIS_PWD)
    else:
        return redirect('/redis/')
    redisinfo = RedisInfo(redis_client)
    if save_type == 'save':
        redisinfo.save(is_bgsave=False)
    else:
        redisinfo.save(is_bgsave=True)
    return redirect('/redis/')
コード例 #5
0
def get_filter(filter_type='set',
               redis_type='single',
               host='127.0.0.1',
               port=6379,
               db=0,
               pwd=None,
               nodes=None,
               capacity=100000000,
               error_rate=0.00000001,
               key='task_filter'):
    redis_client = queues.get_redis_client(redis_type, host, port, db, pwd,
                                           nodes)
    if filter_type == 'set':
        filter_client = filter.RedisFilter(conn=redis_client, key=key)
    elif filter_type == 'bloom':
        filter_client = filter.BloomFilter(conn=redis_client,
                                           capacity=capacity,
                                           error_rate=error_rate,
                                           key=key)
    return filter_client
コード例 #6
0
               error_rate=0.00000001,
               key='task_filter'):
    redis_client = queues.get_redis_client(redis_type, host, port, db, pwd,
                                           nodes)
    if filter_type == 'set':
        filter_client = filter.RedisFilter(conn=redis_client, key=key)
    elif filter_type == 'bloom':
        filter_client = filter.BloomFilter(conn=redis_client,
                                           capacity=capacity,
                                           error_rate=error_rate,
                                           key=key)
    return filter_client


queue_client = queues.get_redis_client(QUEUE_REDIS_TYPE, QUEUE_REDIS_HOST,
                                       QUEUE_REDIS_PORT, QUEUE_REDIS_DB,
                                       QUEUE_REDIS_PWD, QUEUE_REDIS_NODES)
task_queues = queues.RedisQueues(conn=queue_client)
if IS_FILTER:
    filter_client = get_filter(FILTER_TYPE, FILTER_REDIS_TYPE,
                               FILTER_REDIS_HOST, FILTER_REDIS_PORT,
                               FILTER_REDIS_DB, FILTER_REDIS_PWD,
                               FILTER_REDIS_NODES, CAPACITY, ERROR_RATE,
                               TASK_NAME + ':filter')
control_pool = redis.ConnectionPool(host=RTASK_REDIS_HOST,
                                    port=RTASK_REDIS_POST,
                                    db=RTASK_REDIS_DB,
                                    password=RTASK_REDIS_PWD,
                                    encoding='utf-8',
                                    decode_responses=True)
control_client = redis.StrictRedis(connection_pool=control_pool)
コード例 #7
0
def redis_list():
    redis_errors = redis_check()
    if len(redis_errors) > 0:
        return render_template('rediserror.html', redis_errors=redis_errors)
    queue_client = get_redis_client(QUEUE_REDIS_TYPE, QUEUE_REDIS_HOST,
                                    QUEUE_REDIS_PORT, QUEUE_REDIS_DB,
                                    QUEUE_REDIS_PWD, QUEUE_REDIS_NODES)
    filter_client = get_redis_client(FILTER_REDIS_TYPE, FILTER_REDIS_HOST,
                                     FILTER_REDIS_PORT, FILTER_REDIS_DB,
                                     FILTER_REDIS_PWD, FILTER_REDIS_NODES)
    rtask_client = get_redis_client('single', RTASK_REDIS_HOST,
                                    RTASK_REDIS_POST, RTASK_REDIS_DB,
                                    RTASK_REDIS_PWD)
    redis_lists = list()

    redisinfo_queue = RedisInfo(queue_client)
    queue_info = redisinfo_queue.info()
    queue_dict = {'dest': 'Redis任务队列数据库', 'name': 'queue'}
    if QUEUE_REDIS_TYPE == 'single':
        queue_dict['type'] = '单机'
        queue_dict['ip_port'] = QUEUE_REDIS_HOST + ' : ' + str(
            QUEUE_REDIS_PORT)
        queue_dict['dbsize'] = queue_client.dbsize()
        queue_dict['clients'] = queue_info['connected_clients']
        queue_dict['used_memory'] = queue_info['used_memory_human']
    elif QUEUE_REDIS_TYPE == 'cluster':
        queue_dict['type'] = '集群'
        queue_dict['ip_port'] = [
            node['host'] + ' : ' + node['port'] for node in QUEUE_REDIS_NODES
        ]
        queue_dict['dbsize'] = [
            k + ' : ' + str(v) for k, v in queue_client.dbsize().items()
        ]
        queue_dict['clients'] = [
            k + ' : ' + str(v['connected_clients'])
            for k, v in queue_info.items()
        ]
        queue_dict['used_memory'] = [
            k + ' : ' + v['used_memory_human'] for k, v in queue_info.items()
        ]
    redis_lists.append(queue_dict)

    if IS_FILTER:
        redisinfo_filter = RedisInfo(filter_client)
        filter_info = redisinfo_filter.info()
        filter_dict = {'dest': 'Redis数据去重数据库', 'name': 'filter'}
        if FILTER_REDIS_TYPE == 'single':
            filter_dict['type'] = '单机'
            filter_dict['ip_port'] = FILTER_REDIS_HOST + ' : ' + str(
                FILTER_REDIS_PORT)
            filter_dict['dbsize'] = filter_client.dbsize()
            filter_dict['clients'] = filter_info['connected_clients']
            filter_dict['used_memory'] = filter_info['used_memory_human']
        elif FILTER_REDIS_TYPE == 'cluster':
            filter_dict['type'] = '集群'
            filter_dict['ip_port'] = [
                node['host'] + ' : ' + node['port']
                for node in FILTER_REDIS_NODES
            ]
            filter_dict['dbsize'] = [
                k + ' : ' + str(v) for k, v in filter_client.dbsize().items()
            ]
            filter_dict['clients'] = [
                k + ' : ' + str(v['connected_clients'])
                for k, v in filter_info.items()
            ]
            filter_dict['used_memory'] = [
                k + ' : ' + v['used_memory_human']
                for k, v in filter_info.items()
            ]
        redis_lists.append(filter_dict)

    redisinfo_rtask = RedisInfo(rtask_client)
    rtask_info = redisinfo_rtask.info()
    rtask_dict = {'dest': 'Redis RTask控制数据库', 'name': 'rtask'}
    rtask_dict['type'] = '单机'
    rtask_dict['ip_port'] = RTASK_REDIS_HOST + ' : ' + str(RTASK_REDIS_POST)
    rtask_dict['dbsize'] = rtask_client.dbsize()
    rtask_dict['clients'] = rtask_info['connected_clients']
    rtask_dict['used_memory'] = rtask_info['used_memory_human']
    redis_lists.append(rtask_dict)
    return render_template('redis.html', redis_lists=redis_lists)