Redis Cluster 工具

脚本 1

slots.sh

#!/bin/bash

# Connect to Redis Cluster and retrieve node information
nodes_info= echo  "CLUSTER NODES" | rd  10.XX.33.202    6011

# Check if redis-cli command executed successfully
if [ $? -ne 0 ]; then
    echo "Error: Unable to connect to Redis Cluster or retrieve node information."
    exit 1
fi

# Loop through each line of node information
while IFS= read -r line; do
    # Extract the slot information from the line
    slots=$(echo "$line" | awk '{print $9}')
    
    # Check if the line contains slot information (exclude empty lines)
    if [ -n "$slots" ]; then
        # Count the number of slots for each node
        node_slots=$(echo "$slots" | tr -cd , | wc -c)
        echo "$line" | awk -v slots="$node_slots" '{print $2 " has " slots " slots."}'
    fi
done <<< "$nodes_info"

get_slots.py

import sys

def calculate_slot_count_from_file(file_path):
    print(file_path)
    try:
        with open(file_path, 'r') as file:
            cluster_info = file.read()
            for line in cluster_info.splitlines():
                if "master" not in line:
                  continue
                node = line.split(" ")[1].split("@")[0]
                slot_info = line.split("connected")[1]
                slot_count = 0
                for num in slot_info.split(" "):
                    if len(num.strip()) == 0:
                        continue
                    count = int(num.split('-')[1]) - int(num.split('-')[0]) + 1
                    slot_count += count
                print("Node:", node, "Slot count:", slot_count)
    except FileNotFoundError:
        print("Error: File not found.")

# Check if the correct number of arguments is provided
if len(sys.argv) != 2:
    print("Usage: python get_slots_info.py <file_path>")
    sys.exit(1)

file_path = sys.argv[1]
calculate_slot_count_from_file(file_path)

相关推荐

  1. RedisCluster集群扩容

    2024-07-15 19:20:02       63 阅读
  2. 工具清单 - IDE工具

    2024-07-15 19:20:02       40 阅读
  3. 工具:Jupyter

    2024-07-15 19:20:02       57 阅读
  4. ffplay工具

    2024-07-15 19:20:02       67 阅读
  5. ffprobe工具

    2024-07-15 19:20:02       63 阅读
  6. 工具:Peach

    2024-07-15 19:20:02       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 19:20:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 19:20:02       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 19:20:02       58 阅读
  4. Python语言-面向对象

    2024-07-15 19:20:02       69 阅读

热门阅读

  1. leensa注册码

    2024-07-15 19:20:02       26 阅读
  2. vue 导出excel乱码问题

    2024-07-15 19:20:02       15 阅读
  3. tomcat

    tomcat

    2024-07-15 19:20:02      19 阅读
  4. C++ STL中的std::remove_if 的用法详解

    2024-07-15 19:20:02       21 阅读
  5. iOS ------ ARC的工作原理

    2024-07-15 19:20:02       22 阅读