The caching framework of 1.redis and Memecache is divided into server side and client.
We use in the project, the equivalent of the client, to introduce the client to use the Redis jar package
- First you need to download the driver package, download the Jedis.jar, and make sure to download the latest driver package.
2.redis is connected via Jedis, so instantiate the Jedis, then connect the server to
Jedis=newJedis("localhost");
3.redis Store list data
JedisJedis= New Jedis("LocalHost"); System.Out.println("Connection to Server sucessfully"); Storing data in a listJedis.Lpush("Tutorial-list", "Redis");Jedis.Lpush("Tutorial-list", "Mongodb");Jedis.Lpush("Tutorial-list", "Mysql"); Get the stored data and output List<String>List=Jedis.Lrange("Tutorial-list", 0 ,5);For (int i=0; i<list. Size(); i+ +) { System. Out. println("Stored string in Redis::"+list. ) Get(i)); }< /c15>
4.redis get the key value, enter
JedisJedis= New Jedis("LocalHost"); System.Out.println("Connection to Server sucessfully"); Get the data and output List<String>List=Jedis.Keys("*" for (int I =0; I< list. I++) { system.. Println ( "List of stored keys::" +listget (i /span>
Java uses Redis