1,java Configure Redis Client
public class Redisclient implements serializable{private Jedis Jedis;
Private Jedispool Jedispool;
Shardedjedis Shardedjedis;
Private Shardedjedispool Shardedjedispool;
Public redisclient () {initialpool ();
Initialsharepool ();
Shardedjedis = Shardedjedispool.getresource ();
Jedis = Jedispool.getresource (); /** * Initialize non-slice pool/private void Initialpool () {//Pool basic configuration jedispoolconfig config = new Jed
Ispoolconfig ();
Config.setmaxactive (20);
Config.setmaxidle (5);
Config.setmaxwait (10001);
Config.settestonborrow (FALSE);
Jedispool = new Jedispool (config, Enums.LINUX_HOST.getValue (), 6379); /** * Initialize slicing pool/private void Initialsharepool () {//pool base configuration jedispoolconfig config = new
Jedispoolconfig ();
Config.setmaxactive (20);
Config.setmaxidle (5);
Config.setmaxwait (10001);
Config.settestonborrow (FALSE); Slave connection list<jedisshardinfo> Shardinfos = new arraylist<jedisshardinfo> ();
Shardinfos.add (New Jedisshardinfo (Enums.LINUX_HOST.getValue (), 6379, 1000));
Construction Pool Shardedjedispool = new Shardedjedispool (config, shardinfos); }
}
2, the mutual transformation of array and object
1, the object implements the serializable interface in order to serialize and deserialize
2, the code that converts objects and arrays into each other
public class Objectandbyte {public static byte[] Tobytearray (Object obj) {byte[] bytes = NULL;
try {//object to ByteArray bytearrayoutputstream bo = new Bytearrayoutputstream ();
ObjectOutputStream oo = new ObjectOutputStream (bo);
Oo.writeobject (obj);
bytes = Bo.tobytearray ();
Bo.close ();
Oo.close ();
catch (Exception e) {System.out.println ("translation" + E.getmessage ());
E.printstacktrace ();
return bytes; /** * Array to Object *@paramBytes *@return */public static Object toobject (byte[] bytes) {Object obj = null;
try {Bytearrayinputstream bis = new Bytearrayinputstream (bytes);
ObjectInputStream ois = new ObjectInputStream (bis);
obj = Ois.readobject ();
Ois.close ();
Bis.close ();
catch (IOException ex) {ex.printstacktrace ();
catch (ClassNotFoundException ex) {ex.printstacktrace ();
return obj; }
}
3, test