1. Working with Redis in Java requires the use of the Jedis plugin and Linux to turn on the relevant firewall.
To restart the Firewall service:
2. Create a new MAVEN project:
3. Add Project Dependencies:
<dependency> <groupId>redis.clients</groupId> <artifactid>jedis</artifactid > <version>2.9. 0</version> </dependency>
4. Use the Redis tool to test if you can connect to Redis under Windows
5. Add a code test:
Public Static voidMain (string[] args) {//To create a Jedis object to connect to a Redis databaseJedis Jedis =NewJedis ("192.168.80.162",6379); //gets the value of the specified keyString name= Jedis.Get("name"); if(name==NULL){ //sets the value for the specified keyJedis.Set("name","Siggy"); } System. out. println ("name=="+jedis.Get("name")); Jedis.setnx ("Sex","female"); System. out. println ("sex="+jedis.Get("Sex")); //set Multiple valuesJedis.mset ("bname","Java","Bprice"," -","Bauthor","Sun"); System. out. println (Jedis.mget ("bname","Bprice","Bauthor")); }
Redis using the Java operation Redis