- redis版本6.2.6
- 服务器版本CentOS Linux release 7.9.2009
1 下载redis
进入官网找到下载地址 https://redis.io/download
选择稳定版本,复制链接
进入服务器root路径,下载
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
2 解压并安装redis
// 解压
tar -zvxf redis-6.2.6.tar.gz
// 移动目录
mv /root/redis-6.2.6 /usr/local/redis
cd /usr/local/redis
// 编译
make
//安装
make PREFIX=/usr/local/redis install
// 这里 PREFIX= 关键字的作用是编译的时候用于指定程序存放的路径。比如我们现在就是指定了redis必须存放在/usr/local/redis目录。
// 假设不添加该关键字Linux会将可执行文件存放在/usr/local/bin目录,库文件会存放在/usr/local/lib目录,配置文件会存放在/usr/local/etc目录,其他的资源文件会存放在usr/local/share目录。
// 这里指定目录是为了方便后续的卸载,后续直接rm -rf /usr/local/redis 即可完全删除redis。
3 启动redis
cd /usr/local/redis
// 后台方式启动
./bin/redis-server& ./redis.conf
// 前台方式启动
./bin/redis-server ./redis.conf
4 配置conf文件
vim /usr/local/redis/redis.conf
// 1 设置可以远程访问
// 找到bind并注释掉
// 把protected-mode赋值no
// 2 必须加密
// requirepass passwordddddddddd
5 redis常用命令
#进入redis:
./redis-cli -h 192.168.1.1 -p 6379
#输入密码
localhost:6379> auth yourpassword
#进入redis客户端输入命令 ping 查看是否启动
192.168.1.1:6379> ping
PONG
#有时候会有中文乱码。要在 redis-cli 后面加上 --raw
./redis-cli --raw -h 192.168.1.1 -p 6379
#获取所有的key:
keys *
#模糊查询某字符如:
keys ULIN*
#查询是否存在key:
exists key
#删除所有的redis数据:
FLUSHALL
#查看某key的value:
get key
#清除指定库
flush db
#删除key
del key1
#查看key是什么类型的数据
type key
#查看list类型数据命令
lrange key 0 -1
#查看hash类型数据命令
hgetall key
exists key 判断是否存在key
expire key 10 10过期
pexpire key 1000 毫秒
persist key 删除过期时间
#感知节点
cluster meet 192.168.1.2 6381
#查看节点
cluster nodes
#为主节点分配子节点
cluster replicate 主节点ID
在Window10环境运行Redis5
Install Redis with MSI package
If you installed Redis using the MSI package, then Redis was already installed as a Windows service. Nothing further to do. If you would like to change its settings, you can update the redis.windows-service.conf file and then restart the Redis service (Run -> services.msc -> Redis -> Restart).
During installation of the MSI you can either use the installer’s user interface to update the port that Redis listens at and the firewall exception or run it silently without a UI. The following examples show how to install from the command line:
default install (port 6379 and firewall exception ON):
msiexec /i Redis-Windows-x64.msi
set port and turn OFF firewall exception:
msiexec /i Redis-Windows-x64.msi PORT=1234 ADD_FIREWALL_RULE=""
set port and turn ON firewall exception:
msiexec /i Redis-Windows-x64.msi PORT=1234 ADD_FIREWALL_RULE =1
install with no user interface:
msiexec /quiet /i Redis-Windows-x64.msi
Install Redis with zip file
Download zip file from githubReleases · tporadowski/redis · GitHubNative port of Redis for Windows. Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs. This repository contains unofficial port of Redis to Windows. - Releases · tporadowski/redishttps://github.com/tporadowski/redis/releases/ Redis-x64-5.0.14.1.zip , unzip to Redis5/ folder.
Install the service
C:/Redis5/redis-server --service-install redis.windows-service.conf --loglevel verbose
Note: this command does not start the service!
Starting the service
C:/Redis5/redis-server --service-start
Stop the service
C:/Redis5/redis-server --service-stop
Uninstall the service
C:/Redis5/redis-server --service-uninstall
Naming the service
The following would install and start three separate instances of Redis as a service:
redis-server --service-install --service-name redisService1 --port 10001
redis-server --service-start --service-name redisService1
redis-server --service-install --service-name redisService2 --port 10002
redis-server --service-start --service-name redisService2
redis-server --service-install --service-name redisService3 --port 10003
redis-server --service-start --service-name redisService3
Windows上安装Redis流程
1、准备内容
①Redis下载地址:https://github.com/tporadowski/redis/releases
②Redis可视化管理工具下载地址:https://gitee.com/qishibo/AnotherRedisDesktopManager
③Redis参考手册:https://www.php.cn/manual/view/16063.html
2.2、Windows上安装Redis步骤
①下载Windows版本的Redis压缩包且解压
②修改Redis的配置文件实现远程访问
注意:如果不用实现远程访问,则忽略以下操作
③使用超级管理员打开命令行窗口,进入到解压好的Redis目录下,运行Redis服务
#运行Windows下Redis服务的命令
redis-server.exe redis.windows.conf
注意:运行启动Redis服务命令时会弹出网络访问窗口,必须选择允许,否则需要到防火墙里面配置Redis的端口通行。