In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following brings you how redis achieves load balancing. I hope it can give you some help in practical application. Load balancing involves many things, and there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.
Redis load balancing
When high concurrency occurs in web projects, it can be handled by load balancing. The slot allocation mechanism of redis is a load balancing mode.
Redis slot allocation mechanism:
In the official cluster scheme given by redis, the data is allocated according to the slot. The key of each data is mapped to a slot by the hash function. Redis-3.0.0 stipulates that there are a total of 16384 slots. Of course, this can be configured according to the user's preference. When a user put or get a data, it will first look up the corresponding slot of the data, and then find the corresponding node, and then put the data into this node. In this way, the data is evenly distributed to each node in the cluster, so as to achieve the load balance of each node and give full play to the power of the cluster.
Public static void main (String [] args) {List shards = new ArrayList (); shards.add (new JedisShardInfo ("127.0.0.1", 6379)); shards.add (new JedisShardInfo ("127.0.0.1", 6380)); ShardedJedisPool sjp = new ShardedJedisPool (new JedisPoolConfig (), shards); ShardedJedis shardClient = sjp.getResource (); try {shardClient.set ("A", "123") ShardClient.set ("B", "234"); shardClient.set ("C", "345"); try {System.out.println (shardClient.get ("A"));} catch (Exception e) {e.printStackTrace () } try {System.out.println (shardClient.get ("B"));} catch (Exception e) {e.printStackTrace ();} try {System.out.println (shardClient.get ("C")) } catch (Exception e) {e.printStackTrace ();}} catch (Exception e) {e.printStackTrace ();} finally {sjp.returnResource (shardClient);}
These are the details of how to achieve load balancing in redis. Please pay more attention to other related articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.