Redis Cluster 工具

news/2024/8/20 17:10:43 标签: redis, 数据库, 缓存

脚本 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)

http://www.niftyadmin.cn/n/5555543.html

相关文章

nginx系统环境准备

文章目录 1、确认centos的内核2、确保centos能联网3、确认关闭防火墙3.1、systemctl status firewalld 4、确认停用selinux 1、确认centos的内核 准备一个内核为2.6及以上版本的操作系统&#xff0c;因为linux2.6及以上内核才 支持epoll,而Nginx需要解决高并发压力问题是需要用…

Celery 是一个简单、灵活且可靠的分布式系统——python库

目录 引言 Celery 是什么&#xff1f; 安装 Celery 配置 Celery 创建任务 运行 Celery Worker 调用任务 更多示例 示例 1&#xff1a;发送电子邮件 示例 2&#xff1a;图片处理 示例 3&#xff1a;数据处理 结论 引言 今天我们来分享一个超强的 python 库&#xf…

sqllab靶场通过,及sql注入总结(注入点,sqlmap使用)

Sql注入笔记 思维导图 注入类型 普通注入 报错注入 盲注 SQL写马注入 普通注入 靶场练习 https://github.com/Audi-1/sqli-labs 注入流程 1&#xff0c;通过and 11得到报错类型&#xff08;int&#xff0c;string&#xff09; 2&#xff0c;得到闭合方式,order by 猜…

【可视化大屏系列】Echarts之折线图绘制

本文为个人近期学习总结,若有错误之处,欢迎指出! Echarts之折线图绘制 前言1.需求2.实现效果3.大概思路4.代码实现子组件写法父组件写法前言 在前文页面布局、DataV 的使用、Echarts 的基础使用的基础上,开始绘制大屏中的折线图。 1.需求 绘制近一周来三种蔬菜的销售量趋…

Java二十三种设计模式-工厂方法模式(2/23)

工厂方法模式&#xff1a;设计模式中的瑞士军刀 引言 在软件开发中&#xff0c;工厂方法模式是一种常用的创建型设计模式&#xff0c;它用于处理对象的创建&#xff0c;将对象的实例化推迟到子类中进行。这种模式不仅简化了对象的创建过程&#xff0c;还提高了代码的可维护性…

网线8芯分开4芯一组

一、网线如何一分为二 网线通常包含8根线芯&#xff0c;这8根线芯在标准的以太网连接中都有其特定的作用&#xff0c;但并非所有线芯在较低速率的网络连接中都是必要的。 1、网线线芯的作用 在标准的1000Mbps&#xff08;千兆&#xff09;以太网连接中&#xff0c;所有的8根…

《基于深度学习的车辆重识别算法研究与系统实现》论文分析概要

目录 一、选题背景与研究意义 二、国内外研究现状 三、算法创新点 四、实验与结果分析 五、系统实现 六、总结与展望 本文题为《基于深度学习的车辆重识别算法研究与系统实现》,由华东师范大学齐恬恬撰写,旨在研究利用深度学习技术提升车辆重识别的精度,并搭建…

代码随想录算法训练营第三十一天

509. 斐波那契数 可以不用动归也能做出来 class Solution { public:int fib(int n) {int last_last 0;int last 1;int now 0;if (n 0) return 0;if (n 1) return 1;while(n > 1) {now last last_last;last_last last;last now;n--;}return now;} }; 但这里要练一…