Redis 3.2.0·以后·- Vagrant内的redis连接问题

Redis-server 构建在Vagrant的Centos7上,
IP–192.168.44.10
参照: Redis.构建了Redis的Server
Centos7内测试,成功

确认

ps -ef | grep [r]edis              #redis程序存在确认
netstat -tln | grep 63*            #6309监听端口确认
systemctl status redis             #服务器运行状态确认
which redis-server                 #服务器安装场所确认

外部连接

.....................
nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.44.10:6379

原因

Redis默认只监听本机的连接
设定文件
/etc/redis.conf

By default, if no “bind” configuration directive is specified, Redis listens
for connections from all the network interfaces available on the server.
~~~ 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 loopback interface address (this means Redis will be able to
accept connections only from clients running into the same computer it
is running).

对应

屏蔽掉下面的一行

bind 127.0.0.1
更改为
bind 0.0.0.0
server重启

sudo systemctl restart redis

确认

再次连接确认,出现下面的信息

DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no
authentication password is requested to clients. In this mode connections are only accepted from the loopback
interface. If you want to connect from external computers to Redis you may adopt one of the following solutio
ns: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interf
ace by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly a
ccessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you c
an just disable the protected mode by editing the Redis configuration file, and setting the protected mode opt
ion to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart i
t with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only
need to do one of the above things in order for the server to start accepting connections from the outside.

原因

redis3.2.0 以后,bind IP地址未指定并且password未设定的情况下,默认开启了 protect-mode 模式。

解决

启动时指定 --protected-mode no
设定redis.conf文件内 --protected-mode no
设置密码(?)

双击 redis-server.exe运行服务端。 双击 redis-cli.exe 运行一个客户端 此时可以通过一个命令来展示redis的功能。redis的命令如下: 连接控制 QUIT 关闭连接 AUTH (仅限启用时)简单的密码验证 适合全体类型的命令 EXISTS key 判断一个键是否存在;存在返回 1;否则返回0; DEL key 删除某个key,或是一系列key;DEL key1 key2 key3 key4 TYPE key 返回某个key元素的数据类型 ( none:不存在,string:字符,list,set,zset,hash) KEYS pattern 返回匹配的key列表 (KEYS foo*:查找foo开头的keys) RANDOMKEY 随机获得一个已经存在的key,如果当前数据库为空,则返回空字符串 RENAME oldname newname更改key的名字,新键如果存在将被覆盖 RENAMENX oldname newname 更改key的名字,如果名字存在则更改失败 DBSIZE返回当前数据库的key的总数 EXPIRE设置某个key的过期时间(秒),(EXPIRE bruce 1000:设置bruce这个key1000秒后系统自动删除)注意:如果在还没有过期的时候,对值进行了改变,那么那个值会被清除。 TTL查找某个key还有多长时间过期,返回时间秒 SELECT index 选择数据库 MOVE key dbindex 将指定键从当前数据库移到目标数据库 dbindex。成功返回 1;否则返回0(源数据库不存在key或目标数据库已存在同名key); FLUSHDB 清空当前数据库的所有键 FLUSHALL 清空所有数据库的所有键 处理字符串的命令 SET key value 给一个键设置字符串值。SET keyname datalength data (SET bruce 10 paitoubing:保存key为burce,字符串长度为10的一个字符串paitoubing到数据库),data最大不可超过1G。 GET key获取某个key 的value值。如key不存在,则返回字符串“nil”;如key的值不为字符串类型,则返回一个错误。 GETSET key value可以理解成获得的key的值然后SET这个值,更加方便的操作 (SET bruce 10 paitoubing,这个时候需要修改bruce变成1234567890并获取这个以前的数据paitoubing,GETSET bruce 10 1234567890) MGET key1 key2 … keyN 一次性返回多个键的值 SETNX key value SETNX与SET的区别是SET可以创建与更新key的value,而SETNX是如果key不存在,则创建key与value数据 MSET key1 value1 key2 value2 … keyN valueN 在一次原子操作下一次性设置多个键和值 MSETNX key1 value1 key2 value2 … keyN valueN 在一次原子操作下一次性设置多个键和值(目标键不存在情况下,如果有一个以上的key已存在,则失败) INCR key 自增键值 INCRBY key integer 令键值自增指定数值 DECR key 自减键值 DECRBY key integer 令键值自减指定数值 处理 lists 的命令 RPUSH key value 从 List 尾部添加一个元素(如序列不存在,则先创建,如已存在同名Key而非序列,则返回错误) LPUSH key value 从 List 头部添加一个元素 LLEN key 返回一个 List 的长度 LRANGE key start end从自定的范围内返回序列的元素 (LRANGE testlist 0 2;返回序列testlist前0 1 2元素) LTRIM key start end修剪某个范围之外的数据 (LTRIM testlist 0 2;保留0 1 2元素,其余的删除) LINDEX key index返回某个位置的序列值(LINDEX testlist 0;返回序列testlist位置为0的元素) LSET key index value更新某个位置元素的值 LREM key count value 从 List 的头部(count正数)或尾部(count负数)删除一定数量(count)匹配value的元素,返回删除的元素数量。 LPOP key 弹出 List 的第一个元素 RPOP key 弹出 L
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值