mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Adds support for database number specification
This commit is contained in:
parent
01d070b882
commit
ea38eb01b2
@ -83,11 +83,20 @@ def _parse_redis_url(env_redis: Optional[str]) -> Tuple[str]:
|
|||||||
if "unix" in env_redis.lower():
|
if "unix" in env_redis.lower():
|
||||||
# channels_redis socket format, looks like:
|
# channels_redis socket format, looks like:
|
||||||
# "unix:///path/to/redis.sock"
|
# "unix:///path/to/redis.sock"
|
||||||
|
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)
|
return (f"redis+socket:{path}", env_redis)
|
||||||
|
|
||||||
elif "+socket" in env_redis.lower():
|
elif "+socket" in env_redis.lower():
|
||||||
# celery socket style, looks like:
|
# celery socket style, looks like:
|
||||||
# "redis+socket:///path/to/redis.sock"
|
# "redis+socket:///path/to/redis.sock"
|
||||||
|
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}")
|
return (env_redis, f"unix:{path}")
|
||||||
|
|
||||||
# Not a socket
|
# Not a socket
|
||||||
|
@ -97,7 +97,9 @@ class TestIgnoreDateParsing(TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
for input, expected in [
|
for input, expected in [
|
||||||
|
# Nothing is set
|
||||||
(None, ("redis://localhost:6379", "redis://localhost:6379")),
|
(None, ("redis://localhost:6379", "redis://localhost:6379")),
|
||||||
|
# celery style
|
||||||
(
|
(
|
||||||
"redis+socket:///run/redis/redis.sock",
|
"redis+socket:///run/redis/redis.sock",
|
||||||
(
|
(
|
||||||
@ -105,6 +107,7 @@ class TestIgnoreDateParsing(TestCase):
|
|||||||
"unix:///run/redis/redis.sock",
|
"unix:///run/redis/redis.sock",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
# redis-py / channels-redis style
|
||||||
(
|
(
|
||||||
"unix:///run/redis/redis.sock",
|
"unix:///run/redis/redis.sock",
|
||||||
(
|
(
|
||||||
@ -112,6 +115,22 @@ class TestIgnoreDateParsing(TestCase):
|
|||||||
"unix:///run/redis/redis.sock",
|
"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)
|
result = _parse_redis_url(input)
|
||||||
self.assertTupleEqual(expected, result)
|
self.assertTupleEqual(expected, result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user