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