PackageCom.xwolf.java.redis;ImportOrg.junit.Before;Importorg.junit.Test;ImportRedis.clients.jedis.Jedis;ImportRedis.clients.jedis.JedisPool;ImportRedis.clients.jedis.JedisPoolConfig;Importjava.util.List;/*** Created by Administrator on 2015/12/15 0015.*/ Public classRedisop {PrivateJedispool Jedispool; PrivateJedis Jedis; PrivateString host= "127.0.0.1"; Private intport=6379; @Before Public voidConnect () {jedispoolconfig config=NewJedispoolconfig (); Config.setmaxidle (5); Config.setmaxtotal (20); Config.settestonborrow (false); Jedispool=NewJedispool (Config,host,port); Jedis=Jedispool.getresource (); } /*** Redis String type Test*/@Test Public voidteststring () {Jedis.set ("Name", "3243");//Add DataSystem.out.println (Jedis.get ("name"));//Get DataSystem.out.println (Jedis.flushdb ());//Clear All dataSystem.out.println (Jedis.get ("name")); Jedis.set ("QQ", "sdfsd32332"); System.out.println (Jedis.exists ("QQ"));//is there a key//setting multiple Key,value valuesJedis.mset ("K01", "V01", "k02", "V02", "k03", "v03", "K04", "v04"); //Delete key, return the number of deletesSystem.out.println (Jedis.del ("K03", "v03")); Jedis.rename ("K01", "k001");//Rename key//get multiple keyslist<string> VLS =jedis.mget ("k001", "k02", "V01"); for(String vl:vls) {System.out.println (VL); } System.out.println (Jedis.substr ("k001", 1,4));//intercepts the string of the specified keyJedis.lpush ("List01", "JavaScript", "Bootstrap", "JQuery", "Hadoop", "Redis");//storing list type dataSystem.out.println (Jedis.ltrim ("List01", 2,5)); }}
For more information:
Redis Common CommandsBasic Java-to-redis operations
[Redis] Redis operations on string type data