Here are the three types of working patterns that are referred to as:
1. Stand-alone mode
2. Shard Mode
3. Cluster mode (since 3.0)
The illustration is detailed below:
Using Jedis connection mode one:
Initialize connection private Jedis jedis=new Jedis ("192.168.0.100", 6379); Jedis.set ("A", "B"); Jedis.hmset (key, hash);
Using Jedis connection mode two:
GenericObjectPoolConfig config=new Genericobjectpoolconfig (); config.setmaxidle (+); config.setminidle (; ) config.settestonborrow (True); Config.settestonreturn (rtrue); config.settestwhileidle (true); List<JedisShardInfo> shards = new Arraylist<jedisshardinfo> (); for (int i = 0; i < shareds.size (); i++) { shards.add (New jedisshardinfo ("192.168.0.100", 6379, 200)); } // Construction Pool &nbsP; shardedjedispool shardedjedispool= new shardedjedispool (config, shards); shardedjedis jedis= Shardedjedispool.getresource (); jedis.set ("A", "B"); jedis.hmset (Key, hash);
Use Jedis connection mode three:
set
Binaryjediscluster.java is a class that allows Jedis to support byte array form value rewrite, referring to the online documentation and not being sourced. Here is the code (part):Public class binaryjediscluster extends jediscluster { public string set (Final string key, final byte[] value) { return new JedisClusterCommand<String> (connectionhandler, timeout, Maxredirections) { public String execute (jedis connection) { return connection.set (Safeencoder.encode (key), value); } }.run (key); } public byte[] getbytes (final String key) { return new jedisclustercommand<byte[]> ( connectionhandler, timeout, maxredirections) { public byte[] execute (jedis connection) { return connection.get (SafeEncoder.encode (key)); } }.run (Key); } public set<byte[]> Zrevrangebyscorebytes (final string key, final double max, &nbsP; final double min, final int offset, final int count) { Return new jedisclustercommand<set<byte[]>> (connectionhandler, timeout, maxredirections) { public Set<byte[]> Execute (jedis connection) { return connection.zrevrangebyscore (Safeencoder.encode (key), max, min, offset, count); } &Nbsp; }.run (key); } public set<byte[]> zrevrangebyscorebytes (Final string key, final string max , final String min, final int offset, final int Count) { return new jedisclustercommand<set <byte[]>> (connectionhandler, timeout, maxredirections) { public set<byte[]> execute (jedis connection) { &nbsP; return connection.zrevrangebyscore ( Safeencoder.encode (Key), safeencoder.encode (max), SafeEncoder.encode ( min), offset, count); } }.run (key); } public long linsert (final string key, final list_position where, final byte[] pivot, final byte[] value) { return new JedisClusterCommand<Long> (Connectionhandler, timeout, &nbsP; maxredirections) { public long execute (Jedis Connection) { return connection.linsert (Safeencoder.encode (key), where, Pivot, value); } }.run (key); } public long lpushx (final string key, final byte[]... string) { return new JedisClusterCommand<Long> (Connectionhandler, timeout, maxredirections) { public long execute (Jedis connection) { return connection.lpushx (Safeencoder.encode (key), string); } }.run (key); } public long rpushx (final string key, final byte[] ... string) { return new jedisclustercommand <Long> (connectionhandler, timeout, maxredirections) { public&nbSp Long execute (jedis connection) { return connection.rpushx (Safeencoder.encode (key), string); } }.run (Key); } public list<byte[]> Blpopbytes (Final string arg) { return new JedisClusterCommand<List<byte[]>> (connectionhandler, timeout, maxredirections) { public list<byte[]> execute (Jedis connection) { return conneCtion.blpop (Safeencoder.encode (ARG)); } }.run (NULL); } Public list<byte[]> brpopbytes (Final string arg) { return new JedisClusterCommand<List<byte[]>> (Connectionhandler, timeout, Maxredirections) { public List<byte[]> execute (jedis connection) { return connection.brpop (SafeEncoder.encode (ARG)); } }.run (NULL); }}
Post-compilation Jedis jar package: Http://pan.baidu.com/s/1mgIPYDa
Source Address: Http://pan.baidu.com/s/1jGIobBo
Jedis connection for three Redis working modes