Because of the project needs, recently learned the use of Redis
Redis installation in a server CentOS environment is relatively straightforward.
If you want to install on Windows, you can refer to someone else's article
http://blog.csdn.net/renfufei/article/details/38474435
Redis login, no password is required by default, port number is 6379 by default
Use visualizer Redis-desktop-manager to view data under Windows
Redis supports the following types of data structures as a cache database:
String (string), hash (hash), list, set (set), and Zset (sorted set: Ordered set)
The project uses Java as the development language, only need to introduce Jedis, commons-pool2 two jar package, if you need to add a spring-data-redis with spring
Jedis is the object in Java that is used to manipulate Redis
The simplest way to create:
Jedis jedis=New Jedis ("192.168.1.101");
Port number is used by default, no password authentication is used
Insert a string:
Jedis.set ("name", "Gary");
Execution results, you can see the insertion of a string gary,key to name
You can also set multiple key-value pairs at once:
Jedis.mset ("name", "Gary", "Age", "$", "email", "xxxxxx.163.com");
If it is an int value, you can also add 1 directly:
JEDIS.INCR ("Age");
Determine if key exists:
System.out.println (jedis.exists ("name")); System.out.println (Jedis.exists ("name2"));
To set the expiration time for a key:
Jedis.expire ("name", 5); Expired after//5s
Second parameter unit is second
Remove the value of key:
System.out.println ("Name:" +jedis.get ("name"));
Delete key:
Jedis.del ("name");
Redis also has a feature for publishing subscriptions that can implement Message Queuing
Getting started with Redis's Java usage