Key-Value Database with Java client

爷,独闯天下 提交于 2019-12-07 21:17:23

问题


I basically want to store a hashtable on disk so I can query it later. My program is written in Java. The hashtable maps from String to List.

There are a lot of key-value stores out there, but after doing a lot of research/reading, its not clear which one is the best for my purposes. Here are some things that are important to me.

  1. Simple key-value store which allows you to retrieve a value with a single key.
  2. Good Java client that is documented well.
  3. Dataset is small and there is no need for advanced features. Again, I want it to be simple.

I have looked into Redis and MongoDB. Both look promising but not ideal for my purposes. Any info would be appreciated.


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/4881450/key-value-database-with-java-client

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