连redis 连不上怎么办!

网上很多,你应该已经查了一溜够了!我这里只强调config 配置文件!

而配置里,两个配置起决定性作用,bind属性和protected-mode属性(protected-mode有没有是要看版本,老版本没有的)。我为什么把注释都放进来呢,因为人家已经写得很清楚了,好好看!

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected 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 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

如果链接不上,我看很多都让把 protected-mode 修改为 no  并且 将 bind属性注释掉 (老版本只注释掉bind),但是,这样,不就谁都可以链接redis数据库了?那就不安全了啊

所以,protected-mode属性根本不用改,bind属性不要注释,只需要在bind 后添加你想要链接此数据库的地址就好了 如:

bind 192.168.1.100 10.0.0.1 就代表192.168.1.100和10.0.0.1是可以链接到数据库的,人家写的很清楚了!而且这也是安全并被推荐使用的!

下面说一下windows 下启动redis服务的问题!

如下图,是windows安装完的文件

通常,我们会双击redis-server.exe启动服务,但是默认服务使用的并不是这里的conf配置文件,如图:

这个/path/to/redis.conf才是redis-server.exe启动时指定的redis.conf配置,理论上我们修改这个redis.conf里的属性,重新启动服务也行,然而,我并没找到这个redis.conf

所以我修改了redis.windows-service.conf 配置(当然你可以修改redis.windows.conf我认为也没问题),并指定修改好的配置文件 如:

这时候再启动redis-cli.exe 运行命令:config get * 查看一下你的conf配置就ok了

至于linux下,如果链接不上redis也是这个思路:修改下配置文件,然后指定配置文件重新启动服务就好了!

关闭服务
  redis-cli -h 127.0.0.1 -p 6379 shutdown
  1.访问redis根目录    cd  /usr/local/redis-2.8.19
  2.登录redis:redis-cli -h 127.0.0.1 -p 6379
  3.查看所有key值:keys *
  4.删除指定索引的值:del key
  5.清空整个 Redis 服务器的数据:flushall
  6.清空当前库中的所有 key:flushdb
linux下redis操作指令
查询redis
   ps aux|grep redis
关闭redis服务
   redis-cli shutdown
指定conf启动redis-server
   redis-server etc/redis/redis.conf
原文地址:https://www.cnblogs.com/ruber/p/13434616.html