python2监控redis读取速度

1、主要是导入redis模块,如果不存在则执行pip install redis 安装。

#!/usr/bin/env python
import redis
import time
ip='10.12.41.16'
password='Tvgpg#cdz'
r=redis.Redis(host=ip,password=password,port=16379,db=0)
while True:
  localtime = time.asctime( time.localtime(time.time()) )
  start_time = time.time()
  res=r.get('k1')
  end_time = time.time()
  time.sleep(5)
  running_time = end_time - start_time
  print("keys:%s running_time : %.5f sec localtime:%s" %(res,running_time,localtime))

2、放到后台运行并写入文件

[root@db redis_monitor]# nohup  -u check_python.py >redis_out.txt &

  

posted @ 2020-05-01 23:03  西门运维  阅读(350)  评论(0编辑  收藏  举报