mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-12 18:48:17 -06:00
Fixes #15962: support Redis Unix sockets
This commit is contained in:
parent
0cc2963e6f
commit
92900fd887
@ -103,6 +103,25 @@ REDIS = {
|
|||||||
It is highly recommended to keep the task and cache databases separate. Using the same database number on the
|
It is highly recommended to keep the task and cache databases separate. Using the same database number on the
|
||||||
same Redis instance for both may result in queued background tasks being lost during cache flushing events.
|
same Redis instance for both may result in queued background tasks being lost during cache flushing events.
|
||||||
|
|
||||||
|
### Using Redis with UNIX sockets
|
||||||
|
|
||||||
|
Redis may be configured by using the `URL` configuration setting,
|
||||||
|
instead of specifying `HOST`, `PORT`, and so on.
|
||||||
|
This can be used to specify a UNIX socket connection.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```python
|
||||||
|
REDIS = {
|
||||||
|
"tasks": {
|
||||||
|
"URL": "unix:///run/redis-netbox/redis.sock?db=0"
|
||||||
|
},
|
||||||
|
"caching": {
|
||||||
|
"URL": "unix:///run/redis-netbox/redis.sock?db=1"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Using Redis Sentinel
|
### Using Redis Sentinel
|
||||||
|
|
||||||
If you are using [Redis Sentinel](https://redis.io/topics/sentinel) for high-availability purposes, there is minimal
|
If you are using [Redis Sentinel](https://redis.io/topics/sentinel) for high-availability purposes, there is minimal
|
||||||
|
@ -241,6 +241,7 @@ if 'tasks' not in REDIS:
|
|||||||
TASKS_REDIS = REDIS['tasks']
|
TASKS_REDIS = REDIS['tasks']
|
||||||
TASKS_REDIS_HOST = TASKS_REDIS.get('HOST', 'localhost')
|
TASKS_REDIS_HOST = TASKS_REDIS.get('HOST', 'localhost')
|
||||||
TASKS_REDIS_PORT = TASKS_REDIS.get('PORT', 6379)
|
TASKS_REDIS_PORT = TASKS_REDIS.get('PORT', 6379)
|
||||||
|
TASKS_REDIS_URL = TASKS_REDIS.get('URL')
|
||||||
TASKS_REDIS_SENTINELS = TASKS_REDIS.get('SENTINELS', [])
|
TASKS_REDIS_SENTINELS = TASKS_REDIS.get('SENTINELS', [])
|
||||||
TASKS_REDIS_USING_SENTINEL = all([
|
TASKS_REDIS_USING_SENTINEL = all([
|
||||||
isinstance(TASKS_REDIS_SENTINELS, (list, tuple)),
|
isinstance(TASKS_REDIS_SENTINELS, (list, tuple)),
|
||||||
@ -269,7 +270,7 @@ CACHING_REDIS_SENTINEL_SERVICE = REDIS['caching'].get('SENTINEL_SERVICE', 'defau
|
|||||||
CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis'
|
CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis'
|
||||||
CACHING_REDIS_SKIP_TLS_VERIFY = REDIS['caching'].get('INSECURE_SKIP_TLS_VERIFY', False)
|
CACHING_REDIS_SKIP_TLS_VERIFY = REDIS['caching'].get('INSECURE_SKIP_TLS_VERIFY', False)
|
||||||
CACHING_REDIS_CA_CERT_PATH = REDIS['caching'].get('CA_CERT_PATH', False)
|
CACHING_REDIS_CA_CERT_PATH = REDIS['caching'].get('CA_CERT_PATH', False)
|
||||||
CACHING_REDIS_URL = f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}'
|
CACHING_REDIS_URL = REDIS['caching'].get('URL', f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}')
|
||||||
|
|
||||||
# Configure Django's default cache to use Redis
|
# Configure Django's default cache to use Redis
|
||||||
CACHES = {
|
CACHES = {
|
||||||
@ -669,6 +670,12 @@ if TASKS_REDIS_USING_SENTINEL:
|
|||||||
'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT
|
'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
elif TASKS_REDIS_URL:
|
||||||
|
RQ_PARAMS = {
|
||||||
|
'URL': TASKS_REDIS_URL,
|
||||||
|
'SSL': TASKS_REDIS_SSL,
|
||||||
|
'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required',
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
RQ_PARAMS = {
|
RQ_PARAMS = {
|
||||||
'HOST': TASKS_REDIS_HOST,
|
'HOST': TASKS_REDIS_HOST,
|
||||||
|
Loading…
Reference in New Issue
Block a user