epicserve / django-cache-url

Use Cache URLs in your Django Application
MIT License
18 stars 12 forks source link

Multiple redis hosts throws error #22

Open userlerueda opened 1 year ago

userlerueda commented 1 year ago

Passing multiple redis hosts throws an error:

>>> import django_cache_url
>>> django_cache_url.parse("redis://my-redis.nydu4q.ng.0001.use1.cache.amazonaws.com:6379,my-redis-ro.nydu4q.ng.0001.use1.cache.amazonaws.com:6379")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/django_cache_url/__init__.py", line 115, in parse
    port = url.port if url.port else 6379
  File "/usr/local/lib/python3.10/urllib/parse.py", line 178, in port
    raise ValueError(message) from None
ValueError: Port could not be cast to integer value as '6379,my-redis-ro.nydu4q.ng.0001.use1.cache.amazonaws.com:6379'

If port is removed, there is no traceback, but produces incorrect configuration:

>>> django_cache_url.parse("redis://my-redis.nydu4q.ng.0001.use1.cache.amazonaws.com,my-redis-ro.nydu4q.ng.0001.use1.cache.amazonaws.com")
{'BACKEND': 'django.core.cache.backends.redis.RedisCache', 'LOCATION': 'redis://my-redis.nydu4q.ng.0001.use1.cache.amazonaws.com,my-redis-ro.nydu4q.ng.0001.use1.cache.amazonaws.com:6379/0'}
epicserve commented 1 year ago

Contributions welcome. 🙂