Ext.: http://blog.csdn.net/jiangtao_st/article/details/8256610
First, download the jar package
Https://github.com/xetorthio/jedis/downloads
Learn the reference content:
Http://blog.nosqlfan.com/html/3537.html
Second, the configuration in spring
<Bean id= "jedispoolconfig" class="Redis.clients.jedis.JedisPoolConfig">
- <property name= "maxactive" value= " /> "
- <property name= "maxidle" value= "ten" />
- <property name="maxwait" value= " /> "
- <property name="Testonborrow" value="true"/>
- </Bean>
- <Bean id= "jedis.shardinfo" class="Redis.clients.jedis.JedisShardInfo">
- <constructor-arg index="0" value= "fill your Reids server IP here" />
- <constructor-arg index="1" value="6379" />
- </Bean>
- <Bean id= "shardedjedispool" class="Redis.clients.jedis.ShardedJedisPool">
- <constructor-arg index="0" ref="jedispoolconfig" />
- <constructor-arg index="1">
- <list>
- <ref bean="Jedis.shardinfo" />
- </list>
- </constructor-arg>
- </Bean>
Third, the use in the Java code
publicclassRedis{ Public staticvoidmain(Stringargs[]){ //Connect Redis service JedisJedis=newJedis("192.168.0.234",6400); //Password verification-if you have not set up a redis password, you can use the relevant command without verifying it Jedis. Auth("ABCDEFG"); //Simple Key-value storage Jedis. Set("TN","Thisuc"); System. Out. println(Jedis. Get("TN")); //Added on original merit, if not previously, import the key Redis corresponding to "Myredis" has been set, and this execution will make Redis correspond to "Myredisyourredis" Jedis. Append("Redis","Yourredis"); Jedis. Append("content","Rabbit"); //mset is to set multiple Key-value value parameters (key1,value1,key2,value2,..., keyn,valuen) //mget is the value parameter that gets multiple keys (Key1,key2,key3,..., Keyn) returns a Jedis. Mset("name1","Thisuc","name2","Gaoxc","Name3","lemon "); System. Out. println(Jedis. Mget("name1","name2","Name3")); }}
How Redis is used in Java