Using Maven to manage jars, add dependencies:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.0</version>
</dependency>//the jar needed
Use the configuration of the Redis database (setting the value of the property, depending on your needs), to save the data
Jedispool jedispool = null;
Jedispoolconfig poolconfig = new Jedispoolconfig ();
Poolconfig.setmaxidle (10);
Poolconfig.setmaxtotal (100);
Poolconfig.setmaxwaitmillis (10000);
Poolconfig.settestonborrow (TRUE);
Jedispool = new Jedispool (poolconfig, "192.168.0.109", 6379); Configure Jedis configuration, port, server address
Stored Procedures
List<string> lines = Files.readalllines (Paths.get ("E:/oooooooo/task.txt"));//The data source to be stored, the data format is many JSON form string
Jedis Jedis = Jedispool.getresource ();
Jedis.select (3);//3 refers to the partition on the database, can be set freely
Pipeline pipelined = jedis.pipelined ();
Lines.foreach (L-, {
Pipelined.lpush (database name, L);
});
Pipelined.sync (); The purpose of this code is to bulk store to the Redis database through pipelines (Pipeline)
Get data on Redis via Java
Jedispoolconfig poolconfig = new Jedispoolconfig ();
Poolconfig.setmaxidle (10);
Poolconfig.setmaxtotal (500);
Poolconfig.setmaxwaitmillis (100000);
Poolconfig.settestonborrow (TRUE);
Jedispool = new Jedispool (poolconfig, server address, port, timeout, database password);
Jedis Jedis = Jedispool.getresource ();
Jedis.select (3);//3 refers to the partition on the database, can be set freely
String targetstring = jedis.lpop (database name);; /targetstring is the target data that was taken out.
Jedispool.returnresourceobject (Jedis); After a meal, remember to release Jedis resources.
Java uses Redis database