django / channels_redis

Redis channel layer backend for Django Channels
BSD 3-Clause "New" or "Revised" License
601 stars 197 forks source link

need for Advanced Redis configurations #390

Open Aswin1105 opened 5 months ago

Aswin1105 commented 5 months ago

Hi,

I encountered an issue while working with Django Channels. I was required to use the same Redis configuration throughout the Django project. The Django cache framework allows for a more detailed configuration, including parameters like CONNECTION_POOL_CLASS and SOCKET_CONNECT_TIMEOUT.

Firstly, I couldn't find proper documentation or mention in the README indicating that these parameters can be passed in the host as a dictionary. Upon inspecting the channel_redis code, I found that the decode_host function (located in channel_redis.utils at line 48) does parse these parameters and passes them to the asyncio Redis connection. Even then i am not sure, what all we could pass in the host, can we include these in doc??

Secondly, is there any way to follow the same settings format for the cache backend in Django here? Or can we use the same cache settings by default in this package, considering it is specific to Django?

Thank you.

Also, as this is my first time raising a issue, Please let me know any improvements i need to do

bbrowning918 commented 5 months ago

The hosts section of the README outlines some very basic examples and has a link to the redis connection docs with all the config redis-py supports. Some different wording or another example might help make that more visible or clear.

The main channels docs is sparse on the config topic but the root of it is channels-redis just passes things along as-is.

As for matching up with the cache framework exactly, I can already see some mismatch between redis-py expecting connection_pool and the cache framework using CONNECTION_POOL_CLASS which might be hard to enforce/standardize. Would sharing some variables work?

REDIS = "redis://127.0.0.1:6379"
POOL = "redis.connection.ConnectionPool"
TIMEOUT = 3600

CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": REDIS,
        "OPTIONS": {
           "CONNECTION_POOL_CLASS": POOL,
           "SOCKET_CONNECT_TIMEOUT": TIMEOUT
       }
    }
}

CHANNEL_LAYERS = {
    "default: {
        "CONFIG": {
           "hosts" = [{
               "address": REDIS,
               "connection_pool": POOL,
               "socket_connect_timeout": TIMEOUT
           }]
       }
    }
}

Forgive any config errors, I am guessing on the formats/syntax :D