One. Add dependency
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.0</version>
</dependency>
Two. Example:
1. Create Jedis Object Operations Redis
Constructing Jedis objects
Jedis Jedis = new Jedis ("127.0.0.1", 6379);
Adding data to Redis
Jedis.set ("MyTest", "123bin");
Reading data from Redis
String value = Jedis.get ("mytest"); System.out.println (value);
Close connection
Jedis.close (); 2. Build connection pool configuration information by connecting pooling//
Jedispoolconfig jedispoolconfig = new Jedispoolconfig ();
Set maximum number of connections
Jedispoolconfig.setmaxtotal (50); Building Connection Pools
Jedispool Jedispool = new Jedispool (jedispoolconfig, "127.0.0.1", 6379); Getting connections from the connection pool
Jedis Jedis = Jedispool.getresource (); Reading data
System.out.println (Jedis.get ("mytest")); Returning the connection to the connection pool
Jedispool.returnresource (Jedis); Releasing the connection pool
Jedispool.close ();//Note: actually in use. The connection pool cannot be closed, or the connection pool cannot be used once the execution is complete
Use of Redis (Java uses Jedis clients to connect to Redis)