版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zx711166/article/details/82700003
Redis安装(Linux)
1、下载并解压
cd /home/john/redis
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
tar -zxvf redis-3.2.11.tar.gz
2、建立软连接
方便版本后续的版本升级
ln -s redis-3.2.11 redis
3、编译安装
cd redis-3.2.11
make && make install
Redis可执行文件说明
src目录下
- redis-server:Redis服务器
- redis-cli:Reids命令行客户端
- redis-benchmark:Redis性能测试工具
- redis-check-aof:AOF文件修复工具
- redis-check-dump:RDB文件修复工具
- redis-sentinel:Sentinel服务器(v2.8及以上版本)
Redis三种启动方式
- 最简启动:直接执行redis-server,将使用Redis默认配置启动。
//查看redis端口是否启动成功
ps -ef|grep redis
netstat -antpl|grep redis
redis -cli -h ip -p port ping
- 动态参数启动:redis-server --port 6380
- 配置文件启动:redis-server configPath
三种启动方式的比较
- 生产环境选择配置启动
- 单机多实例配置文件可以用端口区分
Redis客户端连接
[root@localhost ~]# redis-cli -h 192.168.138.128 -p 6379
192.168.138.128:6379> ping
PONG
192.168.138.128:6379> set hello world
OK
192.168.138.128:6379> get hello
"world"
Redis客户端返回值
- 状态回复
192.168.138.128:6379> ping
PONG
- 错误回复
192.168.138.128:6379> hget hello field
(error) WRONGTYPE Operation against
- 整数回复
192.168.138.128:6379> incr hello
(integer) 1
- 字符串回复
192.168.138.128:6379> get hello
"world"
- 多行字符串回复(返回key为hello和foo的值)
192.168.138.128:6379> mget hello foo
1) "world"
2) "bar"
Redis常用配置
- daemonize:是否是守护进程(no|yes),默认是no。
- port:Redis对外端口号,默认端口6379。
- logfile:Redis系统日志。
- dir:Redis工作目录。
还有RDB config、AOF config、slow Log config、maxMemory等其他的配置将在下面的部分中分别细讲。