39def initialize():
40 global _CLIENT
41 redis_url = get_setting('redis.url')
42 if not redis_url:
43 return False
44 try:
45
46 _CLIENT = redis.Redis.from_url(redis_url)
47
48
49 kwargs = _CLIENT.get_connection_kwargs().copy()
50 kwargs.pop('password', None)
51 kwargs = ' '.join([f'{k}={v!r}' for k, v in kwargs.items()])
52 logger.info("connecting to Redis %s", kwargs)
53
54
55 _CLIENT.ping()
56
57
58 logger.info("connected to Redis")
59 return True
60 except redis.exceptions.RedisError as e:
61 _CLIENT = None
62 _pw = pwd.getpwuid(os.getuid())
63 logger.exception("[%s (%s)] can't connect redis DB ...", _pw.pw_name, _pw.pw_uid)
64 if redis_url == OLD_REDIS_URL_DEFAULT_URL and isinstance(e, redis.exceptions.ConnectionError):
65 logger.info(
66 "You can safely ignore the above Redis error if you don't use Redis. "
67 "You can remove this error by setting redis.url to false in your settings.yml."
68 )
69 return False