redis安装和redis-cli

https://redis.io/documentation

1、安装

wget http://download.redis.io/releases/redis-4.0.2.tar.gz -O /tmp/redis-4.0.2.tar.gz
cd /tmp
tar xf redis-4.0.2.tar.gz
cd redis-4.0.2
make
make install   只是安装二进制文件,默认将二进制文件安装到/usr/local/bin
make  PREFIX=/usr/local/redis install

2、启动

redis-server 
指定配置文件启动(可以设置认证码)
cp /tmp/redis-4.0.2/redis.conf  /etc/redis.conf
redis-server /etc/redis.conf  

3、测试是否正常

#redis-cli ping
PONG

redis-cli
命令行接口command line interface
模式:命令行|交互式

1、命令行

# redis-cli -h |more
  -h       
  -p           
  -s         
  -a       
  -r      -1:无限次   
  -i      
  -n 

# redis-cli --version
redis-cli 4.0.2
# redis-cli incr mycounter
(integer) 1
# redis-cli get mycounter
"1"
# redis-cli --raw get mycounter
1
连续查询某个key
# redis-cli  -r -1 -i 1 get mycounter

2、交互式

# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> dbsize
(integer) 0
127.0.0.1:6379[1]> set mycounter 1
OK
127.0.0.1:6379[1]> 3 get mycounter  //3次获取该key
"1"
"1"
"1"

3、快速批量导入数据(https://redis.io/topics/mass-insert)

#cat data.txt | redis-cli --pipe
All data transferred. Waiting for the last reply...
ERR unknown command 'ET'
Last reply received from server.
errors: 1, replies: 2
解决:
需要格式转换
#unix2dos data.txt

4、特殊的操作模式

监控redis server的状态
$ redis-cli --stat -i 

扫描大的key
$ redis-cli --bigkeys

以list获取所有keys
$ redis-cli --scan 
$ redis-cli --scan |wc -l  //key的总数
$ redis-cli --scan --pattern '*-11*'   //匹配某类key

监控redis命令使用情况
$ redis-cli monitor

监控redis的延迟
$ redis-cli --latency
min: 0, max: 1, avg: 0.19 (427 samples)
--latency:ping命令测试,每秒100次

$ redis-cli --latency-history   //15分钟取样一次
min: 0, max: 1, avg: 0.14 (1314 samples) -- 15.01 seconds range
min: 0, max: 1, avg: 0.18 (1299 samples) -- 15.00 seconds range
min: 0, max: 1, avg: 0.20 (113 samples)^C

$ redis-cli --latency -i  //指定取样间隔


$redis-cli --intrinsic-latency 5
--intrinsic-latency
 It does not check the latency of a Redis instance, but the latency of the computer you are running redis-cli on. 

你可能感兴趣的:(redis)