Skip to main content

Simple, robust Redis configuration for Python

Project description

redisconfig

Simple, robust Redis configuration for Python

Installation

pip install redisconfig

Basic Usage

>>> import redisconfig

>>> config = redisconfig.RedisConfig()
RedisConfig(host='127.0.0.1', port=6379, db=0, ssl=False, password=None)

>>> config.host
'127.0.0.1'

>>> config.url()
'redis://127.0.0.1:6379/0'

>>> config.connection()
Redis<ConnectionPool<Connection<host=127.0.0.1,port=6379,db=0>>>

REDIS_URL Environment Variable

In many cases the Redis connection URL is stored in the REDIS_URL environment variable. redisconfig will use that value as a default for several operations, such as the module-level config() and connection() methods. With an environment variable of REDIS_URL=rediss://noop:badpassword@10.0.0.1/2:

>>> redisconfig.config()
RedisConfig(host='10.0.0.1', port=6379, db=2, ssl=True, password='badpassword')

>>> redisconfig.connection()
Redis<ConnectionPool<SSLConnection<host=10.0.0.1,port=6379,db=2>>>

Update Configuration Values

You can update values directly like config.db = 5 but sometimes you want to change values without changing the underlying configuration. The url() and replace() methods on RedisConfig allow you to make new urls or configs without changing the original values.

Create a new URL:

>>> config = redisconfig.RedisConfig()
>>> config.url()
'redis://127.0.0.1:6379/0'

>>> config.url(db=2)
'redis://127.0.0.1:6379/2'

Create a new RedisConfig instance:

>>> config.replace(db='10.0.0.1')
RedisConfig(host='10.0.0.1', port=6379, db=0, ssl=False, password=None)

Developing

The following things are needed to use this repository:

Once you have the prerequisites installed and have cloned the repository you can ready your development environment with poetry install -E dev. You should see output similar to:

$ poetry install -E dev
Creating virtualenv redisconfig in /tmp/redisconfig/.venv
Installing dependencies from lock file

...

Installing the current project: redisconfig (0.1.1)

Testing

poetry run pytest

Changelog

0.1.1

  • Fix typing-extensions import on Python >=3.8

0.1.0

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redisconfig-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redisconfig-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file redisconfig-0.1.1.tar.gz.

File metadata

  • Download URL: redisconfig-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

File hashes

Hashes for redisconfig-0.1.1.tar.gz
Algorithm Hash digest
SHA256 94395a65b6d09fae00c8947f27aff61b5c9f13c066d66ed242c772c7c5ea4211
MD5 7223eb458bc120b448399224e748413b
BLAKE2b-256 a795daa8d2e2c54a7206887870b9ac18133fc98e05f56285f5fd3e59f4177d16

See more details on using hashes here.

File details

Details for the file redisconfig-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: redisconfig-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

File hashes

Hashes for redisconfig-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bfce2b77d4876ae9c732bb4b6875a18f601b91a7babc821def89d1468bc9fe2
MD5 71b00db5792b6ec2467b4332e86aaf1f
BLAKE2b-256 a3b818de312a7ef40ed5abc04bad522865beeebaca9af8e314aca8cd76c28637

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page