寻找轻量级的 Java 兼容内存键值存储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2574689/
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
Looking for a lightweight java-compatible in-memory key-value store
提问by Roman
Berkeley DB would be the best choice probably but I can't use it due to licensing issues.
Berkeley DB 可能是最佳选择,但由于许可问题我无法使用它。
Are there any alternatives?
有没有其他选择?
回答by Fuad Malikov
You can try Hazelcast. Just add hazelcast.jar to your classpath. And start coding
你可以试试Hazelcast。只需将 hazelcast.jar 添加到您的类路径中。并开始编码
java.util.Map map = Hazelcast.getMap("myMap");
You'll get an in-memory, distributed, dynamically scalable data grid which performs super fast.
您将获得一个内存中、分布式、动态可扩展的数据网格,它的执行速度非常快。
回答by cletus
Your question could mean one of two things.
你的问题可能意味着两件事之一。
If you mean a data structure for storing key-value pairs, use one of the Mapinstances that are a standard part of the JDK.
如果您指的是用于存储键值对的数据结构,请使用Map作为 JDK 标准部分的实例之一。
If however you are after an in-memory key-value store then I would suggest taking a look at EHCacheor even memcached.
回答by leventov
Chronicle-Mapis a strong alternative.
Chronicle-Map是一个很好的选择。
- Pure Java, simply
java.util.Mapimplementation - Stores the data off-heap, optionally persisted to disk via memory-mapped files
- Open source, permissive Apache 2.0 license
- Incredibly fast, can manage millions of updates/queries per second (see exact numbers)
- 纯Java,简单
java.util.Map实现 - 将数据存储在堆外,可选择通过内存映射文件持久化到磁盘
- 开源、宽松的 Apache 2.0 许可证
- 非常快,每秒可以管理数百万次更新/查询(请参阅确切数字)
回答by Kevin Day
jdbmworks great for this sort of thing. It's intended for storing on disk in a paged file, provides for basic transaction support (no guarantees on isolation, but ACD are covered). We've used it in a production system with fairly wide deployment and have been quite pleased with the performance, stability, etc...
jdbm非常适合这类事情。它旨在以分页文件的形式存储在磁盘上,提供基本的事务支持(不保证隔离,但涵盖了 ACD)。我们已经在部署相当广泛的生产系统中使用了它,并且对性能、稳定性等感到非常满意......
回答by Nathan Hurst
回答by Richard Yhip
I know this is a two-year old post but I've been messing around with Infinispanrecently and I like it so far. I'm not an expert by any means but it was not too difficult for me to set up a distributed cache with a few nodes and I was pulling some data from them in about an hour.
我知道这是一个两年前的帖子,但我最近一直在使用Infinispan,到目前为止我很喜欢它。我无论如何都不是专家,但对我来说用几个节点设置分布式缓存并不太难,我在大约一个小时内从它们中提取了一些数据。
回答by Andrejs
MapDbis an alternative to Berkley with a friendly Apache 2 license.
MapDb是 Berkley 的替代品,具有友好的 Apache 2 许可证。
- Provides key-value store via java's Map interface
- Lightweight (300KB jar)
- Fast and threadsafe
- Persists changes to disk if you want to
- Many other features
- 通过 java 的 Map 接口提供键值存储
- 轻量级(300KB jar)
- 快速且线程安全
- 如果需要,可以将更改保留到磁盘
- 许多其他功能
回答by Nikita Koksharov
I would recommend to try a Redisson. You will able to use distributed and scalable Mapor ConcurrentMapand other (Set, List, Queue, Lock ...) implementations on top of high performance key-value Redisserver.
我会建议尝试Redisson。您将能够在高性能键值Redis服务器之上使用分布式和可扩展Map或ConcurrentMap其他(设置、列表、队列、锁定...)实现。
Easy example:
简单的例子:
Redisson redisson = Redisson.create();
ConcurrentMap<String, SomeObject> map = redisson.getMap("anyMap");
...
redisson.shutdown();
回答by Sebastien Lorber
There are lightweigh or embedded dbs like HSQLDB, Derby, SQLite But like others don't understand why you need a db to store key/values...
有轻量级或嵌入式数据库,如 HSQLDB、Derby、SQLite 但像其他人一样不明白为什么需要数据库来存储键/值......
Why not a Map? Need to keep key/values on app reboot?
为什么不是地图?需要在应用程序重新启动时保留键/值吗?
Also it's perhaps not what you need but with html5 on up to date browsers you have localStorage that permits you to store key/values in the browser using javascript.
此外,它可能不是您需要的,但是在最新的浏览器上使用 html5,您可以使用 localStorage 允许您使用 javascript 在浏览器中存储键/值。

