Redis supports many programming language clients, C, C #, C + +, Clojure, Common Lisp, Erlang, Go, Lua, Objective-c, PHP, Ruby, Scala, Even the more fashionable node. js, of course, is more than Java's client support. Redis's official list of Java clients is also small, with Jedis, Jredis, Jdbc-redis, RJC, and, of course, Jedis is the official Redis preferred Java Client Development package.
Below we simply introduce the introduction of Jedis.
I use the tool is idea, the first step to create a MAVEN project is as follows:
1. Before creating the project, turn on the Redis boot to open your CMD interface, navigate to the Redis installation directory input command Redis-server redis.conf Enter the boot, start the result is this proves successful
2. Create your MAVEN project, which explains why you can create a MAVEN project because it is convenient and does not need to download the Redis dependency package, just add dependencies directly to the Pom.xml file.
The steps to create are as follows:
Next after:
Enter GroupID and Artifactid I won't explain, then next a maven project is done!
The Pom.xml dependency code is as follows:
Red circle of the dependency package can not be added, the landlord is connected in another way so added, you do not need.
2. Then, using the JUnit test, store a string with the key hw,value as Hello Word, and then get the key value, which is the following code:
Here the Main method please note that the red circle marks the place where eclipse may need to be written, Jedis Jedis =new Jedis ("127.1.0.1", 6379); Add a port number, which is not required here, Adding a port number throws an exception. It's OK. Use your JUnit test to run and see the console output of Hello Word
Big God do not spray, share to the introduction of the small white, in fact, I am, haha! Seung-so
Calling Redis using a Java client