问题需求:
  redis内存暴增,后来发现有很多设置永久不过期。 解决:查找出来之后针对前缀批量设置过期时间 (过期时间与开发沟通 保证服务不受影响) 来源于网上杨一的代码 正好解决了我遇到的问题 在这里记录一下。 1 # encoding: utf-8 import redis
import random
import string
import time
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password="", db=0)
r = redis.Redis(connection_pool=pool) def random_str():
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(7)) def init_keys():
start_time = time.time()
for i in xrange(0, 20):
key_name = 'dba_'+str(i)
value_name = random_str()
r.set(key_name, value_name)
print 'initial keys successfully,use time:', time.time() - start_time def del_keys_without_pipe():
start_time = time.time()
result_length = 0
for key in r.scan_iter(match='rawdata_lastStatus_0015000200*', count=1000):
r.delete(key)
result_length += 1
print "normal ways end at:", time.time() - start_time
print "normal ways delete numbers:", result_length def del_keys_with_pipe():
start_time = time.time()
result_length = 0
pipe = r.pipeline()
for key in r.scan_iter(match='rawdata_*_otherTrades', count=1000):
pipe.expire(key,120)
result_length += 1
if result_length % 1000 == 0:
pipe.execute()
time.sleep(1)
pip_time = time.time()
print "use pipeline scan time ", time.time() - start_time
pipe.execute() print "use pipeline end at:", time.time() - pip_time
print "use pipeline ways delete numbers:", result_length def main():
# init_keys()
# del_keys_without_pipe()
# init_keys()
del_keys_with_pipe() if __name__ == '__main__':
main()

最新文章

  1. C#窗体文件的操作
  2. theano报一种float类型错误的处理办法
  3. Writing Your Own jQuery Plugins
  4. 使用Java正则表达式提取字符串中的数字一例
  5. node.js模块之Buffer模块
  6. Asp.net Mvc 自定义Session (二)
  7. NSUserDefaults偶尔/有时候保存数据会失败/失效
  8. pg_dump实例详解(备份postgresql和greenplum数据库)
  9. iscc2016 pwn部分writeup
  10. php时间戳与时间转换
  11. sql定时自动备份(定时作业)
  12. Redis数据类型之Hash(二)
  13. 透过源码看看Redis中如何计算QPS
  14. java 中的 instanceof
  15. RubyMine 2017.3.2破解教程
  16. Node.js实战项目学习系列(3) CommonJS 模块化规范
  17. [PA2014]Iloczyn
  18. 初识linux------用户和用户组
  19. Android MediaScanner 总纲
  20. python六剑客:map()、lambda()、filter()、reduce()、推导类表、切片

热门文章

  1. HTML(一)简介,元素
  2. JIRA使用过程出现问题整理解答
  3. hdu 6016 Count the Sheep(思维)
  4. POJ2084 Game of Connections 卡特兰数 关于卡特兰数经典的几个问题
  5. elementUI树状图竖向滚动条和横向滚动条问题
  6. 机器学习Label Encoder和One Hot Encoder
  7. 二进制协议gob及msgpack介绍
  8. ajax交互案例
  9. 作为一名Android开发者,你有过迷茫吗?
  10. 【第十三篇】mvc下载文件,包括配置xml保护服务端文件不被外链直接访问