Package: celery-redis-sentinel
Celery broker and results backend implementation forRedis SentinelFree software: MIT licenseGitHub:https://github.com/dealertrack/celery-redis-sentinelDocumentation:https://celery-redis-sentinel.readthedocs.org.Why?Redisis a pretty awesome in-memory key-value data-store.
Being in-memory makes it wickedly fast however at a cost of no-persistence.
In business-critical applications (you know, which make company money) that makes
stand-alone redis deployment non-practical. This is whereRedis Sentinelcomes in.
It provides scalability and high availability to Redis 2.X
(Redis 3.X comes with native-clustering which is different from Sentinel).
As a result, Redis becomes a viable solution for solving some of business needs.
As you can imagine from the project title, one use-case is using Redis Sentinel withcelery.
Unfortunately celery does not support Redis Sentinel by default hence this
library which aims to provide non-official Redis Sentinel support asbothcelery broker and results backend.InstallingInstallation is super easy withpip:$ pip install celery-redis-sentinelUsageUsing this library is pretty simple. All you need to do is configure celery
to use Redis Sentinel for broker and/or results backend. That is done
with a couple of settings:# celeryconfig.py
BROKER_URL = 'redis-sentinel://redis-sentinel:26379/0'
BROKER_TRANSPORT_OPTIONS = {
    'sentinels': [('192.168.1.1', 26379),
                  ('192.168.1.2', 26379),
                  ('192.168.1.3', 26379)],
    'service_name': 'master',
    'socket_timeout': 0.1,
}

CELERY_RESULT_BACKEND = 'redis-sentinel://redis-sentinel:26379/1'
CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS = BROKER_TRANSPORT_OPTIONSSome notes about the configuration:note the use ofredis-sentinelschema within the URL for broker and results
backend. In order to use that schema, which is not shipped with celery, where you create
your celery application youmustfirst need to register sentinel support:# tasks.py
from celery_redis_sentinel import register

# has to be called before creating celery app
register()

app = Celery('tasks')hostname and port are ignored within the actual URL. Sentinel uses transport optionssentinelssetting to create aSentinel()instead of configuration URL.Scheduling During FailoverSome considerations while using Redis Sentinel as a celery broker. While the failover
is in progress, no tasks can be scheduled. Trying to schedule a task will either
raiseTimeoutorConnectionError. That is because other sentinel nodes
within the cluster, depending on the configuration, have a timeout until they elect
a new master. During that time, trying to schedule a task will attempt to store
it in now-invalid master node hence the exception. If that is unacceptable within
your application, this library comes with a small wrapper which allows to trigger
tasks which will block the scheduling until new master will be elected:from celery_redis_sentinel.redis_sentinel import ensure_redis_call
from tasks import add

# this will blow up during failover
add.delay(1, 2)
# this will keep retrying until it succeeds
ensure_redis_call(add.delay, 1, 2)Alternatively you can use a supplied abstract celery task subclass which provides
same retrying behavior in the task definition itself:# tasks.py
from celery_redis_sentinel.task import EnsuredRedisTask

@app.task(base=EnsuredRedisTask)
def add(a, b):
    return a + bHistory0.3 (2016-05-03)New: Addition ofShortLivedStrictRedisandShortLivedSentinel.
Both of them use short-lived connections which disconnect from redis
as soon as the query to redis is complete.Fixed: All sentinel connections are now created viaShortLivedSentinel.
This fixes an issue when sentinel would reach its max connections limit
since all celery workers would always be connected to sentinel.
That is not necessary since sentinel is queried very rarely for the current
master connection details.
In addition this is useful when Redis Sentinel is used behind a firewall
since sentinel would not notice when firewall would close the connections
and so would not release them.0.2 (2016-01-14)New: AddedEnsuredRedisTaskwhich allows to ensure tasks are scheduled
via an abstract base task class in task definition rather then explicitly usingensure_redis_callwhile calling the task:@app.task(base=EnsuredRedisTask)
def foo(): pass0.1 (2016-01-13)First releaseCreditsThis utility was created atdealertrack technologies(dealertrack GitHub) for our internal use so thank you
dealertrack for allowing to contribute the utility
to the open-source community.Development LeadMiroslav Shubernetskiy  -https://github.com/miki725ContributorsNone yet. Why not be the first?LicenseThe MIT License (MIT)Copyright © 2015-2016, dealertrack technologiesPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.