Redis的安装
-
上传
redis-3.x.x.tar.gz
到linux虚拟机的/opt
文件夹 -
安装gcc
[root@localhost ~]# yum install -y gcc
-
解压缩
redis-3.x.x.tar.gz
[root@localhost opt]# tar xzvf redis-3.0.7.tar.gz
-
进入到redis根目录,进行编译、安装
[root@localhost redis-3.0.7]# make [root@localhost redis-3.0.7]# make install
-
将
redis-3.x.x/redis.conf
复制到/etc/redis/
目录下[root@localhost redis-3.0.7]# mkdir -p /etc/redis/ [root@localhost redis-3.0.7]# cp redis.conf /etc/redis/
-
启动redis
redis 默认端口号 6379
[root@localhost redis-3.0.7]# redis-server /etc/redis/redis.conf 6255:M 08 Jun 00:19:28.368 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 6255 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
3 Redis客户端的使用
在xshell中复制一个连接虚拟机的窗口。
-
打开客户端
[root@localhost ~]# redis-cli 127.0.0.1:6379>
-
关闭redis数据库
127.0.0.1:6379> shutdown not connected>
-
关闭客户端
not connected> exit [root@localhost ~]#
String类型数据的操作
Redis是k-v数据格式的数据库,v有多种类型,下面演示v为字符串的操作。
key(String类型)-value(String类型)
-
增
127.0.0.1:6379> set zhangsan 123456 OK 127.0.0.1:6379> get zhangsan "123456"
-
查
查看所有的 key 127.0.0.1:6379> keys * 1) "age" 2) "name" 127.0.0.1:6379> get name "xushy" 127.0.0.1:6379> get age "18"
-
改
127.0.0.1:6379> set name liy OK 127.0.0.1:6379> set age 16 OK 127.0.0.1:6379> get name "liy" 127.0.0.1:6379> get age "16"
-
删
127.0.0.1:6379> del name (integer) 1 127.0.0.1:6379> del age (integer) 1 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> get age (nil)
特别注意:
- 字符串外的单引号或双引号可以省略
- 命令结束直接回车,不要添加分号