Best Redis library for Java
JavaRedisJava Problem Overview
The official Redis homepage lists JDBC-Redis and JRedis. What are the advantages / disadvantages of each ? Are there any other options ?
Java Solutions
Solution 1 - Java
You can use also Jedis, which is also in the official Redis clients page. It is compatible with the latest version of Redis.
Update
As of June 2012, Jedis is the Java client library recommended by the Redis official page.
Solution 2 - Java
I've tried JDBC-Redis, Jredis and Jedis. JDBC-Redis is not good at performance. JRedis and Jedis are both fast, I use Jredis for times but now I prefer Jedis because it's simple, and I can handle network connection errors as I want.
Solution 3 - Java
Both Jedis and JRedis are being actively developed. I personally use Jedis since it seems to be more actively developed.
Spring provides a wrapper around both implementations and they're providing serialization/deserialization, amongst other things:
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://git.springsource.org/spring-data/spring-keyvalue-redis/
UPDATE Spring Data now added support for a 3rd library called rjc (Redis Java Client) -- I don't know what the pros/cons for it are, though.
Solution 4 - Java
Jedis is a very good client. I have used jedis to make some performance test against redis. 50 clients, 1m requests completed in 20 seconds(on a old intel 2core 2.6g machine, 100m network). I believe the performance can be much higher if I can use 1000m network to do the test.
Solution 5 - Java
An easier solution is to not worry about working at the lowest level but use an Object Hash Mapper (OHM) like JOhm instead. JOhm lets users decorate their existing objects with familiar annotations to allow persistence to Redis without any invasive code changes. It does not even need any external configuration. You can think of the OHM as a NoSQL counterpart to the ORM of RDBMS.
JOhm is hosted here
Solution 6 - Java
just an update: it seems jredis is not that active anymore, jedis however is going strong and had some great features implemented recently, it s also the same developer of JOhm.
extract from their readme on github:
Ok.. so what can I do with Jedis? [...]
Transactions
Pipelining
Publish/Subscribe
Persistence
control commands
Remote server control commands
Connection pooling
Sharding (MD5, MurmureHash)
Key-tags for sharding
Sharding with pipelining
I was using jredis until recently on half a dozen of projects, moved them all to jedis in no time, without surprises.
Solution 7 - Java
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.