Home > Back-end >  Redis sentry mode can really achieve the high availability?
Redis sentry mode can really achieve the high availability?

Time:09-23

The client code as follows:
Set Sentinels=new HashSet (a);
String hostAndPort1="192.168.0.3:26379";
Sentinels. Add (hostAndPort1);
String clusterName="mymaster";
String password="";
//JedisSentinelPool pool=new JedisSentinelPool (clusterName, sentinels, password);
JedisSentinelPool pool=new JedisSentinelPool (clusterName, sentinels);

For (int I=10000000; i<20000000; I++) {
//map. The put (String. The valueOf (I), String, the valueOf (I));
Jedis Jedis=pool. GetResource ();//in the event of master-slave switch, there will be abnormal, cause the program exit,
Jedis. Set (" username ", clusterName);
Jedis. Set (" password ", ");
Try {
Thread.sleep(500);
{} catch InterruptedException (e)
//TODO Auto - generated the catch block,
e.printStackTrace();
}
Jedis. Set (String. The valueOf (I), a String, the valueOf (I));
Jedis. Close ();
Jedis. Disconnect ();

//the following lines of code, in the event of master-slave switch, there will be abnormal, cause the program exit, who can help me solve?
Jedis Jedis=pool. GetResource ();

CodePudding user response:

The
refer to the original poster hopegood response:
client code as follows:
Set Sentinels=new HashSet (a);
String hostAndPort1="192.168.0.3:26379";
Sentinels. Add (hostAndPort1);
String clusterName="mymaster";
String password="";
//JedisSentinelPool pool=new JedisSentinelPool (clusterName, sentinels, password);
JedisSentinelPool pool=new JedisSentinelPool (clusterName, sentinels);

For (int I=10000000; i<20000000; I++) {
//map. The put (String. The valueOf (I), String, the valueOf (I));
Jedis Jedis=pool. GetResource ();//in the event of master-slave switch, there will be abnormal, cause the program exit,
Jedis. Set (" username ", clusterName);
Jedis. Set (" password ", ");
Try {
Thread.sleep(500);
{} catch InterruptedException (e)
//TODO Auto - generated the catch block,
e.printStackTrace();
}
Jedis. Set (String. The valueOf (I), a String, the valueOf (I));
Jedis. Close ();
Jedis. Disconnect ();

//the following lines of code, in the event of master-slave switch, there will be abnormal, cause the program exit, who can help me solve?
Jedis Jedis=pool. GetResource ();

Redis is a main 2 from, sentry has three nodes
  • Related