Redis資料匯總(十) java client

來源:互聯網
上載者:User

標籤:

redis首頁上列出的java 用戶端有JDBC-Redis JRedis Jedis三種,下面分別介紹三種用戶端的優缺點及其他相關的工具.

 

支援redis版本 效能 維護 推薦
JDBC-Redis   not good    
JRedis 1.2.n release
2.0.0 尚未release版本
fast    
Jedis 2.0.0 release fast actively developed 推薦

JDBC-Redis

JDBC-Redis is just a JDBC wrapper for JRedis database.
If you plan on using your code with different back-ends then JDBC is a good way to go. NOTE: It is not a complete JDBC implementation and the NOSQL will bleed through.

If you are going to stay with Redis then I would suggest using the API, which will give you more flexibility. Use a DAO layer pattern to encapsulate your DB Access and down the road that is all you will 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 have to write new queries anyway... – muriloq Jun 16 ‘10 at 14:00
@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/deserialization, amongst other things: 

1234 Person p = new Person("Joe", "Trader", 33);template.convertAndSet("trader:1", p);Person samePerson = template.getAndConvert("trader:1", Person.class);Assert.assertEquals(p, samePerson);
上面的方法可能已經調整,請參見最新的 http://static.springsource.org/spring-data/data-keyvalue/docs/1.0.0.M2/reference/html/#redis
放棄spring wrapper

項目中本來打算使用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" />

上面的這種配法在spring初始化時擷取一次執行個體化jedisCommands,而後每次的redis的調用時並未從pool中擷取,解決方案:

設定

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>

參考:
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資料匯總(十) java client

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.