Support Redis Unix sockets #9583

Closed
opened 2025-12-29 21:19:17 +01:00 by adam · 2 comments
Owner

Originally created by @tacerus on GitHub (May 4, 2024).

Deployment Type

Self-hosted

NetBox Version

3.7.5

Python Version

3.11

Steps to Reproduce

Re-open the issue in https://github.com/netbox-community/netbox/issues/4377.

Expected Behavior

Unix sockets should be supported.

Observed Behavior

https://github.com/netbox-community/netbox/pull/15590 was closed.

Originally created by @tacerus on GitHub (May 4, 2024). ### Deployment Type Self-hosted ### NetBox Version 3.7.5 ### Python Version 3.11 ### Steps to Reproduce Re-open the issue in https://github.com/netbox-community/netbox/issues/4377. ### Expected Behavior Unix sockets should be supported. ### Observed Behavior https://github.com/netbox-community/netbox/pull/15590 was closed.
adam closed this issue 2025-12-29 21:19:17 +01:00
Author
Owner

@tacerus commented on GitHub (May 4, 2024):

In https://github.com/netbox-community/netbox/pull/15590#issuecomment-2029621652 additional discussion was desired.
What are the concerns?
No discussion happened in https://github.com/netbox-community/netbox/issues/4377.
Can we implement the patch from @evlli in https://github.com/netbox-community/netbox/pull/15590?

I have an alternative patch attached, but the already submitted one seems more flexible and thought through.

Patch
--- a/netbox/netbox/settings.py	2024-05-04 21:35:18.459236034 +0200
+++ b/netbox/netbox/settings.py	2024-05-04 21:35:05.462490445 +0200
@@ -277,6 +277,7 @@
 TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False)
 TASKS_REDIS_SKIP_TLS_VERIFY = TASKS_REDIS.get('INSECURE_SKIP_TLS_VERIFY', False)
 TASKS_REDIS_CA_CERT_PATH = TASKS_REDIS.get('CA_CERT_PATH', False)
+TASKS_REDIS_USE_UNIX_SOCKET = TASKS_REDIS.get('USE_UNIX_SOCKET', False)
 
 # Caching
 if 'caching' not in REDIS:
@@ -292,13 +293,21 @@
 CACHING_REDIS_SENTINELS = REDIS['caching'].get('SENTINELS', [])
 CACHING_REDIS_SENTINEL_SERVICE = REDIS['caching'].get('SENTINEL_SERVICE', 'default')
 CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis'
+CACHING_REDIS_PROTO = 'unix' if REDIS['caching'].get('USE_UNIX_SOCKET', False) else CACHING_REDIS_PROTO
 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)
 
