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

Support Database URLs #246

Closed
kennethreitz opened this issue May 18, 2012 · 7 comments · Fixed by #247
Closed

Support Database URLs #246

kennethreitz opened this issue May 18, 2012 · 7 comments · Fixed by #247

Comments

@kennethreitz
Copy link
Contributor

A trend in platform as a service providers is to use Database URLs to supp. They're quickly becoming a standard.

SQLAlchemy and RedisToGo, for example, uses them for database connections.

I'd love to implement this at the redis-py level, if appropriate.

That would turn this code:

    import os
    import urlparse
    from redis import Redis

    redis_url = os.getenv('REDISTOGO_URL')

    url = urlparse.urlparse(redis_url)
    r = redis.Redis(
        host=url.hostname, 
        port=url.port, 
        db=0, 
        password=url.password)

Into this:

    import os
    from redis.utils import from_databaseurl

    redis_url = os.getenv('REDISTOGO_URL')
    r = from_databaseurl(redis_url)
@andymccurdy
Copy link
Contributor

When 2.4 came out, we talked about doing this with the internal refactoring of how connections worked in redis-py. Ultimately, ended up punting on the idea for several reasons. Most notably, there's a number of options when creating a redis client instance that aren't able to be elegantly represented in a URL, e.g. ConnectionClass and unix_socket_path.

However, I do see the value in what you're proposing, especially for services like Heroku/RedisToGo. Your suggestion of using a factory-like function might make a lot of my initial concern go away.

@kennethreitz
Copy link
Contributor Author

I agree with your concern, which is why I think it should be a helper function instead of a first-class member of the API.

So, you're 👍 to this? I can send a pull request if you'd like :)

@andymccurdy
Copy link
Contributor

Send away!

@kennethreitz
Copy link
Contributor Author

@andymccurdy excellent :)

Do you think the function should exist at the root namespace (e.g. redis.from_url or redis.utils.from_url)?

@andymccurdy
Copy link
Contributor

Root namespace. It's where you create a client instance the "normal way".

@kennethreitz
Copy link
Contributor Author

Sent! 💨

@pietern
Copy link
Contributor

pietern commented May 18, 2012

We had the same problem for redis-rb, and avoided representing a remote as an URL for the same reasons. To still allow specifying the remote using an URL we take an :url option to Redis.new. This probably translates to using a keyword(?) in Python.

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

Successfully merging a pull request may close this issue.

3 participants