1, the first to download Redis, this resource is everywhere on the internet. (the service cannot be turned off during redis, otherwise it cannot be accessed)
After downloading a driver package, I downloaded it through maven and added coordinates.
2, will install or unzip the Redis configuration to the system environment variable, my path is D:\redis\64bit
3, use in Java, such as the following basic operations:
The first is to get the Redis object in Java Jedis
Jedis Jedis = new Jedis ("localhost");
Test if the link succeeds if print server is Running:pong indicates success
System.out.println ("Server is running:" + jedis.ping ());
Storing key-value pairs of information
Jedis.set ("name", "Lisi");
Use get to get its value by key
System.out.println (Jedis.get ("name"));
Store a set of data in a Jedis (actually a list)
Jedis.lpush ("AAA", "AAA");
Jedis.lpush ("AAA", "BBB");
Jedis.lpush ("AAA", "CCC");
Jedis.lpush ("AAA", "ddd");
Jedis.lpush ("AAA", "Eee");
Jedis.lpush ("AAA", "FFF");
Jedis.lpush ("AAA", "GGG");
Jedis.lpush ("AAA", "JJJ");
According to the key from the Jedis to take data, start and end subscript, the last to add the data subscript is 0, subscript is calculated from the next online
list<string> lists = Jedis.lrange ("AAA", 6, 6);
for (String list:lists) {
SYSTEM.OUT.PRINTLN (list);
}
Delete a key value
Jedis.del ("nae");
Querying all the keys that exist in the Jedis
set<string> sets = Jedis.keys ("*");
for (String set:sets) {
System.out.println ("set:" + set);
}
Using Redis in Java