遇到的问题

[root@localhost ~]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>

        当我们直接连接 redis 时,会遇到 Could not connect to Redis at 127.0.0.1:6379: Connection refused 这个问题,显示连接被拒绝

原因

        是因为没有启动 redis 的服务端,所以我们的 redis 连接不到他的服务,需要启动 redis 服务端

解决方法

        如下图,这是 redis 的 bin 目录,找到 redis-server 和 redis.conf 这两个文件

[root@localhost ~]# ll /usr/local/redis/bin/
总用量 16264
-rwxr-xr-x. 1 root root  708272 11月  1 00:04 redis-benchmark
-rwxr-xr-x. 1 root root 4962208 11月  1 00:04 redis-check-aof
-rwxr-xr-x. 1 root root 4962208 11月  1 00:04 redis-check-rdb
-rwxr-xr-x. 1 root root  964912 11月  1 00:04 redis-cli
-rwxr-xr-x. 1 root root   84842 11月  1 00:08 redis.conf
lrwxrwxrwx. 1 root root      12 11月  1 00:04 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 4962208 11月  1 00:04 redis-server

        我们在命令行启动这两个文件,输入 /usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf

[root@localhost ~]# /usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf

        然后启动 redis 客户端,输入 redis-cli 就可以成功了

[root@localhost ~]# redis-cli
127.0.0.1:6379>

若有不足或者不正之处,欢迎指正批评,感激不尽!如果有疑问欢迎留言,绝对第一时间回复! 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