redis_config

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis_config相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python
#-*- coding:utf-8 -*-
# by MO
#DATA 2018-08-02

import redis
import datetime


RedisHostMessage={
    'test':[{'Host':'***',
          'Port':6379,
          'Pwd':None}],

}


#查询slowlog
def SlowlogGet(*args):
    slowlog = connect.slowlog_get()
    for msg in slowlog:
        print(Host)
        for key in msg:
            if key == 'start_time':
                print(key, ':', datetime.datetime.fromtimestamp(msg[key]))        #进行时间转换,unix时间转换
                continue
            print(key,':',msg[key])
        print('----------ID-----------')
    # print(slowlog)

#查询redis配置
def ConfigGet(*args):
    config = connect.config_get(pattern='slowlog*')
    for key in config:
        print(key,config[key])

#修改redis配置
def ConfigSet(*args):
    # connect.config_set('slowlog-log-slower-than',50000)       #配置slowlog阈值时间50ms
    connect.slowlog_reset()                                     #重置slowlog list





for key in RedisHostMessage:
    for message in RedisHostMessage[key]:
        Host=message['Host']
        Port=message['Port']
        Pwd=message['Pwd']

        connect = redis.Redis(host=Host, port=Port, password=Pwd)
        # print(Host,Port,Pwd)
        # SlowlogGet(connect)
        ConfigSet(connect)
        SlowlogGet(connect)


以上是关于redis_config的主要内容,如果未能解决你的问题,请参考以下文章