这是我参与8月更文挑战的第4天,活动详情查看:8月更文挑战
本章的主要内容是学会从 github 上下载自己需要的 redis,然后根据实际需要指定配置文件进行系统服务安装,以实现开机自动运行 redis 服务
version:5.0.10
reids 中的默认端口为 6397,为了不影响本机正在运行的 redis 实例,修改端口为 16379
redis 文件下载
根据自己需要,去 github 下载自己需要的版本 github.com/tporadowski…
如果觉得 redis 这个工具非常不错,希望深入研究源码的话,可以 fork 这一个官方库 github.com/redis/redis
如果不能访问 github,可以尝试如下操作:
1.找到 hosts 文件,路径是C:\Windows\System32\drivers\etc\hosts
2.在文件中追加如下内容
140.82.114.4 github.com
199.232.5.194 github.global.ssl.fastly.net
window 下自启服务安装/卸载
命令需要在 cmd 中执行,建议直接使用管理员权限进行操作
- 打开cmd
- 进入到 redis 文件夹目录
安装
redis-server --service-install redis.windows.conf --service-name redis-6379 --loglevel verbose
卸载
rem 通过系统通用的命令来卸载服务
sc delete redis-6379
rem 用 redis 提供的卸载命令来处理
redis-server --service-uninstall --service-name redis-6379
启动服务端
rem 使用当前目录下的配置文件进行启动
redis-server.exe redis.windows-service.conf
如果不指定配置文件启动,会提示如下:
D:\Program Files\Redis-x64-5.0.10>redis-server.exe
[19224] 26 Jun 15:08:20.441 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
[19224] 26 Jun 15:08:20.441 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=19224, just started
[19224] 26 Jun 15:08:20.441 # Warning: no config file specified, using the default config. In order to specify a config
file use redis-server.exe /path/to/redis.conf
[19224] 26 Jun 15:08:20.447 # Could not create server TCP listening socket *:6379: bind: 在一个非套接字上尝试了一个操作
通过对 redis.conf 文件进行检索,得到的实际路径为:
D:\$RECYCLE.BIN\S-1-5-21-526095006-1361995329-208084219-19111\$RF7M1CL.10\redis.conf
额外安利一个好东西,everything,专业搞文件检索的,可以根据多个关键字或者是通配符去系统里检查符合要求的文件,基本1,2秒就能拉出东西来,比 windows 自带的搜索快的多
启动客户端
redis-cli.exe -h 127.0.0.1 -p 16379
# -h 指定目标ip -p 指定连接的端口
在命令行查看配置项
# 查看指定配置项
127.0.0.1:16379> config get dbfilename
# 查看全部配置项
127.0.0.1:16379> config get *
在命令行修改配置项
127.0.0.1:16379> config set loglevel 'notice'
OK
127.0.0.1:16379> config get loglevel
1) "loglevel"
2) "notice"
注意:通过命令行修改的配置,仅限本次运行可用,当实例重新运行时,会使用配置文件中的数据
基础操作操作
# 删除指定key,返回成功删除的数量,不存在的 key 将会忽略
127.0.0.1:16379> del db db1
(integer) 2
# 使用密码登陆 redis(当前 redis 还未设置密码)
27.0.0.1:16379> auth wanb
error) ERR Client sent AUTH, but no password is set
# 切换 db 库
127.0.0.1:16379> select 1
OK
# 退出 redis
quit
# keys [pattern] 匹配指定表达式的全部 key
# 测试正则表达式发现只支持 ? 占位符,以及 * 通配符
# ?:匹配当前位置任意字符
# * :匹配 0 - n 个任意字符