最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解如何清理redis集群的所有數(shù)據(jù)

 更新時間:2021年02月18日 16:05:10   作者:前路無畏  
這篇文章主要介紹了詳解如何清理redis集群的所有數(shù)據(jù),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1. 背景:生產(chǎn)測試后redis中產(chǎn)生大量數(shù)據(jù)

生產(chǎn)前需要清理reids集群中的數(shù)據(jù)。、
你看有很多key呢:

使用工具

在這里插入圖片描述

使用命令,查看是否有數(shù)據(jù):

keys * 

在這里插入圖片描述

2. 清理步驟

2.1 任意登錄一臺redis機器

執(zhí)行下面腳本:

clear_redis_cluster.sh 10.1.33.101:8001 redis

在這里插入圖片描述

執(zhí)行日志如下:

在這里插入圖片描述

Clearing 10.1.33.112:8028 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.110:8026 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.111:8027 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.107:8007 ...
Background append only file rewriting started
OK
Clearing 10.1.33.108:8024 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.104:8020 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.114:8014 ...
Background append only file rewriting started
OK
Clearing 10.1.33.109:8025 ...
Background append only file rewriting started
READONLY You can't write against a read only replica. 
Clearing 10.1.33.105:8005 ...
Background append only file rewriting started
OK
Clearing 10.1.33.108:8008 ...
Background append only file rewriting started
OK

2.2 clear_redis_cluster.sh內(nèi)容

#!/bin/bash
# Writed by yijian on 2018/8/20
# Batch to clear all nodes using FLUSHALL command
# 用來清空一個redis集群中的所有數(shù)據(jù),要求 FLUSHALL 命令可用,
# 如果在 redis.conf 中使用 rename 改名了 FLUSHALL,則不能執(zhí)行本腳本。
# 可帶兩個參數(shù):
# 1)參數(shù)1 集群中的任一可用節(jié)點(必須)
# 2)連接redis的密碼(設置了密碼才需要)
REDIS_CLI=${REDIS_CLI:-redis-cli}
REDIS_IP=${REDIS_IP:-127.0.0.1}
REDIS_PORT=${REDIS_PORT:-6379}

# 顯示用法函數(shù)
function usage()
{
  echo "Usage: clear_redis_cluster.sh a_redis_node_of_cluster redis_password"
  echo "Example1: clear_redis_cluster.sh '127.0.0.1:6379'"
  echo "Example2: clear_redis_cluster.sh '127.0.0.1:6379' '123456'"
}

# 檢查參數(shù)個數(shù)
if test $# -lt 1 -o $# -gt 2; then
  usage
  exit 1
fi

# 第一個參數(shù)為集群中的節(jié)點,
REDIS_NODE="$1"
# 第二個參數(shù)為密碼
REDIS_PASSWORD=""
if test $# -ge 2; then
  REDIS_PASSWORD="$2"
fi

# 取得IP和端口
eval $(echo "$REDIS_NODE" | awk -F[\:] '{ printf("REDIS_IP=%s\nREDIS_PORT=%s\n",$1,$2) }')
if test -z "$REDIS_IP" -o -z "$REDIS_PORT"; then
  echo "Parameter error: \`$REDIS_NODE\`."
  usage
  exit 1
fi

# 確保redis-cli可用
echo "Checking \`redis-cli\` ..."
which "$REDIS_CLI" > /dev/null 2>&1
if test $? -ne 0; then
  echo "Command \`redis-cli\` is not exists or not executable."
  echo "You can set environment variable \`REDIS_CLI\` to point to the redis-cli."
  echo "Example: export REDIS_CLI=/usr/local/bin/redis-cli"
  exit 1
fi

if test -z "$REDIS_PASSWORD"; then
  redis_nodes=`redis-cli -h $REDIS_IP -p $REDIS_PORT cluster nodes | awk -F[\ \:\@] '!/ERR/{ printf("%s:%s\n",$2,$3); }'`
else
  redis_nodes=`redis-cli --no-auth-warning -a "$REDIS_PASSWORD" -h $REDIS_IP -p $REDIS_PORT cluster nodes | awk -F[\ \:\@] '!/ERR/{ printf("%s:%s\n",$2,$3); }'`
fi
if test -z "$redis_nodes"; then
  # Standlone(非集群)
  if test -z "$REDIS_PASSWORD"; then
    $REDIS_CLI -h $REDIS_IP -p $REDIS_PORT FLUSHALL ASYNC
    $REDIS_CLI -h $REDIS_IP -p $REDIS_PORT BGREWRITEAOF
  else
    $REDIS_CLI --no-auth-warning -a "$REDIS_PASSWORD" -h $REDIS_IP -p $REDIS_PORT FLUSHALL ASYNC
    $REDIS_CLI --no-auth-warning -a "$REDIS_PASSWORD" -h $REDIS_IP -p $REDIS_PORT BGREWRITEAOF
  fi
