简体   繁体   English

用于计数器的Java嵌入式键值数据存储

[英]java embedded key-value data store for counters

I am searching for an embedded key-value data store which 我正在寻找一个嵌入式的键值数据存储

  1. has Java API 有Java API
  2. easy to manipulate counters (aka SET value=value+10 WHERE key="k") 易于操作的计数器(又名SET value = value + 10 WHERE key =“ k”)
  3. support multi-threads clients 支持多线程客户端
  4. High performance 高性能

I have found LevelDBJni , but it is designed for simple KV operation and unfriendly for counters. 我已经找到了LevelDBJni ,但是它是为简单的KV操作而设计的,对计数器不友好。 Are there better solutions? 有更好的解决方案吗?

Thanks. 谢谢。

With the Java library you can use a Map with an AtomicInteger as value. 使用Java库,您可以将AtomicInteger用作值的Map

In the following examples I use String as datatype for the key. 在以下示例中,我将String用作键的数据类型。

Eg 例如

Map<String, AtomicInteger> kvStore = new ...

To manipulate the counters you can then use 要操作计数器,您可以使用

kvStore.get("...").addAndGet(10);

To retrieve also the updated value 还要检索更新的值

AtomicInteger value = kvStore.get("...").addAndGet(10);

As AtomicInteger is designed for concurrency a multi-threaded environmet should be no problem. 由于AtomicInteger是为并发而设计的,因此多线程环境应该没有问题。

I cannot tell you how the performance of this is as I don't know your specific requirements so you have to determine this yourself. 我无法告诉您这样做的效果如何,因为我不知道您的具体要求,因此您必须自己确定。

嵌入式Java DB count-db( https://github.com/koendeschacht/count-db )在其API中提供了一个count方法,该方法应对此用例进行解答。

Take a look at http://www.mapdb.org . 看看http://www.mapdb.org It is very high performance and offers a very familiar API (Java Map). 它具有很高的性能,并提供了非常熟悉的API(Java Map)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM