[Redis] Redis operations on string type data

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.