{"id":28741012,"url":"https://github.com/aliyuncontainerservice/redis-cluster","last_synced_at":"2025-06-16T07:09:54.598Z","repository":{"id":25236852,"uuid":"28661438","full_name":"AliyunContainerService/redis-cluster","owner":"AliyunContainerService","description":"HA Redis Cluster with Sentinel by Docker Compose","archived":false,"fork":false,"pushed_at":"2023-06-29T00:38:21.000Z","size":22,"stargazers_count":465,"open_issues_count":9,"forks_count":205,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-27T08:45:31.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AliyunContainerService.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-12-31T08:53:58.000Z","updated_at":"2025-03-19T17:51:44.000Z","dependencies_parsed_at":"2024-01-16T06:20:04.150Z","dependency_job_id":"df18bd94-6cd5-42ba-8874-4d79e86d6824","html_url":"https://github.com/AliyunContainerService/redis-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AliyunContainerService/redis-cluster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fredis-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fredis-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fredis-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fredis-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AliyunContainerService","download_url":"https://codeload.github.com/AliyunContainerService/redis-cluster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fredis-cluster/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260116644,"owners_count":22961065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-16T07:09:52.110Z","updated_at":"2025-06-16T07:09:54.589Z","avatar_url":"https://github.com/AliyunContainerService.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redis-cluster \n**Redis cluster with Docker Compose** \n\nUsing Docker Compose to setup a redis cluster with sentinel.\n\nThis project was inspired by the project of **@mdevilliers**\n\n## Prerequisite\nInstall [Docker](https://docs.docker.com/engine/) and [Docker Compose](https://docs.docker.com/compose/) in testing environment.\n\nIf you are using Windows, please execute the following command before \"git clone\" to disable changing the line endings of script files into DOS format:\n```sh\ngit config --global core.autocrlf false\n```\n\n## Docker Compose template of Redis cluster\n\nThe template defines the topology of the Redis cluster:\n```yml\nversion: '3.9'\n\nservices:\nmaster:\nimage: redis:latest\ncontainer_name: redis-master\n\nslave:\nimage: redis:latest\ncontainer_name: redis-slave\ncommand: redis-server --slaveof redis-master 6379\ndepends_on:\n- master\n\nsentinel:\nbuild:\ncontext: ./sentinel\ndockerfile: Dockerfile\ncontainer_name: redis-sentinel\nenvironment:\n- SENTINEL_DOWN_AFTER=5000\n- SENTINEL_FAILOVER=5000\ndepends_on:\n- master\n- slave\n```\n\nNotes:\n1. Updated the version format to '3.9'.\n2. Added the container_name parameter for each service to specify container names.\n3. Replaced use of links with depends_on to define dependencies between services.\n4. The Dockerfile path for the sentinel service is specified in the build parameter.\n5. The path to the build context for sentinel services is specified in the context parameter.\n6. The redis:latest image is used instead of a specific version to get the latest available version of Redis.\n7. The declaration of links for the slave service has been removed, since it is already defined in the command section.\n\nPlease make sure the Dockerfile path for the sentinel service and the build context (./sentinel) are correctly specified and refer to your project file structure.\n\nThere are following services in the cluster:\n* master: Redis master\n* slave:  Redis slave\n* sentinel: Redis sentinel\n\n\nThe sentinels are configured with a \"mymaster\" instance with the following properties:\n```sh\nsentinel monitor mymaster redis-master 6379 2\nsentinel down-after-milliseconds mymaster 5000\nsentinel parallel-syncs mymaster 1\nsentinel failover-timeout mymaster 5000\n```\n\nThe details could be found in `sentinel/sentinel.conf`.\n\nThe default values of the environment variables for Sentinel are as following:\n* SENTINEL_QUORUM: 2\n* SENTINEL_DOWN_AFTER: 30000\n* SENTINEL_FAILOVER: 180000\n\n\n\n## Play with it\nBuild the sentinel Docker image:\n```sh\ndocker compose build .\n```\n\nStart the redis cluster:\n```sh\ndocker compose up -d\n```\n\nCheck the status of redis cluster:\n```sh\ndocker compose ps\n```\n\nThe result is:\n```md\n         Name                        Command               State          Ports        \n--------------------------------------------------------------------------------------\nrediscluster_master_1     docker-entrypoint.sh redis ...   Up      6379/tcp            \nrediscluster_sentinel_1   docker-entrypoint.sh redis ...   Up      26379/tcp, 6379/tcp \nrediscluster_slave_1      docker-entrypoint.sh redis ...   Up      6379/tcp     \n```\n\nScale out the instance number of sentinel:\n```sh\ndocker compose scale sentinel=3\n```\n\nScale out the instance number of slaves:\n```sh\ndocker compose scale slave=2\n```\n\nCheck the status of redis cluster:\n```sh\ndocker compose ps\n```\n\nThe result is:\n```md\n         Name                        Command               State          Ports        \n--------------------------------------------------------------------------------------\nrediscluster_master_1     docker-entrypoint.sh redis ...   Up      6379/tcp            \nrediscluster_sentinel_1   docker-entrypoint.sh redis ...   Up      26379/tcp, 6379/tcp \nrediscluster_sentinel_2   docker-entrypoint.sh redis ...   Up      26379/tcp, 6379/tcp \nrediscluster_sentinel_3   docker-entrypoint.sh redis ...   Up      26379/tcp, 6379/tcp \nrediscluster_slave_1      docker-entrypoint.sh redis ...   Up      6379/tcp            \nrediscluster_slave_2      docker-entrypoint.sh redis ...   Up      6379/tcp            \n```\n\nExecute the test scripts:\n```sh\n./test.sh\n```\nto simulate stop and recover the Redis master. And you will see the master is switched to slave automatically. \n\nOr, you can do the test manually to pause/unpause redis server through:\n```sh\ndocker pause rediscluster_master_1\ndocker unpause rediscluster_master_1\n```\nAnd get the sentinel infomation with following commands:\n```sh\ndocker exec rediscluster_sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster\n```\n\n## References\n1: https://github.com/mdevilliers/docker-rediscluster\u003cbr\u003e\n2: https://registry.hub.docker.com/r/bitnami/redis-sentinel\u003cbr\u003e\n3: https://docs.docker.com/compose/\u003cbr\u003e\n4: https://www.docker.com\n\n## License\nApache 2.0 license \n\n## Contributors\n* Li Yi (\u003cdenverdino@gmail.com\u003e)\n* Ty Alexander (\u003cty.alexander@gmail.com\u003e)\n* Dmitrii Zagorodnev (\u003cdmitrii.zagorodnev@outlook.com\u003e)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliyuncontainerservice%2Fredis-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faliyuncontainerservice%2Fredis-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faliyuncontainerservice%2Fredis-cluster/lists"}