Skip to content

Commit 60f5dd7

Browse files
Support Redis Unix sockets (netbox-community#16227)
* Fixes netbox-community#15962: support Redis Unix sockets * Clean up language & remove obsolete note --------- Co-authored-by: Jeremy Stretch <[email protected]>
1 parent 5b83d70 commit 60f5dd7

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

docs/configuration/required-parameters.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,25 @@ REDIS = {
9494
}
9595
```
9696

97-
!!! note
98-
If you are upgrading from a NetBox release older than v2.7.0, please note that the Redis connection configuration
99-
settings have changed. Manual modification to bring the `REDIS` section inline with the above specification is
100-
necessary
101-
10297
!!! warning
10398
It is highly recommended to keep the task and cache databases separate. Using the same database number on the
10499
same Redis instance for both may result in queued background tasks being lost during cache flushing events.
105100

101+
### UNIX Socket Support
102+
103+
Redis may alternatively be configured by specifying a complete URL instead of individual components. This approach supports the use of a UNIX socket connection. For example:
104+
105+
```python
106+
REDIS = {
107+
'tasks': {
108+
'URL': 'unix:///run/redis-netbox/redis.sock?db=0'
109+
},
110+
'caching': {
111+
'URL': 'unix:///run/redis-netbox/redis.sock?db=1'
112+
},
113+
}
114+
```
115+
106116
### Using Redis Sentinel
107117

108118
If you are using [Redis Sentinel](https://redis.io/topics/sentinel) for high-availability purposes, there is minimal

netbox/netbox/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def _setting(name, default=None):
242242
TASKS_REDIS = REDIS['tasks']
243243
TASKS_REDIS_HOST = TASKS_REDIS.get('HOST', 'localhost')
244244
TASKS_REDIS_PORT = TASKS_REDIS.get('PORT', 6379)
245+
TASKS_REDIS_URL = TASKS_REDIS.get('URL')
245246
TASKS_REDIS_SENTINELS = TASKS_REDIS.get('SENTINELS', [])
246247
TASKS_REDIS_USING_SENTINEL = all([
247248
isinstance(TASKS_REDIS_SENTINELS, (list, tuple)),
@@ -270,7 +271,7 @@ def _setting(name, default=None):
270271
CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis'
271272
CACHING_REDIS_SKIP_TLS_VERIFY = REDIS['caching'].get('INSECURE_SKIP_TLS_VERIFY', False)
272273
CACHING_REDIS_CA_CERT_PATH = REDIS['caching'].get('CA_CERT_PATH', False)
273-
CACHING_REDIS_URL = f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}'
274+
CACHING_REDIS_URL = REDIS['caching'].get('URL', f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}')
274275

275276
# Configure Django's default cache to use Redis
276277
CACHES = {
@@ -678,6 +679,12 @@ def _setting(name, default=None):
678679
'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT
679680
},
680681
}
682+
elif TASKS_REDIS_URL:
683+
RQ_PARAMS = {
684+
'URL': TASKS_REDIS_URL,
685+
'SSL': TASKS_REDIS_SSL,
686+
'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required',
687+
}
681688
else:
682689
RQ_PARAMS = {
683690
'HOST': TASKS_REDIS_HOST,

0 commit comments

Comments
 (0)