+if CACHING_REDIS_PROTO == 'unix':
+    CACHING_REDIS_PORT=''
+    CACHING_REDIS_DATABASE=f'?db={CACHING_REDIS_DATABASE}'
+else:
+    CACHING_REDIS_PORT=f':{CACHING_REDIS_PORT}'
+    CACHING_REDIS_DATABASE=f'/{CACHING_REDIS_DATABASE}'
+
 CACHES = {
     'default': {
         'BACKEND': 'django_redis.cache.RedisCache',
-        'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}',
+        'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}{CACHING_REDIS_PORT}{CACHING_REDIS_DATABASE}',
         'OPTIONS': {
             'CLIENT_CLASS': 'django_redis.client.DefaultClient',
             'PASSWORD': CACHING_REDIS_PASSWORD,
@@ -688,12 +697,18 @@
         },
     }
 else:
-    RQ_PARAMS = {
-        'HOST': TASKS_REDIS_HOST,
-        'PORT': TASKS_REDIS_PORT,
-        'SSL': TASKS_REDIS_SSL,
-        'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required',
-    }
+    if TASKS_REDIS_USE_UNIX_SOCKET:
+        RQ_PARAMS = {
+            'UNIX_SOCKET_PATH': TASKS_REDIS_HOST,
+        }
+    else:
+        RQ_PARAMS = {
+            'HOST': TASKS_REDIS_HOST,
+            'PORT': TASKS_REDIS_PORT,
+            'SSL': TASKS_REDIS_SSL,
+            'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required',
+        }
+
 RQ_PARAMS.update({
     'DB': TASKS_REDIS_DATABASE,
     'USERNAME': TASKS_REDIS_USERNAME,
@tacerus commented on GitHub (May 4, 2024): In https://github.com/netbox-community/netbox/pull/15590#issuecomment-2029621652 additional discussion was desired. What are the concerns? No discussion happened in https://github.com/netbox-community/netbox/issues/4377. Can we implement the patch from @evlli in https://github.com/netbox-community/netbox/pull/15590? I have an alternative patch attached, but the already submitted one seems more flexible and thought through. <details> <summary>Patch</summary> ``` --- a/netbox/netbox/settings.py 2024-05-04 21:35:18.459236034 +0200 +++ b/netbox/netbox/settings.py 2024-05-04 21:35:05.462490445 +0200 @@ -277,6 +277,7 @@ TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False) TASKS_REDIS_SKIP_TLS_VERIFY = TASKS_REDIS.get('INSECURE_SKIP_TLS_VERIFY', False) TASKS_REDIS_CA_CERT_PATH = TASKS_REDIS.get('CA_CERT_PATH', False) +TASKS_REDIS_USE_UNIX_SOCKET = TASKS_REDIS.get('USE_UNIX_SOCKET', False) # Caching if 'caching' not in REDIS: @@ -292,13 +293,21 @@ CACHING_REDIS_SENTINELS = REDIS['caching'].get('SENTINELS', []) CACHING_REDIS_SENTINEL_SERVICE = REDIS['caching'].get('SENTINEL_SERVICE', 'default') CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis' +CACHING_REDIS_PROTO = 'unix' if REDIS['caching'].get('USE_UNIX_SOCKET', False) else CACHING_REDIS_PROTO 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) +if CACHING_REDIS_PROTO == 'unix': + CACHING_REDIS_PORT='' + CACHING_REDIS_DATABASE=f'?db={CACHING_REDIS_DATABASE}' +else: + CACHING_REDIS_PORT=f':{CACHING_REDIS_PORT}' + CACHING_REDIS_DATABASE=f'/{CACHING_REDIS_DATABASE}' + CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', - 'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}', + 'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_USERNAME_HOST}{CACHING_REDIS_PORT}{CACHING_REDIS_DATABASE}', 'OPTIONS': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient', 'PASSWORD': CACHING_REDIS_PASSWORD, @@ -688,12 +697,18 @@ }, } else: - RQ_PARAMS = { - 'HOST': TASKS_REDIS_HOST, - 'PORT': TASKS_REDIS_PORT, - 'SSL': TASKS_REDIS_SSL, - 'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required', - } + if TASKS_REDIS_USE_UNIX_SOCKET: + RQ_PARAMS = { + 'UNIX_SOCKET_PATH': TASKS_REDIS_HOST, + } + else: + RQ_PARAMS = { + 'HOST': TASKS_REDIS_HOST, + 'PORT': TASKS_REDIS_PORT, + 'SSL': TASKS_REDIS_SSL, + 'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required', + } + RQ_PARAMS.update({ 'DB': TASKS_REDIS_DATABASE, 'USERNAME': TASKS_REDIS_USERNAME, ``` </details>
Author
Owner

@DanSheps commented on GitHub (May 6, 2024):

Thank you for opening a bug report. It seems that the described functionality is intended behavior. If you meant to open a feature request instead, please close this issue and open a new one using the feature request template. Otherwise, please revise your post above to elaborate on why you believe the observed behavior is flawed.

@DanSheps commented on GitHub (May 6, 2024): Thank you for opening a bug report. It seems that the described functionality is intended behavior. If you meant to open a feature request instead, please close this issue and open a new one using the [feature request template](https://github.com/netbox-community/netbox/issues/new?template=feature_request.md). Otherwise, please revise your post above to elaborate on why you believe the observed behavior is flawed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9583