redis configuration
Redis
The cluster needs to be at least3
For data integrity each master node needs at least one slave node, so you need to prepare at least6
classifier for individual things or people, general, catch-all classifierRedis
service
It is recommended that theredis
Register as a system service and set up self-start, the service registration command is:
redis-server --service-install --service-name redis6379 --loglevel verbose
Modify in the following configurations:
bind 127.0.0.1 // ip address
port 6379 // port
logfile "" // Name of the logfile.
cluster-enabled yes // Enable cluster support.
cluster-config-file // Name of the cluster configuration file.
cluster-node-timeout 15000 // Cluster node timeout ms
Initiate allRedis
After the service has been performed on any of theRedis
directory, execute the Create Cluster command with the number of copies of the1
, three master and three slave nodes are automatically generated:
redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1
code example
public static void main(String[] args) {
// Cluster node information from which to retrieve
Set<HostAndPort> nodes = new HashSet<>();
(new HostAndPort("127.0.0.1", 6379));
(new HostAndPort("127.0.0.1", 6380)); (new HostAndPort("127.0.0.1", 6379)); (new HostAndPort("127.0.0.1", 6379))
(new HostAndPort("127.0.0.1", 6383)); (new HostAndPort("127.0.0.1", 6384)).
// The connection pool configuration from which to retrieve the
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
(10);
(5);
(1).
// Initialize the cluster object, globally unique
JedisCluster cluster = new JedisCluster(nodes, jedisPoolConfig);
// Execute the command
("key1", "1"); // Execute the command.
("key12", "12"); // Execute the command.
("key123", "123"); // Execute the command.
("key1234", "1234").
("key12345", "12345").
("key123456", "123456").
("key1234567", "1234567").
("key12345678", "12345678").
("key123456789", "123456789").
();
}
added9
classifier for individual things or people, general, catch-all classifierkey
The distribution is on different nodes.