redis_change_expiretime_2.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python
  2. # --coding:utf-8--
  3. import redis
  4. import os ,sys ,time
  5. def redis_scan():
  6. try:
  7. redisconn = redis.Redis(host='r-bp1lsmidgnw4w7n1pi.redis.rds.aliyuncs.com', password="Wqsd@2019", port=6379,
  8. db=0)
  9. except Exception as e:
  10. print("connect redis error")
  11. sys.exit(1)
  12. cursor = 1
  13. isNoe = True
  14. file = open('rediskey', 'a+')
  15. while cursor != 0:
  16. if isNoe:
  17. cursor = 0
  18. isNoe = False
  19. key = redisconn.scan(cursor, count=10000) #每次拿2000个key
  20. time.sleep(0.05)
  21. if len(key[1]) == 0:
  22. print("key scan finish")
  23. else:
  24. for n in key[1]:
  25. n = bytes.decode(n)
  26. # MESSAGE_MERGE_LIST_IDS
  27. # MESSAGE_MERGE_LIST_COUNT
  28. if n[:23] == "MESSAGE_MERGE_LIST_SORT":
  29. # MESSAGE_MERGE_LIST_SORT
  30. redisconn.expire(n,2592000)
  31. print(n)
  32. cursor = key[0]
  33. file.close()
  34. redis_scan()