The Java clients listed on the Redis home page have Jdbc-redis Jredis Jedis three, and the following describes the advantages and disadvantages of three clients and other related tools.
|  
|
Redis version supported |
performance |
maintenance |
recommended |
|   |
  |
  |
| jredis |
1.2.N release
2.0.0 Not yet release version |
fast |
  |
& nbsp; |
| jedis |
2.0.0 release |
< td> |
actively developed |
recommended |
Jdbc-redis
Jdbc-redis is just a JDBC wrapper for Jredis database.
If you plan on the using your code with different back-ends then the JDBC is a good the go. Note:it is isn't a complete JDBC implementation and the NOSQL would bleed through.
If you were going to stay with Redis then I would suggest using the API, which would give you more flexibility. Use a DAO layer pattern to encapsulate your DB Access and down the road, that's all you'll need to change.
-Romain Hippeau
Redis syntax is completely different from standard SQL so using JDBC doesn ' t help encapsulating different Back-ends As you suggest:i would has to write new queries Anyway...–muriloq June "
at
@muriloq-but the mechanical acquiring and releasing resources is Standard.–romain Hippeau
Spring Wrapper
Spring provides a wrapper around both implementations (Jredis Jedis) and they ' re providing serialization/deserializatio N, amongst other things:
| 1234 |
person p = new person ( "Joe" 33 ); template.convertandset ( "trader:1" , p); person Sameperson = Template.getandconvert ( "trader:1" , person. class assert.assertequals (p, Sameperson); |
The above method may have been adjusted, see the latest http://static.springsource.org/spring-data/data-keyvalue/docs/1.0.0.M2/reference/html/#redis
Discard Spring Wrapper
The project originally intended to use the spring wrapperBean id = "jedisPoolConfig" class = "redis.clients.jedis.JedisPoolConfig" >
<property name="maxActive" value="20"/> <property name="maxIdle" value="10"/> <property name="maxWait" value="1000"/> </bean><!-- jedis shard信息配置 --><bean id="jedis.shardInfo" class="redis.clients.jedis.JedisShardInfo"> <constructor-arg index="0" value="*.*.*.*"/> <constructor-arg index="1" value="6379"/> </bean><!-- jedis shard pool配置 --><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><bean id="jedisCommands" factory-bean="shardedJedisPool" factory-method="getResource"/>
The above method of matching gets the instantiation of jediscommands at spring initialization, and then each Redis call is not fetched from the pool, the solution:
Set up
| 1234567891011121314151617181920212223 |
<!-- POOL配置 --><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxActive"value="20" /> <property name="maxIdle" value="10" /> <property name="maxWait" value="1000" /> <property name="testOnBorrow"value="true"/></bean><!-- jedis shard信息配置 --><bean id="jedis.shardInfo" class="redis.clients.jedis.JedisShardInfo"> <constructor-arg index="0" value="*.*.*.*" /> <constructor-arg index="1" value="6379" /></bean><!-- jedis shard pool配置 --><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> |
Reference:
Http://stackoverflow.com/questions/3047010/best-redis-library-for-java
Https://github.com/xetorthio/johm
Https://github.com/xetorthio/jedis/issues/closed#issue/76
Redis Data Summary (10) Java Client