在Windows上搭建Redis服务器

redis简介:

redis是一个缓存数据库,里面的数据都是字符串,使用key-value形式存储,使用redis缓存数据库可以提高系统的访问性能,一般开发时使用Windows下的redis服务器,生产时使用linux下的服务器。

一、下载Windows版本的redis

下载地址:https://github.com/MicrosoftArchive/redis/releases

 

 二、安装与配置

1、将下载下来的安装包解压到指定文件夹下

2、进入到文件夹下,使用管理员权限运行cmd

3、将redis服务安装到Windows中

执行命令:redis-server --service-install redis.windows-service.conf --loglevel verbose

 

 这是我们可以在Windows的服务列表中看到redis服务。如下:

 

 此时redis的状态还是未启用的状态,我们可以执行命令启动它。

4、启动redis

执行命令:redis-server --service-start

 

 使用F5刷新Windows列表,这时Windows的服务列表中redis变为运行状态,如下:

 

 到这里redis就搭建成功了。

卸载redis的命令:redis-server --service-uninstall

停止redis的命令:redis-server --service-stop

 

三、测试redis

1、连接redis:redis-cli -h 127.0.0.1 -p 6379

 

 127.0.0.1代表主机,使用localhost也可以,或者直接命令:redis-cli也可以直接连,默认为本地连接,默认端口6379

2、简单测试

 

 

四、添加密码

在Redis中找到redis.windows-service.conf这个文件并以记事本的方式打开,找到修改密码这一段:

################################## SECURITY ###################################

# 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 foobared后面添加一行:requirepass logan123

logan123就是密码

################################## SECURITY ###################################

# 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 logan123

重新启动redis,密码生效

连接redis:redis-cli -h 127.0.0.1 -p 6379 -a logan123

 

 

 

info命令用来查询redis的信息

expire用来设置超期时间

 

posted @ 2020-05-18 12:01  alittlecomputer  阅读(505)  评论(0编辑  收藏  举报