self_example/Spider/Chapter10_模拟登录/大规模账号池的搭建/AccountPool/accountpool/utils/parse.py

14 lines
473 B
Python

import re
def parse_redis_connection_string(connection_string):
"""
parse a redis connection string, for example:
redis://[password]@host:port
rediss://[password]@host:port
:param connection_string:
:return:
"""
result = re.match('rediss?:\/\/(.*?)@(.*?):(\d+)\/(\d+)', connection_string)
return result.group(2), int(result.group(3)), (result.group(1) or None), (result.group(4) or 0) if result \
else ('localhost', 6379, None)