linux的shell腳本管理redis鍵值

初始目標:通過linux腳本讀取redisserver的某個鍵值

腳本如下:

 

##########################################

# example1: ./getredis.sh [key] 

# example2: ./getredis.sh [key] (ttl) #()include commands:get,ttl,exists,del,strlen,type,persist,watch,incr,decr

# example3: ./getredis.sh [key] (incr)

# example5: ./getredis.sh [a] session #查看PHPREDIS_SESSION 開頭的字母

# example4: ./getredis.sh [a] like

# example5: ./getredis.sh info

# example5: ./getredis.sh |more

# example5: ./getredis.sh |grep PHP

##########################################

#!/bin/sh

host="192.168.11.12"

port="6379"

if [ $# -eq 1 ];then

if [ $1 == "info" ];then

redis-cli -h $host -p $port info

else

# if input one arg then get the key values

redis-cli -h $host -p $port   keys $1 |  xargs redis-cli -h $host -p $port get

fi

elif [ $# -eq 2 ];then

    # if input two arg then get the second commad values

# get,ttl,exists,del,strlen,type,persist,watch,incr,decr 

if [ $2 == "like" ];then

#like is a*

redis-cli -h $host -p $port   keys $1*

elif [ $2 == "session" ];then

redis-cli -h $host -p $port   keys PHPREDIS_SESSION:$1*

else

   redis-cli -h $host -p $port   keys $1 |  xargs redis-cli -h $host -p $port  $2

fi

else

redis-cli -h $host -p $port   keys "*"

fi

 
 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章