本博客是在学习《Redis从入门到高可用,分布式实践》教程时的笔记。
同时参考:
https://www.cnblogs.com/yiwangzhibujian/p/7067575.html
https://www.cnblogs.com/jiang910/p/10020048.html
一、Redis 初识
1. 下载
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
5.0.7 是当前 Redis 官网最新的稳定版本,大小不到2M。
2. 解压
tar xzf redis-5.0.7.tar.gz
3. 安装依赖 gcc
yum -y install gcc automake autoconf libtool make
4. 编译
# 进入到目录cd redis-5.0.7# 执行命令 make# 安装make install
5. 可执行文件说明
只执行 make,未执行 make install 命令时,上述可执行文件只能在 redis/src/ 目录下执行。
①. redis-server :Redis 服务器
②. redis-cli :Redis 命令行客户端
③. redis-benchmark :Redis 性能测试
④. redis-check-aof :AOF 文件修复工具
⑤. redis-check-rdb :RDB 文件修复工具
⑥. redis-sentinel :Sentinel 服务器
6. 启动方式
①. 最简单的
redis-server
②. 动态参数
redis-server --port 6379
③. 配置文件
redis-server redis.conf
④. 测试
# 查看进程 ps -ef | grep redis # 查看端口 netstat -antpl | grep redis # 命令行访问 redis-cli -h 127.0.0.1 -p 6379 # 执行命令,正常会返回 PONG ping
7. 配置文件中更改
daemonize no # 是否守护进程启动。改为 yes
bind 127.0.0.1 # 只允许该 ip 访问。注释掉
protected-mode yes # 保护模式。如果使用bind和密码可以开启,否则关闭改为 no
8. 纯净版配置文件
# 查看 cat redis.conf | grep -v "#" | grep -v "^$" # 输出 > redis-pure.conf
二、API 的使用和理解
1. 通用命令
mset / mget # 批量设置 / 批量查询
keys * # 遍历所有匹配的 key
dbsize # 计算 key 的总数
exists key # 检查 key 存在
expire key 10 # 设置 key 的过期时间 10 秒
ttl key # 查看剩余过期时间
persist key # 去掉过期时间
type key # 查看类型
2. 字符串类型
incr key # 自增
decr key # 自减
3. 哈希类型
4. 列表类型
5. 集合类型
6. 有序集合类型
三、Redis 客户端
1. 待
待
来源:https://www.cnblogs.com/libra0920/p/12017418.html