This article mainly explains how to operate Redis in Java.
Using Java to connect Redis requires the introduction of a corresponding Jedis jar package.
Java connects to a single redis, Redis connection pool, Redis cluster (explained later)
//Connection Single Redis server
Jedis jedis= New Jedis ("192.168.0.100", 6379);
//Connection Redis thread Pool
Redis Configuration Objects
Jedispoolconfig config = New jedispoolconfig ();
// maximum number of available Redis connection instances
Config.setmaxactive (8);
//maximum idle (idle) Number of Jedis instances, the default value is also 8 Config.setmaxidle (8);
//The maximum time to wait for an available connection, in units milliseconds , the default value is-1, which means that never times out. If the waiting time is exceeded, the jedisconnectionexception is thrown directly;
Config.setmaxwait (10000);
Whether validate operations are performed in advance when a Jedis instance is borrow, and if true, the resulting Jedis instances are available;
Config.settestonborrow (Test_on_borrow);
Redis Connection Pool Object
Jedispool Jedispool = New jedispool(config, "192.168.0.100", "6379", "10000");
Jedis resource = jedispool.getresource ();
Releasing Jedis Resources
Jedispool. Returnresource (Jedis) ;
The string, Hash, List, Set, Zset, respectively, are explained in turn
One, string manipulation
Second,the hash operation
4. Use of Redis and Java