redistest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import time
  2. import json
  3. import random
  4. import dataset
  5. import redis
  6. import string
  7. import logging
  8. import sys
  9. from logging.handlers import SysLogHandler
  10. import socket
  11. #_LOG_SERVER = ('172.105.219.42', 514)
  12. _LOG_SERVER = ('hhh.ptt.cx', 514)
  13. logger = logging.getLogger('Jared')
  14. logger.setLevel(logging.FATAL)
  15. handler1 = SysLogHandler(
  16. address=_LOG_SERVER,socktype=socket.SOCK_DGRAM)
  17. formatter1 = logging.Formatter('%(module)s: %(process)s - %(name)s - %(levelname)s - %(lineno)s - %(message)s')
  18. handler1.setFormatter(formatter1)
  19. logger.addHandler(handler1)
  20. #logger.fatal()
  21. ###logging.setLoggerClass('cc')
  22. r = logging.makeLogRecord({'msg': '測試訊息','filename':'fname','funcName':'fcname','lineno':1234,'threadName':'thname','process':54321})
  23. handler1.handle(r)
  24. #logger.
  25. #logger.fatal('ttt')
  26. #logger.info('this is a test')
  27. d = {'clientip': '192.168.0.999', 'user': 'fbloggs'}
  28. logger.fatal('測試一下',extra=d,exc_info=1)
  29. #logger.debug('中文測試')
  30. sys.exit()
  31. def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
  32. return ''.join(random.choice(chars) for _ in range(size))
  33. r = redis.Redis(host='db.ptt.cx', port=6379, db=1,password='choozmo9')
  34. #r.set('hbeat:20220319', 1, ex=90)
  35. for key in r.scan_iter("hbeat:*"):
  36. print(key)
  37. # delete the key
  38. #r.get()
  39. # r.delete(key)
  40. #r = redis.Redis(host='db.ptt.cx', port=6379, db=1)
  41. #len=r.llen('test')
  42. #lst=r.lrange('test',0,len-1)
  43. #print(lst)
  44. #r.delete('test')
  45. #for i in range(5):
  46. # js={'name':id_generator(),'id':random.randint(111111,999999)}
  47. # r.lpush('test',json.dumps(js))
  48. #p = r.pubsub(ignore_subscribe_messages=True)