redis--------redis客户端windows下安装

来源:博客园 分类: 文章浏览史 发布时间:2022-10-08 15:33:17 最后更新:2022-10-08 浏览:364
转载声明:
本文为摘录自“博客园”,版权归原作者所有。
温馨提示:
为了更好的体验,请点击原文链接进行浏览
摘录时间:
2022-10-08 15:33:17

一、Redis下载

Redis官网建议使用Linux进行部署,未提供windows版本的Redis,但微软开发和维护着Windows64版本的Redis。
Windows64版本的Redis下载地址:Releases · microsoftarchive/redis (github.com)

二、redis安装

将下载的压缩包解压至需要安装的目录,如D:\redis。

三、启动Redis临时服务并测试连接

1.启动Redis临时服务

双击安装目录下的"redis-server.exe"文件,并保持窗口开启(若关闭窗口则服务关闭)。

2、启动redis服务器

切换到redis目录下,使用如下命令行启动redis服务器

redis-server redis.windows.conf

3、启动Redis客户端测试连接

双击安装目录下的"redis-cli.exe"文件,执行ping命令,下行出现"PONG"则连接成功。

四、Redis配置

1.配置系统环境变量

右键此电脑->属性||打开设置->系统->关于,高级系统设置->环境变量


选中系统变量Path点击"编辑",弹出的窗口点击"新建",输入Redis安装目录的绝对路径(可点击"浏览",选择Redis安装目录)。

配置好之后,弹出的窗口全部点击"确定"关闭即可。

2.安装Redis服务

在安装目录下打开命令提示符(可在安装目录的地址栏输入cmd直接回车),执行以下命令。

注:即使配置了系统环境变量,此命令仍需在Redis安装目录下执行,否则找不到redis.windows.conf文件会报错;

此命令的配置文件参数可以是"redis.windows.conf"或"redis.windows-service.conf",执行哪个参数则后期需要修改配置的文件就是哪个。

redis-server.exe --service-install redis.windows.conf --loglevel verbose

 遇到了个1073的错误,我之前装过服务重新装了遍就会报这个错误,卸了重装就好。卸载redis服务
redis-server --service-uninstall

3、修改密码

redis安装完后,默认是没有密码的。

使用命令设置的密码为临时密码,重启服务即失效,不推荐;推荐修改配置文件设置永久密码,重启服务依旧有效。

打开安装目录下的redis.windows.conf文件,搜索"requirepass foobared",在下一行输入"requirepass "+密码,保存后重启服务即可。(如上一步骤安装服务命令的配置文件参数为redis.windows-service.conf,则修改redis.windows-service.conf文件。)

4.启动Redis客户端测试连接

由于上一步修改了配置文件,所以要重启服务。

运行命令提示符,先执行redis-server --service-stop停止服务,再执行redis-server --service-start启动服务 或者 打开任务管理器选择服务找到Redis右键重新启动

 重启redis服务

运行命令提示符,执行redis-cli启动Redis客户端(或双击运行安装目录下的redis-cli.exe文件,此处无需运行redis-server.exe文件)。

执行ping命令,提示需要身份验证,继续执行auth 密码命令,如密码正确会提示OK,再次执行ping命令,下行出现"PONG"则连接成功。

Redis命令行测试

首先

redis-cli -h 127.0.0.1 -p 6379  

 登入客户端

设置姓名为jack

120.0.0.1:6379> set name jack

设置年龄为21

120.0.0.1:6379>set age 21  

获取姓名

120.0.0.1:6379>get name 

输出结果为"jack"

获取年龄

120.0.0.1:6379>get age

输出结果为21

Redis命令行客户端有如下命令行:

redis-cli [option] [commands]

  其中常见的options有:

1、-h 127.0.0.1 指定要连接的redis节点的IP地址,默认是127.0.0.1

2、-p 6379 指定要连接的redis节点的端口,默认是6379

3、-a 123321指定redis的访问密码

其中的commonds就是redis的操作命令,例如:

1、ping:与redis服务端做心跳测试,服务器端正常会返回pong

不指定commond时,会进入redis-cli的交互控制台:

 Redis配置文件中属性的修改

#监听的地址,默认是127.0.0.1,会导致只能在本地访问,修改为0.0.0.0则可以存在任意IP访问,生产环境不要设置监听为0.0.0.0

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 127.0.0.1

#守护进程,修改为yes后即可后台运行(windows下不支持,Linux才支持)

daemonize yes

#密码,设置后访问redis必须输入密码

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 123456

#监听的端口

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# 工作目录,默认是当前的目录,也就是运行redis-server时的命令、日志、持久化等文件会保存在这个目录

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# 
# The Append Only File will also be created inside this directory.
# 
# Note that you must specify a directory here, not a file name.
dir ./

#数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0-15

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

#设置redis能够使用的最大内存

maxmemory 512mb

#日志文件,默认为空,不记录日志,可以指定日志文件名

logfile "redis.log"

五、redis客户端工具链接

给个redis可视化客户端工具的链接

链接:https://pan.baidu.com/s/1GkGHfz1l7xBUzpGL4ECBpA
提取码:lwth

————————————————
版权声明:本文为CSDN博主「pingcode」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_41521682/article/details/122788722

php技术微信