26

According to this thread, Jedis is the best thing to use if I want to use Redis from Java.

However, I was wondering if there are any libraries/packages providing similarly efficient set operations to those that already exist in Redis, but can be directly embedded in a Java application without the need to set up separate servers. (i.e., using Jetty for web server).

To be more precise, I would like to be able to do the following efficiently:

  1. There are a large set of M users (M not known in advance).
  2. There are a large set of N items.
  3. We want users to examine items, one user/item at a time, which produces a stored result (in a normal database.)
  4. Each time a user arrives, we want to assign to that user the item with the least number of existing results that the user has not already seen before. This produces an approximate round-robin assignment of the items over all arriving users, when we just care about getting all items looked at approximately the same number of times.

The above happens in a parallelized fashion. When M and N are large, Redis accomplishes the above much more efficiently than SQL queries. Is there some way to do this using an embeddable Java library that is a bit more lightweight than starting a Redis server?

I recognize that it's possible to write a pile of code using Java's concurrency libraries that would roughly approximate this (and to some extent, I have done that), but that's not exactly what I'm looking for here.

Community
  • 1
  • 1
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224

4 Answers4

11

Have a look at project voldemort . It's an distributed key-value store created by Linked-In, and it supports the ability to be embedded.

In the quick start guide is a small example of running the server embedded vs. stand-alone.

VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
VoldemortServer server = new VoldemortServer(config);
server.start();

I don't know much about Redis, so I can't compare them feature to feature. In the project we used Voldemort, we used it's readonly backing store with great results. It allowed us to "precompile" a bi-daily database in our processing data-center and "ship it" out to edge data-centers. That way each edge data-center had a local copy of it's dataset.

EDIT: After rereading your question, I wanted to add Gauva's Table -- This Table DataStructure may also be something your looking for and is simlar to what you get with many no-sql databases.

eSniff
  • 5,713
  • 1
  • 27
  • 31
  • Sounds very interesting...so I can run a one-node instance just for local lookups and stuff? I will check it out. – Andrew Mao Mar 07 '13 at 19:31
  • @AndrewMao Yes it support a single node. And I added a link to Gauva's Table data structure also. good luck and happy hunting :-) – eSniff Mar 07 '13 at 19:39
4

Hazelcast provides a number of distributed data structure implementations which can be used as a pure Java alternative to Redis' services. You could then ship a single "jar" with all required dependencies to run your application. You may have to adjust for the slightly different primitives relative to Redis in your own application.

Commercial solutions in this space include Teracotta's Enterprise Ehcache and Oracle Coherence.

Pavel
  • 3,481
  • 26
  • 31
0

Take a look at lmdb (Lightning Memory Database), because I needed exactly the same thing. I deploy a dropwizard application into a container, and adding redis or another external dependancy is painful. This seems to perform well, has good activity. fyi, though, i have not yet used this in production.

https://github.com/lmdbjava/lmdbjava

-6

Google's Guava Library provides friendly versions of the same (and more) Set operators that redis provides.

https://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained

e.g.

    Guava                     Redis
    Sets.intersection(a,b)    sinter a b
    a.count()                 scard a
    Sets.difference(a,b)      sdiff a b
    Sets.union(a,b)           sunion a b

Multisets are a reasonably straightforward proxy for redis sorted-sets as well.

Scott B
  • 1,665
  • 1
  • 15
  • 14
  • 2
    This definitely does not answer the question. While Guava is an extremely useful general library, it doesn't provide a key-value store. The results of these methods still have to be persisted in some way. – gyorgyabraham Jul 16 '13 at 11:29
  • 2
    @gyabraham actually, in many use cases Redis is not persisting the data, some other database is doing that. It is just used as a fast way to compute queries that would be nearly impossible using the database. In any case, Guava can't really replace the features of Redis. – Andrew Mao Sep 19 '13 at 16:19
  • 1
    Jedis is just a Java API to Redis. The database still needs to be explicitly started outside the Java process. – Arun Gupta Oct 03 '13 at 19:31