{"id":7661,"library":"redis-sentinel-url","title":"Redis Sentinel URL","description":"Redis-Sentinel-Url is a Python library that provides a parser and connection factory for Redis connections, specifically supporting both standard `redis://` and the custom `redis+sentinel://` URL schemes. It allows applications to connect to Redis instances via Sentinel for high availability. The library is currently at version 1.0.1, with its last major update addressing password handling, and it appears to be in maintenance mode, offering stable functionality rather than active feature development.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/exponea/redis-sentinel-url","tags":["redis","sentinel","high-availability","connection-pooling","url-parser"],"install":[{"cmd":"pip install Redis-Sentinel-Url","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Provides the underlying Redis client and Sentinel client functionalities. Requires redis-py 2.9.0+.","package":"redis","optional":false}],"imports":[{"note":"The primary connection factory is 'connect', not 'create_connection'.","wrong":"import redis_sentinel_url; redis_sentinel_url.create_connection()","symbol":"connect","correct":"from redis_sentinel_url import connect"}],"quickstart":{"code":"import os\nfrom redis_sentinel_url import connect\n\n# Example Sentinel URL. Replace with your actual Sentinel configuration.\n# The 'mymaster' is the service name configured in Redis Sentinel.\n# Use os.environ.get for sensitive info like passwords.\nREDIS_SENTINEL_URL = os.environ.get(\n    'REDIS_SENTINEL_URL',\n    'redis+sentinel://localhost:26379,otherhost:26479/mymaster/0?password=your_redis_master_password&sentinel_password=your_sentinel_password'\n)\n\ntry:\n    # Connect returns a (sentinel_client, redis_client) tuple\n    sentinel_client, redis_client = connect(REDIS_SENTINEL_URL)\n\n    if sentinel_client:\n        print(f\"Connected to Redis Sentinel service: {sentinel_client.service_name}\")\n        # You can get the current master and use it\n        master = sentinel_client.master_for(sentinel_client.service_name)\n        print(f\"Master host: {master.connection_pool.connection_kwargs.get('host')}\")\n        print(f\"Master port: {master.connection_pool.connection_kwargs.get('port')}\")\n        master.set('mykey', 'hello from sentinel')\n        print(f\"Set 'mykey': {master.get('mykey').decode('utf-8')}\")\n\n    if redis_client:\n        # If connecting directly to Redis without Sentinel, redis_client will be present and sentinel_client will be None\n        print(\"Connected directly to Redis.\")\n        redis_client.set('anotherkey', 'hello from direct redis')\n        print(f\"Set 'anotherkey': {redis_client.get('anotherkey').decode('utf-8')}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to use `redis_sentinel_url.connect()` to establish connections. It attempts to connect using a `redis+sentinel://` URL, retrieving both the Sentinel client and a `StrictRedis` client for the master. It also illustrates setting and getting a key to confirm functionality. Ensure your `REDIS_SENTINEL_URL` environment variable is correctly configured with your Redis Sentinel setup."},"warnings":[{"fix":"Upgrade to version 1.0.1 or higher: `pip install --upgrade Redis-Sentinel-Url`. Ensure your URL includes passwords for both the Redis master (as `password=`) and Sentinel instances (as `sentinel_password=`) if applicable.","message":"Password handling for Redis Sentinel connections was fixed in version 1.0.1. Prior versions (specifically 1.0.0) might have silently failed to pass passwords correctly, leading to authentication errors or unexpected behavior when connecting to password-protected Redis instances or Sentinels.","severity":"breaking","affected_versions":"<1.0.1"},{"fix":"Ensure `redis-py` is installed and is version 2.9.0 or higher. You can check with `pip show redis` and upgrade with `pip install --upgrade redis`.","message":"The library relies on the `redis-py` package, and its internal implementation notes indicate a requirement for `redis-py` version 2.9.0 or newer. Using older versions of `redis-py` may lead to compatibility issues or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Double-check your `redis+sentinel://` URL for typos. Verify that the `service_name` matches your Redis Sentinel configuration exactly and that all listed sentinel `host:port` pairs are correct and accessible from the application. Consult your Redis Sentinel configuration (`sentinel.conf`) for details.","message":"Incorrect configuration of the `redis+sentinel://` URL, especially the `service_name` (often 'mymaster') or sentinel host:port pairs, will prevent successful connection. The library will accurately relay connection errors from the underlying `redis-py` client.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that your Sentinel instances are running and healthy on the specified `host:port`. Check the `service_name` in your connection URL against your `sentinel.conf` configuration. Ensure network connectivity and correct firewall rules to the Sentinel ports (default 26379).","cause":"The Redis Sentinel cluster could not identify an active master for the specified `service_name` (e.g., 'mymaster'), or the Sentinel instances themselves are unreachable/misconfigured.","error":"redis.sentinel.MasterNotFoundError: No master found for 'mymaster'"},{"fix":"Check if the Sentinel process is running on `localhost:26379`. Verify network connectivity between your application and the Sentinel server. Ensure no firewall rules are blocking the connection on port 26379.","cause":"The Python application was unable to establish a TCP connection to the specified Redis Sentinel host and port. This is often a network or server availability issue.","error":"redis.exceptions.ConnectionError: Error 111 connecting to localhost:26379. Connection refused."},{"fix":"Include the correct password(s) in your `redis+sentinel://` URL. For the Redis master, use `?password=your_redis_master_password`. For Sentinel authentication (Redis 6.2+), use `?sentinel_password=your_sentinel_password`.","cause":"The Redis master or one of the Sentinel instances requires a password, but none was provided in the connection URL, or an incorrect password was supplied.","error":"redis.exceptions.AuthenticationError: Authentication required."}]}