1. 安装 & 使用[Redis推荐Linux开发]
1.1 基于HomeBrew安装Redis
brew -- version //检查电脑上有没有安装Homebrew
brew search redis //查看redis版本
brew install redis //安装最新版本的redis
1.2 启动Redis
brew services start redis //启动redis服务
brew services list //查看mac上所有服务目前的状况
brew services stop redis //关闭redis
brew services restart redis //重启redis
**redis-cli //打开图形化界面**
brew list redis //查看redis安装的位置 //redis.conf的目录:/opt/homebrew/Cellar/redis/7.0.10/.bottle/etc/
vim redis.config //查看redis配置文件
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents //开机启动redis服务
redis-server /usr/local/etc/redis.conf //使用配置文件启动redis-server
redis-cli shutdown //停止redis服务
/usr/local/etc/redis.conf //redis配置文件位置
brew uninstall redis //卸载redis
rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
cd /usr/local/Cellar/bin/6.0.5/bin //通过bin目录下的redis-server命令来启动redis服务
./redis-server
DBSIZE //查看容量
flushall //清空所有数据
flushdb //清空当前db
select 3 //选3号数据库
keys * //查看数据库所有的key
//🌰
**(base) xielong@xielongdeMacBook-Pro etc % redis-cli -p 6379**
**127.0.0.1:6379> ping //测试链接**
PONG //连接成功
**127.0.0.1:6379> flushall**
OK
**127.0.0.1:6379> keys ***
(empty array)
**127.0.0.1:6379> set name lily //设置name**
OK
**127.0.0.1:6379> keys * //查看所有的key**
1) "name"
**127.0.0.1:6379> set age 1 //设置age**
OK
**127.0.0.1:6379> keys * //查看所有的key**
1) "age"
2) "name"
**127.0.0.1:6379> exists name //判断当前的key是否存在:是否存在name**
(integer) 1 //1 - 是 0-不是
**127.0.0.1:6379> exists name1 //是否存在name1**
(integer) 0
**127.0.0.1:6379> move name 1 //删除name**
(integer) 1
**127.0.0.1:6379> keys * //查看所有的key**
1) "age"
**127.0.0.1:6379> set name susie //设置name**
OK
**127.0.0.1:6379> keys ***
1) "age"
2) "name"
**127.0.0.1:6379> get name //取出name**
"susie"
**127.0.0.1:6379> expire name 10 //设置key的过期时间:设置name过期时间【单位是秒】**
(integer) 1
**127.0.0.1:6379> ttl name //name还剩多久过期**
(integer) 0
**127.0.0.1:6379> get name //取出name**
(nil) //🈳️
**127.0.0.1:6379> type age //查看当前key的类型:查看age的类型**
string