Spring Boot Redis Cluster Combat Dry

Source: Internet
Author: User
Tags redis cluster redis server

Adding configuration information
spring.redis:  database: 0 # Redis数据库索引(默认为0)  #host: 192.168.1.8  #port: 6379  password: 123456  timeout: 10000 # 连接超时时间(毫秒)    pool:     max-active: 8 # 连接池最大连接数(使用负值表示没有限制)    max-idle: 8 # 连接池中的最大空闲连接    max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)    min-idle: 0 # 连接池中的最小空闲连接  cluster:    nodes:      - 192.168.1.8:9001      - 192.168.1.8:9002      - 192.168.1.8:9003

You only need to add 3 master nodes, and 3 slave nodes do not need to be added.

All you have to do is configure it, and the other spring boot is configured automatically.

Now you can use the cluster as if you were using a single machine, and Redis will automatically fragment to a different cluster instance by key.

Problems encountered
caused by:redis.clients.jedis.exceptions.JedisConnectionException:Could not get a resource from the pool at REDIS.CLI Ents.util.Pool.getResource (pool.java:53) at Redis.clients.jedis.JedisPool.getResource (jedispool.java:226) at Redis    . Clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot (jedisslotbasedconnectionhandler.java:66) At Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:116) at Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:141) at Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:141) at Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:141) at Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:141) at Redis.clients.jedis.JedisClusterCommand.runBinary (jedisclustercommand.java:60) at Redis.clients.jedis.BinaryJedisCluster.set (binaryjediscluster.java:77) at Org.springframework.data.Redis.connection.jedis.JedisClusterConnection.set (jedisclusterconnection.java:618) ... Morecaused by:redis.clients.jedis.exceptions.JedisConnectionException:java.net.ConnectException:Connection Refused:connect at Redis.clients.jedis.Connection.connect (connection.java:207) at redis.clients.jedis.BinaryClient . Connect (binaryclient.java:93) at Redis.clients.jedis.BinaryJedis.connect (binaryjedis.java:1767) at Redis.clients.jedis.JedisFactory.makeObject (jedisfactory.java:106) at Org.apache.commons.pool2.impl.GenericObjectPool.create (genericobjectpool.java:868) at Org.apache.commons.pool2.impl.GenericObjectPool.borrowObject (genericobjectpool.java:435) at Org.apache.commons.pool2.impl.GenericObjectPool.borrowObject (genericobjectpool.java:363) at Redis.clients.util.Pool.getResource (pool.java:49) ... morecaused by:java.net.ConnectException:Connection Refused:connect at Java.net.DualStackPlainSocketImpl.waitForC Onnect (Native Method) at Java.net.DuaLstackplainsocketimpl.socketconnect (dualstackplainsocketimpl.java:85) at Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188) at Java.net.PlainSocketImpl.connect ( plainsocketimpl.java:172) at Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392) at Java.net.Socket.connect (socket.java:589) at Redis.clients.jedis.Connection.connect (connection.java:184) ... More

When trying to write data to Redis, the report can not get the connection exception, tracking a half-day code, found that the connection is 127.0.0.1, rather than the configuration of 192.168.1.8, it's strange, continue tracking code discovery is the list of returned cluster instances to the Redis server, it's a pit!

Source:

Redis.clients.jedis.jedis#clusterslots

@Overridepublic List<Object> clusterSlots() {    checkIsInMultiOrPipeline();    client.clusterSlots();    return client.getObjectMultiBulkReply();}

That's it. Gets the list of returned clusters, which is returned in 127.0.0.1 instead of 192.168.1.8 configured.

Finally, modify the configuration file redis.conf for each cluster node and add:

bind 192.168.1.8

After restarting the cluster node, read and write normally.

Follow the public number below and reply to "answer" to get a full set of Redis face questions and answers.

Spring Boot Redis Cluster Combat Dry

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.