赞
踩
key-value 键值对类型
string 字符串(可以是整形,浮点型,字符型,统称为元素)
list 列表(实现队列形式,元素不唯一)
set 集合(各不相同的元素,分有序和无序)
hash hash散列值
[root@localhost ~]# yum -y install gcc gcc-c++ make
[root@localhost ]# tar zxf redis-5.0.7.tar.gz
[root@localhost redis-5.0.7]# cd redis-5.0.7/
[root@localhost redis-5.0.7]# make PREFIX=/usr/local/redis install //因为Redis源码包中直接提供了Makefile文件,所以不用执行./configure配置,可以直接执行make
[root@localhost redis-5.0.7]# cd utils/
[root@localhost utils]# ./install_server.sh
Please select the redis executable path [] /usr/local/redis/bin/redis-server
[root@localhost utils]# ln -s /usr/local/redis/bin/* /usr/local/bin/
[root@localhost utils]# netstat -antp | grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 122058/redis-server
[root@localhost utils]# vim /etc/redis/6379.conf
70 bind 127.0.0.1 192.168.1.5 //添加监听的主机地址
93 port 6379 //默认监听端口
137 daemonize yes //开启守护进程模式
159 pidfile /var/run/redis_6379.pid //指定pid文件路径
167 loglevel notice //设置日志的级别
172 logfile /var/log/redis_6379.log //指定日志文件路径
-h //指定服务器主机名
-p //指定服务器端口号
-s //指定服务器套接字
-c //指定并发连接数
-n //指定请求数
-d //以字节形式指定set/get值的数据大小
-k //1是keep alive 0是reconnect
-r //set/get/incr是用随机key,sadd使用随机值
-p //通过管道传输<numreq>请求
-q //强制退出redis
--csv //以csv格式输出
-l //生成循环,一直执行测试
-t //仅运行以逗号分隔的测试命令列表
-I //idle模式,打开n个idle连接并等待
[root@localhost utils]# redis-benchmark -h localhost -p 6379 -q -d 110 PING_INLINE: 154320.98 requests per second PING_BULK: 163398.70 requests per second SET: 180505.41 requests per second GET: 156985.86 requests per second INCR: 177304.97 requests per second LPUSH: 187617.27 requests per second RPUSH: 181159.42 requests per second LPOP: 181159.42 requests per second RPOP: 180831.83 requests per second SADD: 162074.56 requests per second HSET: 154083.20 requests per second SPOP: 154083.20 requests per second LPUSH (needed to benchmark LRANGE): 178571.42 requests per second LRANGE_100 (first 100 elements): 45106.00 requests per second LRANGE_300 (first 300 elements): 15772.87 requests per second LRANGE_500 (first 450 elements): 9212.34 requests per second LRANGE_600 (first 600 elements): 6876.16 requests per second MSET (10 keys): 102774.92 requests per second
[root@localhost utils]# redis-benchmark -t set,lpush -n 100000 -q
SET: 175131.36 requests per second
LPUSH: 182149.36 requests per second
-h //指定远程主机
-p //指定Redis的服务端口号
-a //指定密码,未设置密码可以省略此选项
若不加任何参数表示使用127.0.0.1:6379连接本机的redis数据库
[root@localhost utils]# /etc/init.d/redis_6379 restart
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...
[root@localhost utils]# redis-cli -h 192.168.1.5 -p 6379
192.168.1.5:6379>
192.168.1.5:6379> set test zhangsan
OK
192.168.1.5:6379> get test
"zhangsan"
192.168.1.5:6379> keys *
1) "k2"
2) "myset:__rand_int__"
3) "key:__rand_int__"
4) "mylist"
5) "k1"
6) "test"
7) "counter:__rand_int__"
192.168.1.5:6379> KEYS k*
1) "k2"
2) "key:__rand_int__"
3) "k1"
192.168.1.5:6379> KEYS k?
1) "k2"
2) "k1"
192.168.1.5:6379> KEYS k??
1) "k22"
192.168.1.5:6379> exists k
(integer) 0 //0代表不存在
192.168.1.5:6379> exists k1
(integer) 1 //1代表存在
192.168.1.5:6379> del k1
(integer) 1
192.168.1.5:6379> get k1
(nil)
192.168.1.5:6379> type k2
string
192.168.1.5:6379> rename k2 k
OK
192.168.1.5:6379> get k2
(nil)
192.168.1.5:6379> get k
"2"
192.168.1.5:6379> rename k22 k
OK
192.168.1.5:6379> get k
"12"
192.168.1.5:6379> get k1
"2"
192.168.1.5:6379> get k3
"3"
192.168.1.5:6379> renamenx k1 k3 //n代表不进行修改,x进行修改,对已有的新名不进行修改
(integer) 0
192.168.1.5:6379> get k1
"2"
192.168.1.5:6379> get k3
"3"
192.168.1.5:6379> select 10 //切换到10号库,一共0-15个库
OK
192.168.1.5:6379[10]>
192.168.1.5:6379> get k1
"2"
192.168.1.5:6379> move k1 1
(integer) 1
192.168.1.5:6379> select 1
OK
192.168.1.5:6379[1]> get k1
"2"
192.168.1.5:6379[1]> flushdb //清空当前数据库数据
OK
192.168.1.5:6379[1]> get k1
(nil)
192.168.1.5:6379[1]> flushall //清空所有数据库的数据,慎用
OK
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。