Package: nameko-rediskn
NamekoRedis Keyspace Notificationsextension.UsageThisNamekoextension adds the ability to subscribe to events, keys and
databases.Some event examples:expireevents fired forEXPIREcommandsexpiredevents fired when a key gets deleted due to expirationUsage example:fromnameko_redisknimportrediskn,REDIS_PMESSAGE_TYPEclassMyService:name='my-service'@rediskn.subscribe(uri_config_key='MY_REDIS',keys='foo/bar-*')defsubscriber(self,message):ifmessage['type']!=REDIS_PMESSAGE_TYPE:returnevent_type=message['data']ifevent_type!='expired':returnkey=message['channel'].split(':')[1]# ...Wheresubscribeaccepts:MY_REDIS, which is the attribute name referring to he Redis URI
(see theConfigurationsection below).events,keysanddbsas 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 theRedisKNEntrypointentrypoint.NOTE: this dependency is not “cluster-aware” and fires on all service
instances. There are different ways to solve that: usingddebounceis
one of them.ConfigurationNamekoconfiguration file:# config.yamlREDIS:notification_events:"KEA"pubsub_backoff_factor:3REDIS_URIS:MY_REDIS:"redis://localhost:6380/0"REDIS[notification_events]is optional and can be omited or just
containNone. 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 forbackoff_factor * 2 ** (n - 1)wherenis the
number of consecutive errors that have occurred. If omitted, this defaults
to2.REDIS_URISfollows the config format used by theNameko Redisdependency provider, whereMY_REDISis just the attribute name
refering to the Redis URI of the instance being used.TestsRabbitMQshould be up and running on the default URIguest:guest@localhostand using the default ports.Redisshould 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:$makerabbitmq-container$makeredis-containerA virtual environment should be set up and up to date:$# Create/activate a virtual environment$pipinstall-Upipsetuptoolswheeltoxcan be used to run the tests. It is recomented that all its
dependencies, speciallyvirtualenv, are up to date, so that it uses
the correct version of libraries likepip,setuptoolsandwheel:$pipinstall-U--upgrade-strategy=eagertox$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:$pipinstall-U--editable".[dev]"$maketest$makecoverageA different RabbitMQ URI can be provided overriding the following
environment variables:RABBIT_CTL_URIandAMQP_URI.Additionalpytestparameters can be also provided using theARGSvariable:$maketestRABBIT_CTL_URI=http://guest:guest@localhost:15673AMQP_URI=amqp://guest:guest@localhost:5673ARGS='-x -vv --disable-warnings'$makecoverageRABBIT_CTL_URI=http://guest:guest@localhost:15673AMQP_URI=amqp://guest:guest@localhost:5673ARGS='-x -vv --disable-warnings'LintingTo run linting checks usingtox:$forenvin$(tox-l-|greplinting);dotox-e$env;doneNameko supportThe followingNamekoversions are actively supported:2.11,2.12.However, this extension should work from, at least,Nameko2.6onwards.Redis supportThe followingRedis Pythonversions are actively supported:2.10,3.0,3.1,3.2.Redis4.0is actively supported.ChangelogConsult theCHANGELOGdocument for fixes and enhancements of each
version.LicenseThe MIT License. SeeLICENSEfor details.