{"id":19476107,"url":"https://github.com/sun1211/redis-cluster-tutorial","last_synced_at":"2026-04-14T05:33:32.578Z","repository":{"id":132558548,"uuid":"479731344","full_name":"sun1211/redis-cluster-tutorial","owner":"sun1211","description":"This repository provides comprehensive examples and instructions for setting up and using Redis with Docker. Whether you're looking to deploy a standalone Redis instance or a full-fledged Redis cluster, this guide covers all the essential steps to get you up and running.","archived":false,"fork":false,"pushed_at":"2025-09-21T14:28:07.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T16:25:27.983Z","etag":null,"topics":["backend","docker","docker-compose","fullstack","nodejs","redis","redis-cache","redis-cluster","redis-deployment","redis-examples-free","redis-tutorials","web-development","yarn"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sun1211.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-09T13:16:03.000Z","updated_at":"2025-09-21T14:28:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"28ee6e32-a043-4472-b180-64549c62e577","html_url":"https://github.com/sun1211/redis-cluster-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sun1211/redis-cluster-tutorial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sun1211%2Fredis-cluster-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sun1211%2Fredis-cluster-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sun1211%2Fredis-cluster-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sun1211%2Fredis-cluster-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sun1211","download_url":"https://codeload.github.com/sun1211/redis-cluster-tutorial/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sun1211%2Fredis-cluster-tutorial/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31784253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["backend","docker","docker-compose","fullstack","nodejs","redis","redis-cache","redis-cluster","redis-deployment","redis-examples-free","redis-tutorials","web-development","yarn"],"created_at":"2024-11-10T19:36:34.728Z","updated_at":"2026-04-14T05:33:32.572Z","avatar_url":"https://github.com/sun1211.png","language":"JavaScript","readme":"# Redis Example\n\nThis project demonstrates how to set up and use Redis in both standalone and cluster configurations using Docker.\n\n## Prerequisites\n\nBefore you begin, ensure you have the following installed:\n\n- [Docker](https://docs.docker.com/compose/install/)\n- Yarn v1.22.17 or higher\n- Node.js v14.17.0 or higher\n\n## Standalone Redis Instance\n\n### 1. Start Redis Using Docker\n\nTo start a standalone Redis instance, run the following command:\n\n```bash\nyarn run start-redis\n```\n\nThis will initiate the Redis container using the configuration in `docker-compose.yml`:\n\n```yaml\ncache:\n  image: redis:latest\n  container_name: redis-cache\n  restart: always\n  ports:\n    - \"6379:6379\"\n```\n\nThis configuration sets up a Redis cache service listening on port 6379, which is typical for single-instance Redis deployments.\n\n### 2. Start the Example Application\n\nTo start the example application using the standalone Redis instance, run:\n\n```bash\nyarn run start:single\n```\n\n### 3. Test the Application\n\nYou can test the APIs as follows:\n\n- API without Redis caching: `/getphoto`\n- API with Redis caching: `/getphoto-redis`\n\n## Redis Cluster\n\nA Redis cluster is an advanced configuration that enhances performance, scalability, and fault tolerance by distributing data across multiple nodes.\n\n### 1. Start Redis Cluster Using Docker\n\nRun the following command to start the Redis cluster:\n\n```bash\nyarn run start-redis\n```\n\nIn the `docker-compose.yml` file, the following environment variables are used:\n\n- `ALLOW_EMPTY_PASSWORD`: Allows connections to the cluster without requiring credentials.\n- `REDIS_NODES`: Specifies the hostnames of all nodes in the cluster, separated by spaces.\n- `REDIS_CLUSTER_REPLICAS: 1`: Configures the cluster with three master nodes and three replica nodes across six nodes.\n\nExecute the command to launch the Redis cluster:\n\n```bash\ndocker-compose up\n```\n\nLogs:\n```\nredis-node-5  | \u003e\u003e\u003e Performing Cluster Check (using node 172.18.0.2:6379)\nredis-node-5  | M: 025420b382c7d631ebfe4959b346eaf255caeaba 172.18.0.2:6379\nredis-node-5  |    slots:[0-5460] (5461 slots) master\nredis-node-5  |    1 additional replica(s)\nredis-node-5  | S: 1d693ab3d6b630768359615889bfcdc69642cea3 172.18.0.5:6379\nredis-node-5  |    slots: (0 slots) slave\nredis-node-5  |    replicates 025420b382c7d631ebfe4959b346eaf255caeaba\nredis-node-5  | M: 9239ec8481a3ec411dd0f2f832d0f7a4b07472ef 172.18.0.6:6379\nredis-node-5  |    slots:[10923-16383] (5461 slots) master\nredis-node-5  |    1 additional replica(s)\nredis-node-5  | S: 4d8b42ab42c2f589f31ea2310ccc630a899d71f1 172.18.0.7:6379\nredis-node-5  |    slots: (0 slots) slave\nredis-node-5  |    replicates 9c5e768c2aaae24e48bb62c0be8395d13592a940\nredis-node-5  | S: 07fc9c307fc4fca6371e8832821638d412c8c350 172.18.0.4:6379\nredis-node-5  |    slots: (0 slots) slave\nredis-node-5  |    replicates 9239ec8481a3ec411dd0f2f832d0f7a4b07472ef\nredis-node-5  | M: 9c5e768c2aaae24e48bb62c0be8395d13592a940 172.18.0.3:6379\nredis-node-5  |    slots:[5461-10922] (5462 slots) master\nredis-node-5  |    1 additional replica(s)\nredis-node-5  | [OK] All nodes agree about slots configuration.\nredis-node-5  | \u003e\u003e\u003e Check for open slots...\nredis-node-5  | \u003e\u003e\u003e Check slots coverage...\nredis-node-5  | [OK] All 16384 slots covered.\nredis-node-5  | Cluster correctly created\n```\n\nYou should see output indicating the successful creation of the cluster:\n\n```\nredis-node-5  | \u003e\u003e\u003e Performing Cluster Check (using node 172.18.0.2:6379)\n...\nredis-node-5  | [OK] All 16384 slots covered.\nredis-node-5  | Cluster correctly created\n```\n\n### 2. Connect to the Redis Cluster\n\nTo connect to a specific Redis container, list all running containers:\n\n```bash\ndocker ps\n```\n\nThen, use the following command to access the container:\n\n```bash\ndocker exec -it \u003ccontainer_id\u003e sh\n```\n\nOnce inside the container, you can start the Redis CLI:\n\n```bash\nredis-cli -c\n```\n\nTo view all nodes in the cluster, run:\n\n```bash\nCLUSTER NODES\n```\n\nLogs:\n```\n127.0.0.1:6379\u003e CLUSTER NODES\n82d2bee961c7a4b73f099550d72a232e55d12d60 172.18.0.2:6379@16379 master - 0 1683707451345 2 connected 5461-10922\ne09bd0f03f71d5ca9e1db6804ac28f2470eb70db 172.18.0.7:6379@16379 myself,slave 82d2bee961c7a4b73f099550d72a232e55d12d60 0 1683707449000 2 connected\n8cb609962e074807b56f1a01bbbde3e6a436e7ca 172.18.0.3:6379@16379 master - 0 1683707450331 1 connected 0-5460\n7dd24d5ffc732189f7b32a5468d9b20ebc1f60d7 172.18.0.5:6379@16379 master - 0 1683707450000 3 connected 10923-16383\nc02f2c7285074d9d5b23b8faf07ec287c6e94636 172.18.0.4:6379@16379 slave 8cb609962e074807b56f1a01bbbde3e6a436e7ca 0 1683707449316 1 connected\n5105b2780cabbff516e0f834a694bcdca310e8b7 172.18.0.6:6379@16379 slave 7dd24d5ffc732189f7b32a5468d9b20ebc1f60d7 0 1683707448291 3 connected\n```\n\nYou can now set a value in the cluster:\n\n```bash\nSET key \"value\"\n```\n\n```\n127.0.0.1:6379\u003e SET key \"value\"\n-\u003e Redirected to slot [12539] located at 172.18.0.5:6379\nOK\n```\n\n### 3. Running the Example Application\n\nStart the application configured for the Redis cluster:\n\n```bash\nyarn run start:multiple\n```\n\n### 4. Test the Application\n\nTest the APIs as follows:\n\n- API without Redis caching: `/getphoto`\n- API with Redis caching: `/getphoto-redis`\n\n## Outside Docker Network (MacOS)\n\nFor MacOS, to connect to the Redis cluster from outside the Docker network, first retrieve your external host IP:\n\n```bash\necho \"$(route get uninterrupted.tech | grep interface | sed -e 's/.*: //' | xargs ipconfig getifaddr)\"\n```\n\nUpdate the `REDIS_NODES` environment variable in the `docker-compose.yml` file with the retrieved IP:\n\n```yaml\nREDIS_NODES: \u003cexternal_ip\u003e:6370 \u003cexternal_ip\u003e:6371 \u003cexternal_ip\u003e:6372 \u003cexternal_ip\u003e:6373 \u003cexternal_ip\u003e:6374 \u003cexternal_ip\u003e:6375\n```\n\nYou can then connect to the Redis cluster and run the `CLUSTER NODES` command as described earlier.\n```\n❯ redis-cli -c -h 192.168.1.13 -p 6375\n127.0.0.1:6375\u003e CLUSTER NODES\n275c337ffe6073071088bb0706a2536608c03fe9 192.168.1.184:6372@16372 master - 0 1683717016000 3 connected 10923-16383\n0e779e30ce3879ee37b470b299a97d41c0e16779 192.168.1.184:6370@16370 master - 0 1683717018000 1 connected 0-5460\n3e7dc06681938425f71a39a2a7d189b336132e4a 192.168.1.184:6374@16374 slave 0e779e30ce3879ee37b470b299a97d41c0e16779 0 1683717020706 1 connected\n841b05c2890454b345da8380ee63fa41c03fae6b 192.168.1.184:6371@16371 master - 0 1683717020000 2 connected 5461-10922\n44444520eb2bbc346ab4dba9b1c495973399a227 192.168.1.184:6375@16375 myself,slave 841b05c2890454b345da8380ee63fa41c03fae6b 0 1683717017000 2 connected\n8f14d7d1faac0e131d315ee34c0c7fc3836716c9 192.168.1.184:6373@16373 slave 275c337ffe6073071088bb0706a2536608c03fe9 0 1683717019000 3 connected\n```\n\n## More Question:\n\nSee documentation [here](common_question.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsun1211%2Fredis-cluster-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsun1211%2Fredis-cluster-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsun1211%2Fredis-cluster-tutorial/lists"}