Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need for Advanced Redis configurations #390

Open
Aswin1105 opened this issue Jun 6, 2024 · 1 comment
Open

need for Advanced Redis configurations #390

Aswin1105 opened this issue Jun 6, 2024 · 1 comment

Comments

@Aswin1105
Copy link

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants