Guest User

Untitled

a guest
Jan 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. def parse_info(response):
  2. "Parse the result of Redis's INFO command into a Python dict"
  3. info = {}
  4. def get_value(value):
  5. if ',' not in value:
  6. return value
  7. sub_dict = {}
  8. for item in value.split(',',2):
  9. k, v = item.split('=')
  10. try:
  11. sub_dict[k] = int(v)
  12. except ValueError:
  13. sub_dict[k] = v
  14. return sub_dict
  15. for line in response.splitlines():
  16. key, value = line.split(':')
  17. try:
  18. info[key] = int(value)
  19. except ValueError:
  20. info[key] = get_value(value)
  21. return info
Add Comment
Please, Sign In to add comment