else
  # Cluster(集群)
  for redis_node in $redis_nodes;
  do
    if test ! -z "$redis_node"; then
      eval $(echo "$redis_node" | awk -F[\:] '{ printf("redis_node_ip=%s\nredis_node_port=%s\n",$1,$2) }')

      if test ! -z "$redis_node_ip" -a ! -z "$redis_node_port"; then
        # clear
        echo -e "Clearing \033[1;33m${redis_node_ip}:${redis_node_port}\033[m ..."
        if test -z "$REDIS_PASSWORD"; then
          result=`$REDIS_CLI -h $redis_node_ip -p $redis_node_port FLUSHALL ASYNC`
          $REDIS_CLI -h $redis_node_ip -p $redis_node_port BGREWRITEAOF
        else
          result=`$REDIS_CLI --no-auth-warning -a "$REDIS_PASSWORD" -h $redis_node_ip -p $redis_node_port FLUSHALL ASYNC`
          $REDIS_CLI --no-auth-warning -a "$REDIS_PASSWORD" -h $redis_node_ip -p $redis_node_port BGREWRITEAOF
        fi

        if test ! -z "$result"; then
          # SUCCESS
          if test "$result" = "OK"; then
            echo -e "\033[0;32;32m$result\033[m"
          else
            echo -e "\033[0;32;31m$result\033[m"
          fi
        fi
      fi
    fi
  done
fi

這位仁兄的腳本寫的特別好。直接執(zhí)行即可。

2.3 確認刪除成功

使用redis工具查看:

在這里插入圖片描述

3.清理單機redis

flushall 

4.總結(jié)

使用腳本刪除redis集群中的數(shù)據(jù)。
記得地址哦:
https://github.com/eyjian/redis-tools/blob/master/clear_redis_cluster.sh

到此這篇關(guān)于詳解如何清理redis集群的所有數(shù)據(jù)的文章就介紹到這了,更多相關(guān)清理redis集群數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Redis解決Session共享問題的方法詳解

    Redis解決Session共享問題的方法詳解

    這篇文章主要為大家詳細介紹了分布式系統(tǒng)Redis解決Session共享問題的方法,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2022-07-07
  • ELK配置轉(zhuǎn)存redis緩存采集nginx訪問日志的操作方法

    ELK配置轉(zhuǎn)存redis緩存采集nginx訪問日志的操作方法

    本文介紹了在服務器上部署MySQL及如何啟動MySQL服務,并詳細說明了如何查找安裝軟件的日志文件位置,通過使用rpm命令查詢MySQL服務的日志文件位置,以及通過編輯Logstash配置文件來添加MySQL日志信息,感興趣的朋友一起看看吧
    2024-11-11
  • Spring?Boot實戰(zhàn)解決高并發(fā)數(shù)據(jù)入庫之?Redis?緩存+MySQL?批量入庫問題

    Spring?Boot實戰(zhàn)解決高并發(fā)數(shù)據(jù)入庫之?Redis?緩存+MySQL?批量入庫問題

    這篇文章主要介紹了Spring?Boot實戰(zhàn)解決高并發(fā)數(shù)據(jù)入庫之?Redis?緩存+MySQL?批量入庫問題,本文通過圖文實例相結(jié)合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • redis調(diào)用二維碼時的不斷刷新排查分析

    redis調(diào)用二維碼時的不斷刷新排查分析

    這篇文章主要為大家介紹了redis調(diào)用二維碼時不斷刷新排查分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪
    2022-04-04
  • 一文帶你了解Redis的三種集群模式

    一文帶你了解Redis的三種集群模式

    Redis?的常用的集群方式主要有以下三種,分別是主從復制模式、哨兵模式、Redis-Cluster集群模式,那么下面我們就分別了解一下這三種集群模式的優(yōu)點與缺點
    2023-06-06
  • 基于Redis實現(xiàn)短信驗證碼登錄項目示例(附源碼)

    基于Redis實現(xiàn)短信驗證碼登錄項目示例(附源碼)

    手機登錄驗證在很多網(wǎng)頁上都得到使用,本文主要介紹了基于Redis實現(xiàn)短信驗證碼登錄項目示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • Redis實現(xiàn)事物以及鎖的方法

    Redis實現(xiàn)事物以及鎖的方法

    本文主要介紹了Redis實現(xiàn)事物以及鎖的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • SpringSession通過Redis統(tǒng)計在線用戶數(shù)量的實現(xiàn)代碼

    SpringSession通過Redis統(tǒng)計在線用戶數(shù)量的實現(xiàn)代碼

    這篇文章主要介紹了SpringSession通過Redis統(tǒng)計在線用戶數(shù)量,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • 解決Redis分布式鎖的誤刪問題和原子性問題

    解決Redis分布式鎖的誤刪問題和原子性問題

    Redis的分布式鎖是通過利用Redis的原子操作和特性來實現(xiàn)的,為了保證數(shù)據(jù)的一致性和避免沖突,可以使用分布式鎖來進行同步控制,本文給大家介紹了如何解決Redis分布式鎖的誤刪問題和原子性問題,需要的朋友可以參考下
    2024-02-02
  • redis做websocket分布式消息推送服務的實現(xiàn)

    redis做websocket分布式消息推送服務的實現(xiàn)

    本文介紹了使用Redis作為消息隊列實現(xiàn)WebSocket分布式消息推送服務的方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-12-12

最新評論

安溪县| 安宁市| 出国| 宝兴县| 弋阳县| 临夏市| 平湖市| 濮阳市| 兰考县| 巴彦县| 西乡县| 黎城县| 梓潼县| 饶平县| 偏关县| 融水| 巴青县| 建瓯市| 饶平县| 湘潭县| 宜君县| 汤原县| 淮阳县| 读书| 鄯善县| 固安县| 和平县| 类乌齐县| 宁国市| 泰和县| 望江县| 山阴县| 芒康县| 凌源市| 临武县| 聂荣县| 云南省| 浮山县| 滕州市| 多伦县| 聂拉木县|