Redis从入门到精通
Redis安装成功,在/usr/bin下可执行的程序:
redis-benchmark Redis性能测试工具
redis-check-aof AOF文件修复工具
redis-check-dump RDB文件检测工具
redis-cli 命令行客户端
redis-server Redis服务器
Redis默认端口号:6379
Redis配置文件
redis.conf
修改配置文件redis.conf中的daemonize yes 以守护进程的方式使用
启动Redis
直接启动
1 | redis-server |
指定配置文件
1 | redis-server /etc/redis/redis.conf |
指定配置选项的值
1 | redis-server /etc/redis/redis.conf --loglevel warning |
设置端口号
1 | redis-server --port=6379 |
停止Redis
1 | shutdown |
使用命令行客户端连接Redis
直接连接Redis
1 | redis-cli |
指定服务器和端口连接Redis
1 | redis-cli -h localhost -p 6379 |
命令返回值
状态回复
PING
SET test ‘this is a test’
错误回复
错误回复以error开头
整数回复
以integer开头
字符串回复
GET test
(nil)代表空结果
多行字符串回复
KEYS*,得到当前数据库中存在的键名
Redis配置选项
动态获得配置选项的值
CONFIG GET name
动态设置配置选项的值
CONFIG SET name value
PHP使用Redis
PHP使用Redis需要安装phpredis扩展或者使用predis,我之前写过一篇PHP安装Redis扩展的文章,大家可以参考一下,这里不再赘述。
CentOS7中PHP安装Redis扩展