Basic use of Redis

Source: Internet
Author: User

I. Installation of the REDIS environment

1,: Https://github.com/MSOpenTech/redis

2. Install on Windows, boot, default port 6379.

3, the basic use of methods, in the project to introduce Jedis.jar files.

 PackageCom.redis;ImportJava.util.Set;ImportRedis.clients.jedis.Jedis; Public classredisclient { Public Final StaticString redis_host = "127.0.0.1";//The server address where Redis resides     Public Final StaticInteger redis_port = 6379;//Redis Port     Public StaticJedis getredisclient () {Jedis Jedis=NULL; Jedis=NewJedis (Redisclient.redis_host, Redisclient.redis_port); returnJedis; }     Public Static voidjedistest () {Jedis Jedis=getredisclient (); //Deposit JedisJedis.set ("Key1", "LVYF"); Jedis.set ("Key2", "CHENJL"); Jedis.set ("Color", "red"); //determine if a key existsSystem.out.println (jedis.exists ("Color")); //output all the keysSYSTEM.OUT.PRINTLN ("All keys are as follows:"); Set<String> keys = Jedis.keys ("*");  for(String keytmp:keys) {System.out.println ("Key:" +keytmp); }                //Delete a keySystem.out.println ("Delete Key1 in System:" +jedis.del ("Key1"))); //Set Expiration TimeSYSTEM.OUT.PRINTLN ("Set Expiration Time:" +jedis.expire ("Key2", 5)); //View the type of value stored by keySystem.out.println ("Type:" +jedis.type ("Color")); //gets the value corresponding to the keySYSTEM.OUT.PRINTLN ("color corresponding to Value:" +jedis.get ("Color")); //AppendJedis.append ("Color", "-test"); System.out.println (Jedis.get ("Color")); //List FunctionJedis.lpush ("Numberlists", "3"); Jedis.lpush ("Numberlists", "1"); Jedis.lpush ("Numberlists", "5"); Jedis.lpush ("Numberlists", "2"); System.out.println ("All elements:" + jedis.lrange ("Numberlists", 0, 1)); //Clear Datajedis.flushdb (); }     Public Static voidMain (string[] args) {jedistest (); }}

Basic use of Redis

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.