Connection
Set<HostAndPort> hostAndPorts=new HashSet<>(); HostAndPort hostAndPort=new HostAndPort("192.168.11.153",7000); HostAndPort hostAndPort1=new HostAndPort("192.168.11.153",7001); HostAndPort hostAndPort2=new HostAndPort("192.168.11.154",7003); HostAndPort hostAndPort3=new HostAndPort("192.168.11.157",7006); hostAndPorts.add(hostAndPort); hostAndPorts.add(hostAndPort1); hostAndPorts.add(hostAndPort2); hostAndPorts.add(hostAndPort3);= JedisCluster jedisClusternew JedisCluster(hostAndPorts,6000); jedisCluster.set("mic","hello");
Principle Analysis
The program starts to initialize a clustered environment
1), read node configuration profile, whether it is a master-slave, no matter how many, take only a first acquiring connection instance redis
2) connected with execution examples acquired redis clusternodes () method, the actual implementation of the server cluster nodes redis command, obtain master-slave configuration Letter
interest
3) parsing the configuration information from the master, all nodes store the first set of nodes in the map, key node of ip: port, value for the current node
jedisPool
4), the master node analytical range segment allocated slots, the slot corresponding to the index value as the key, in a third step to get as jedisPool value, stored in
map set in slots
Is realized with a slot groove jedisPool mapping index value, the node information contains jedisPool the master, the groove and the corresponding points, and
redis server consistent
Access from a cluster environment values
1), as the key parameter, performing CRC16 algorithm, the key slot corresponding to the value of
2), through which slot value, a set of slots in the map to obtain jedisPool Examples
3) obtaining jedis instance via jedisPool example, the final data access work is completed redis