Maven Dependency Packages:
1 <Dependency>2 <groupId>Redis.clients</groupId>3 <Artifactid>Jedis</Artifactid>4 <version>2.9.0</version>5 </Dependency>6 <Dependency>7 <groupId>Org.apache.commons</groupId>8 <Artifactid>Commons-pool2</Artifactid>9 <version>2.6.0</version>Ten </Dependency>
Source:
1 Packagestudypro.base;2 3 Importorg.junit.Test;4 ImportRedis.clients.jedis.Jedis;5 ImportRedis.clients.jedis.JedisPool;6 ImportRedis.clients.jedis.JedisPoolConfig;7 8 Public classTestsample {9 //Jedis Jedis = new Jedis ("10.15.1.19", 16379);Ten One //Simple Connection A @Test - Public voidTest () { -Jedis Jedis =NewJedis ("10.15.1.19", 16379); theJedis.auth ("WC3XO8E5MLMGMB"); -Jedis.set ("A", "BB")); -System.out.println (Jedis.get ("a")); - jedis.close (); + } - + //Using connection pooling A @Test at Public voidTestpool () { -Jedispoolconfig Poolconfig =Newjedispoolconfig (); -Poolconfig.setmaxidle (20); -Poolconfig.setminidle (10); -Poolconfig.setmaxtotal (30); -Poolconfig.setmaxwaitmillis (3000); inPoolconfig.settestonborrow (true); -Poolconfig.settestonreturn (true); toJedispool Jedispool =NewJedispool ("10.15.1.19", 16379); +Jedis Jedis =Jedispool.getresource (); -Jedis.auth ("WC3XO8E5MLMGMB"); theSystem.out.println (Jedis.get ("a")); * jedis.close (); $ jedispool.close ();Panax Notoginseng } - the}
Java Code REDIS Basic operations