最好的 Java Redis 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3047010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:58:29  来源:igfitidea点击:

Best Redis library for Java

javaredis

提问by muriloq

The official Redis homepage lists JDBC-Redis and JRedis. What are the advantages / disadvantages of each ? Are there any other options ?

Redis 官方主页列出了 JDBC-Redis 和 JRedis。每个的优点/缺点是什么?还有其他选择吗?

回答by Romain Hippeau

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.

JDBC-Redis 只是 JRedis 数据库的 JDBC 包装器。
如果您计划在不同的后端使用您的代码,那么 JDBC 是一个不错的选择。注意:它不是一个完整的 JDBC 实现,并且 NOSQL 会溢出。
如果您打算继续使用 Redis,那么我建议您使用 API,这将为您提供更大的灵活性。使用 DAO 层模式来封装您的数据库访问,然后您将需要更改的全部内容。

回答by xetorthio

You can use also Jedis, which is also in the official Redis clients page. It is compatible with the latest version of Redis.

您也可以使用Jedis,它也在官方 Redis 客户端页面中。它与最新版本的Redis兼容。

Update

更新

As of June 2012, Jedis is the Java client library recommended by the Redis official page.

截至 2012 年 6 月,Jedis 是 Redis 官方页面推荐的 Java 客户端库。

回答by opyate

Both Jedisand JRedisare being actively developed. I personally use Jedis since it seems to be more actively developed.

无论JedisJRedis正在积极发展。我个人使用 Jedis,因为它似乎得到了更积极的开发。

Spring provides a wrapper around both implementations and they're providing serialization/deserialization, amongst other things:

Spring 为这两个实现提供了一个包装器,它们提供了序列化/反序列化等功能:

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/

http://git.springsource.org/spring-data/spring-keyvalue-redis/

UPDATESpring 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.

更新Spring Data 现在添加了对名为rjc(Redis Java 客户端)的第三个库的支持——不过,我不知道它的优缺点是什么。

回答by gshx

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 这样的对象哈希映射器 (OHM)。JOhm 允许用户使用熟悉的注释来装饰他们现有的对象,以允许持久化到 Redis,而无需任何侵入性的代码更改。它甚至不需要任何外部配置。您可以将 OHM 视为 RDBMS 的 ORM 的 NoSQL 对应物。

JOhm is hosted here

JOhm 托管在这里

回答by secmask

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.

我尝试过 JDBC-Redis、Jredis 和 Jedis。JDBC-Redis 不擅长性能。JRedis 和 Jedis 都很快,我多次使用 Jredis,但现在我更喜欢 Jedis,因为它很简单,而且我可以根据需要处理网络连接错误。

回答by mpenet

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.

只是一个更新:似乎 jredis 不再那么活跃了,但是 jedis 正在变得强大并且最近实现了一些很棒的功能,它也是 JOhm 的同一个开发人员。

extract from their readme on github:

从他们在 github 上的自述文件中摘录:

Ok.. so what can I do with Jedis? [...]

好吧..那么我可以用 Jedis 做什么?[...]

Transactions

交易

Pipelining

流水线

Publish/Subscribe

发布/订阅

Persistence

坚持

control commands

控制命令

Remote server control commands

远程服务器控制命令

Connection pooling

连接池

Sharding (MD5, MurmureHash)

分片(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.

直到最近,我在六个项目中使用 jredis,并很快将它们全部迁移到 jedis,没有任何意外。

回答by CharlieQ

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.

Jedis 是一个非常好的客户。我已经使用 jedis 对 redis 进行了一些性能测试。50 个客户端,1m 请求在 20 秒内完成(在旧的 intel 2core 2.6g 机器上,100m 网络)。我相信如果我可以使用1000m网络进行测试,性能会更高。