redis 常用方法整理
1、进入redis
redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL
2、查询keys
keys activity_mobile_*
3、赋值、查值、删除
set mykey 1 get mykey
del mykey
4、批量删除
[milan@redis-50-240 ~]$ redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL keys 'abc*' | xargs redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL del
5、一次查询多个key 文件名 milan_vikeys
echo $1 echo $2 echo '---------------cat-------------------------------' redis-cli -p 6379 -h 192.168.0.100 -a 9D0X0jZFsxN6 keys *$1* echo '---------------coupon-------------------------------' redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL keys *$1* echo '---------------coupon-------------------------------' redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL keys *$2* echo '----------------------------------------------' echo '------mobile_count-------' redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL get csp_activity_mobile_1512704178992738_$1 echo '------user_count-------' redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL get csp_activity_user_1512704178992738_$2
#调用
sh milan_vikeys abc
6、一次性删除多个keys 文件名 milan_del
redis-cli -p 6379 -h 192.168.0.100 -a 9D0X0jZFsxN6 keys *$1* | xargs redis-cli -p 6379 -h 192.168.0.100 -a 9D0X0jZFsxN6 del redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL keys *$2* | xargs redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL del redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL keys ASH_ACTIVITY_BASE_CONF_IDX_1512704178992738 | xargs redis-cli -p 6409 -h 192.168.0.100 -a q9pCeAEMAWEL del