Customers using in-memory data in ecplise , if ready to download two jar Packages
Commons-pool2-2.0.jar
Jedis-2.4.2.jar
The premise is ready, so let's start the Redis service , Open a command window and enter the following command:redis-server or Redis-server redis root mesh \redis.conf
The server is turned on, note that the port number is 6377.
2. Create a project in Eclipse , import the package that redist needs into the project
3. write a Jedis Tool class
Public class Jedisutil {
Private Static String HOST="127.0.0.1"; //Native address
Private Static Integer PORT= 6379; //Service Port
Private Static Jedispoolconfig config; //Connection pool Configuration object
Private Static Jedispool Pool; //Connection pool object
Static {
config = new jedispoolconfig ();
config. Setmaxidle (1024*10); //Set memory size
Pool = new jedispool (config,HOST);
}
/**
*
* @return get a Jedis object from the connection pool
*/
Public Static Jedis Getpooljedis () {
return pool. getresource ();
}
/**
* Jedis objects are manually played back into the connection pool
*/
Public Static void Returnpooljedis (Jedis Jedis) {
pool. Returnresource (Jedis);
}
/**
* @return Create a Jedis connection directly
*/
Public Static Jedis Getjedis () {
return New Jedis (HOST, PORT);
}
}
4. Write a client class operation Jedis
Public class Client {
Public Static void Main (string[] args) {
Simpleset ();
MSet ();
}
Private Static void MSet () {
Note If you use Jedisutil.getjedis (); is to create a Jredis object directly, so it is not managed by the connection pool, so it cannot be played back into the connection pool.
Jedis Jedis = Jedisutil.getpooljedis ();
Setting values for multiple values
Jedis.mset ("UserName","user1","pwd","123");
Take value
list<string> list = Jedis.mget ("UserName","pwd");
for (String string:list) {
System. out. println (string);
}
Jedis.flushdb ();
Jedisutil.returnpooljedis (Jedis);
}
Private Static void Simpleset () {
Jedis Jedis = Jedisutil.getpooljedis ();
Setting the value
Jedis.set ("UserName", "user1");
Take value
System. out. println ("userName:"+jedis.get ("userName"));
Emptying the in-memory database
Jedis.flushdb ();
Jedisutil.returnpooljedis (Jedis);
}
}
Data can now be evaluated on the redist client
Open a Command window, enter the command redis-cli Open the client , after the original assignment