Skip to main content

Nameko Redis Keyspace Notifications extension.

Project description

Nameko Redis Keyspace Notifications extension.

https://img.shields.io/pypi/v/nameko-rediskn.svg https://img.shields.io/pypi/pyversions/nameko-rediskn.svg https://img.shields.io/pypi/format/nameko-rediskn.svg https://travis-ci.org/sohonetlabs/nameko-rediskn.svg?branch=master https://img.shields.io/badge/code%20style-black-000000.svg

Usage

This Nameko extension adds the ability to subscribe to events, keys and databases.

Some event examples:

  • expire events fired for EXPIRE commands

  • expired events fired when a key gets deleted due to expiration

Usage example:

from nameko_rediskn import rediskn, REDIS_PMESSAGE_TYPE


class MyService:

    name = 'my-service'

    @rediskn.subscribe(uri_config_key='MY_REDIS', keys='foo/bar-*')
    def subscriber(self, message):
        if message['type'] != REDIS_PMESSAGE_TYPE:
            return

        event_type = message['data']
        if event_type != 'expired':
            return

        key = message['channel'].split(':')[1]

        # ...

Where subscribe accepts:

  • MY_REDIS, which is the attribute name referring to he Redis URI (see the Configuration section below).

  • events, keys and dbs as a single value (string) or a list of values to subscribe to. They are all optional but at least one of those arguments must be provided.

For more information, you can check the documentation of the RedisKNEntrypoint entrypoint.

NOTE: this dependency is not “cluster-aware” and fires on all service instances. There are different ways to solve that: using ddebounce is one of them.

Configuration

Nameko configuration file:

# config.yaml

REDIS:
    notification_events: "KEA"
    pubsub_backoff_factor: 3

REDIS_URIS:
    MY_REDIS: "redis://localhost:6380/0"

REDIS[notification_events] is optional and can be omited or just contain None. Otherwise, it must have a valid value for the 'notify-keyspace-events' Redis client configuration attribute. This should be ideally set on the server side, as setting it in one of the Redis clients will affect the rest of them.

REDIS[pubsub_backoff_factor] sets the exponential backoff factor for reconnecting to Redis on errors. If an error occurs while listening for Redis events, we sleep for backoff_factor * 2 ** (n - 1) where n is the number of consecutive errors that have occurred. If omitted, this defaults to 2.

REDIS_URIS follows the config format used by the Nameko Redis dependency provider, where MY_REDIS is just the attribute name refering to the Redis URI of the instance being used.

Tests

RabbitMQ should be up and running on the default URI guest:guest@localhost and using the default ports.

Redis should be also running on the default port.

There are Makefile targets to run both RabbitMQ and Redis docker containers locally using the default ports and configuration:

$ make rabbitmq-container
$ make redis-container

A virtual environment should be set up and up to date:

$ # Create/activate a virtual environment
$ pip install -U pip setuptools wheel

tox can be used to run the tests. It is recomented that all its dependencies, specially virtualenv, are up to date, so that it uses the correct version of libraries like pip, setuptools and wheel:

$ pip install -U --upgrade-strategy=eager tox
$ tox
$ tox -e "py37-namekolatest-redislatest-test"

There are other Makefile targets that can be used to run the tests, but extra dependencies will have to be installed, including this package in develop mode:

$ pip install -U --editable ".[dev]"
$ make test
$ make coverage

A different RabbitMQ URI can be provided overriding the following environment variables: RABBIT_CTL_URI and AMQP_URI.

Additional pytest parameters can be also provided using the ARGS variable:

$ make test RABBIT_CTL_URI=http://guest:guest@localhost:15673 AMQP_URI=amqp://guest:guest@localhost:5673 ARGS='-x -vv --disable-warnings'
$ make coverage RABBIT_CTL_URI=http://guest:guest@localhost:15673 AMQP_URI=amqp://guest:guest@localhost:5673 ARGS='-x -vv --disable-warnings'

Linting

To run linting checks using tox:

$ for env in $(tox -l - | grep linting); do tox -e $env; done

Nameko support

The following Nameko versions are actively supported: 2.11, 2.12.

However, this extension should work from, at least, Nameko 2.6 onwards.

Redis support

The following Redis Python versions are actively supported: 2.10, 3.0, 3.1, 3.2.

Redis 4.0 is actively supported.

Changelog

Consult the CHANGELOG document for fixes and enhancements of each version.

License

The MIT License. See LICENSE for details.

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

nameko-rediskn-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

nameko_rediskn-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file nameko-rediskn-0.1.1.tar.gz.

File metadata

  • Download URL: nameko-rediskn-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.2

File hashes

Hashes for nameko-rediskn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7503369f7d48d61fef3e41dce355d429a61b2411a56c6fa0534767047b44048e
MD5 9405546a43b7b24a2b3da20358cca26c
BLAKE2b-256 8de799218e19a6a93cfb8d0d7420f41ba809c692f649e938ea0ea67ad2807f2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nameko_rediskn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.2

File hashes

Hashes for nameko_rediskn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac1a473470ee86dca3d4c3617cc888c3fcb24d013e0f0eb7868b730b21bbae4
MD5 29625b01efb0ad609070620851983839
BLAKE2b-256 bdf345494ed5ff30cbcc6c2b3b40aed43228573fa26682d5bf13d0d5f36b8b24

See more details on using hashes here.

Supported by

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