Key-Value Database with Java client

谁说我不能喝 提交于 2019-12-06 04:39:17

Before providing any sort of answers, I'd start by asking myself why do I need to store this hashtable on disk as according to your description the data set is small and so I assume it can fit into memory. If it is just to be able to reuse this structure after restarting your application, then you can probably use any sort of format to persist it.

Second, you don't provide any reasons for Redis or MongoDB not being ideal. Based on your (short) 3 requirements, I would have said Redis is probably your best bet:

  • good Java clients
  • not only able to store lists, but also supports operations on the list values (so data is not opaque)

The only reason I could suppose for eliminating Redis is that you are looking for strict ACID characteristics. If that's what you are looking for than you could probably take a look at BerkleyDB JE. It has been around for a while and the documentation is good.

What you are looking for is a library that supports object prevalence. These libraries are designed to be simple and fast providing collection like API. Below are few such libraries that allow you to work with collections but behind the scenes use a disk storage.

  1. space4j
  2. Advagato
  3. Prevayler

If your dataset is small and you want it to be SIMPLE. why don't you serialize your hashmap to a file or rdbms and load it in your application?

How do you wan't to "query" your hashmap? key approximation? value 'likeness'? I don't know, seems overkill to me to mantain a keyvalue storage just for the sake of.

Check out JDBM2 - http://code.google.com/p/jdbm2/

I worked on the JDBM 1 code base, and have been impressed with what I've seen in jdbm2

Chronicle Map should be a perfect fit, it's an embeddable key-value store written in pure Java, so it acts as the best possible "client" (though actually there are no "client" or "server", you just open your database and have full read/update in-process access to it).

Chronicle Map resides a single file. This file could be moved around filesystem, and even sent to another machine with different OS and/or architecture and still be an openable Chronicle Map database.

To create or open a data store (if the database file is non-existent, it is created, otherwise an existing store is accessed):

ChronicleMap<String, List<Point>> map = ChronicleMap
    .of(String.class, (Class<List<Point>>) (Class) List.class)
    .averageKey("range")
    .averageValue(asList(of(0, 0), of(1, 1)))
    .entries(10_000)
    .createPersistedTo(myDatabaseFile);

Then you can work with created ChronicleMap object just as with a simple HashMap, not bothering with keys and values serialization.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!