DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Working With Geospatial Data in Redis
  • Basic CRUD Operations Using Hasura GraphQL With Distributed SQL on GKE
  • Performance and Scalability Analysis of Redis and Memcached
  • Techniques for Chaos Testing Your Redis Cluster

Trending

  • The Role of AI in Low- and No-Code Development
  • 10 ChatGPT Prompts To Boost Developer Productivity
  • Mastering Distributed Caching on AWS: Strategies, Services, and Best Practices
  • Data Integration Technology Maturity Curve 2024-2030
  1. DZone
  2. Data Engineering
  3. Data
  4. How To Manage Redis Cluster Topology With Command Line

How To Manage Redis Cluster Topology With Command Line

Understanding and managing Redis cluster topology is crucial. Learn commands are extremely helpful in managing and troubleshooting Redis cluster topology.

By 
Rahul Chaturvedi user avatar
Rahul Chaturvedi
·
May. 30, 24 · Tutorial
Like (3)
Save
Tweet
Share
3.3K Views

Join the DZone community and get the full member experience.

Join For Free

Manual intervention is often necessary to understand and manage the current topology of a Redis cluster. This article covers essential commands for interacting with and managing the Redis cluster, along with retrieving its state information.

CLUSTER INFO

This command gives you an overview of your Redis cluster, including details about key distribution, participating nodes, cluster size, and message statistics.


CLUSTER NODES

With CLUSTER NODES, find information about the nodes that are a part of the Redis cluster.


Questions

  • How many nodes are part of the cluster?
    • The total number of rows shows the number of nodes that are a part of this Redis cluster. The cluster above has 6 nodes. 
  • What are the IPs or ports on which these nodes are present?
    • In this IP is 127.0.0.1 and port is 30005 for this node.

  • Is a node primary or replica?
    • One of the primary nodes in the cluster above:
    • One of the replica nodes in the cluster above:
  • What’s the unique node ID of the node? 
    • In the above row, 717d7a44655dad4a1ec6879c6894c0fdb02d0d6c is the unique ID of the node.

  • Is the node connected or not? 
    • The string “connected” in the picture below shows the node is connected.
    • The string “disconnected” in the picture below shows the node is disconnected. Also, the status is “fail”.

CLUSTER SLOTS

This command provides the mapping of the hash slots to cluster nodes so that we can identify which slots are served with which primary and replica nodes.

The output displays information about each hash slot in the cluster. Notably, the first node ID listed for each slot corresponds to the primary node holding that slot's data, while the second node ID represents its replica.

CLUSTER FORGET <node_id>

A troubled node within your Redis cluster can lead to slow response times for client requests. To maintain optimal performance and avoid latency spikes, the CLUSTER FORGET command allows you to proactively remove the problematic node from the cluster, directing client requests to healthy nodes.

  • Note: You need to run this command on all the remaining nodes so they update their own copy topology (nodes table) which is maintained on each node. This can be accomplished by running a script that can loop over all remaining nodes (except the one that needs to be removed).
Shell
 
for port in {30001..30006}; do
  # Run the CLUSTER FORGET command for each node
  redis-cli -p $port CLUSTER FORGET $NODE_ID
done


Before removing the node:

We can see the node with the id 717d7a44655dad4a1ec6879c6894c0fdb02d0d6c and port 30003 is present in the cluster. 

Now we can run a script like this:

Shell
 
NODE_ID="717d7a44655dad4a1ec6879c6894c0fdb02d0d6c"

for port in {30001..30006}; do
  redis-cli -p $port CLUSTER FORGET $NODE_ID
done


After running the script:

We can now see the node with the id 717d7a44655dad4a1ec6879c6894c0fdb02d0d6c and port 30003 is not present and hence not a part of the cluster. 

  • Note: This Redis node with id 717d7a44655dad4a1ec6879c6894c0fdb02d0d6c and port 30003 is still running, but not a part of the cluster anymore.

CLUSTER MEET <ip> <port>

When your Redis cluster needs to grow, the CLUSTER MEET command comes in handy. It lets you seamlessly add new nodes to distribute the workload. Additionally, if you previously removed a node due to problems (as we did above using CLUSTER FORGET), you can use CLUSTER MEET to reintroduce it to the cluster once the issues are fixed.

Before running the cluster meet (node with port 30003 is not a part of the cluster):

Run the command:

After running the command:

We can see that the node with port 30003 is again a part of the cluster now.

CLUSTER REPLICATE <primary_node_id>

Expanding a Redis cluster involves not just adding nodes but also configuring them for high availability. This command helps us achieve that by promoting a new node to become a replica of an existing node (identified by its ID). This ensures data redundancy and allows clients to access replicas if the primary node fails.

References

  • Redis Documentation: Commands
Data redundancy cluster Command (computing) Data (computing) Redis (company)

Opinions expressed by DZone contributors are their own.

Related

  • Working With Geospatial Data in Redis
  • Basic CRUD Operations Using Hasura GraphQL With Distributed SQL on GKE
  • Performance and Scalability Analysis of Redis and Memcached
  • Techniques for Chaos Testing Your Redis Cluster

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: