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

Standardize redis url parsing #222

Closed
Babarberousse opened this issue Aug 30, 2022 · 3 comments
Closed

Standardize redis url parsing #222

Babarberousse opened this issue Aug 30, 2022 · 3 comments

Comments

@Babarberousse
Copy link

Babarberousse commented Aug 30, 2022

Hi,
At the moment I'm not really sure if django-defender is compatible with redis through unix socket. django-defender uses a custom parse_redis_url function (

def parse_redis_url(url, password_quote=None):
).
This results in the following parsing error when using DEFENDER_REDIS_URL = "unix://run/redis/redis.sock" :

    def parse_redis_url(url, password_quote=None):                                                                                                                                       
        """Parses a redis URL."""                                                                                                                                                        
                                                                                                                                                                                         
        # create config with some sane defaults                                                                                                                                          
        redis_config = {                                                                                                                                                                 
            "DB": 0,
            "USERNAME": "default",
            "PASSWORD": None,
            "HOST": "localhost",
            "PORT": 6379,
            "SSL": False,
        }
     
        if not url:
            return redis_config
     
        url = urlparse.urlparse(url)
        # Remove query strings.
        path = url.path[1:]
        path = path.split("?", 2)[0]
     
        if path:
>           redis_config.update({"DB": int(path)})
E           ValueError: invalid literal for int() with base 10: 'redis/redis.sock'

Shouldn't you use redis.Redis.from_url method instead ? This should require redis-py >=2.7.0.
If you're ok with this approach I can do the PR.

@kencochrane
Copy link
Collaborator

I think that makes sense. If you submit the PR, please also add the unit tests to cover socket and URL based redis urls.

I have to check which redis version we require today, to see if that is a big jump or not. If too big I wonder if we make a larger bump to the version so people are aware it is a bigger change.

@wind-shift
Copy link
Contributor

Should be solved by #234

@kencochrane
Copy link
Collaborator

Thanks, closing

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

3 participants