From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Fri, 2 Dec 2022 21:54:15 +0000 (-0800) Subject: Adds support for database number specification X-Git-Tag: v1.10.2~2^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea38eb01b21844aadc99956b54cd3b65ffd458a1;p=thirdparty%2Fpaperless-ngx.git Adds support for database number specification --- diff --git a/src/paperless/settings.py b/src/paperless/settings.py index eef7344da8..3271ae7e6f 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -83,12 +83,21 @@ def _parse_redis_url(env_redis: Optional[str]) -> Tuple[str]: if "unix" in env_redis.lower(): # channels_redis socket format, looks like: # "unix:///path/to/redis.sock" - return (f"redis+socket:{path}", env_redis) + if "?db=" in env_redis: + path, number = path.split("?db=") + return (f"redis+socket:{path}?virtual_host={number}", env_redis) + else: + return (f"redis+socket:{path}", env_redis) elif "+socket" in env_redis.lower(): # celery socket style, looks like: # "redis+socket:///path/to/redis.sock" - return (env_redis, f"unix:{path}") + if "?virtual_host=" in env_redis: + # Virtual host (aka db number) + path, number = path.split("?virtual_host=") + return (env_redis, f"unix:{path}?db={number}") + else: + return (env_redis, f"unix:{path}") # Not a socket return (env_redis, env_redis) diff --git a/src/paperless/tests/test_settings.py b/src/paperless/tests/test_settings.py index fa839299fa..346f2d098a 100644 --- a/src/paperless/tests/test_settings.py +++ b/src/paperless/tests/test_settings.py @@ -97,7 +97,9 @@ class TestIgnoreDateParsing(TestCase): """ for input, expected in [ + # Nothing is set (None, ("redis://localhost:6379", "redis://localhost:6379")), + # celery style ( "redis+socket:///run/redis/redis.sock", ( @@ -105,6 +107,7 @@ class TestIgnoreDateParsing(TestCase): "unix:///run/redis/redis.sock", ), ), + # redis-py / channels-redis style ( "unix:///run/redis/redis.sock", ( @@ -112,6 +115,22 @@ class TestIgnoreDateParsing(TestCase): "unix:///run/redis/redis.sock", ), ), + # celery style with db + ( + "redis+socket:///run/redis/redis.sock?virtual_host=5", + ( + "redis+socket:///run/redis/redis.sock?virtual_host=5", + "unix:///run/redis/redis.sock?db=5", + ), + ), + # redis-py / channels-redis style with db + ( + "unix:///run/redis/redis.sock?db=10", + ( + "redis+socket:///run/redis/redis.sock?virtual_host=10", + "unix:///run/redis/redis.sock?db=10", + ), + ), ]: result = _parse_redis_url(input) self.assertTupleEqual(expected, result)