初始目标:通过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