BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Moneta: An Interface to Key-Value Stores like Tokyo Cabinet, Memcache

Moneta: An Interface to Key-Value Stores like Tokyo Cabinet, Memcache

Leia em Português

This item in japanese

Bookmarks

Relational databases are only one option when it comes to storing your data. Depending on the actual case, it might be worth taking a look at a key-value store. If the data is stored and accessed mainly by a primary key, a key-value store might be a better option than the relational model. So, what are key-value stores? The name sounds awfully similar to the plain-old hash, and conceptually, it's just that.

Compared to a fully fledged RDBMS, key-value stores are much simpler, which is likely also the reason why there are so many competing implementations available. We take a look at Tokyo Cabinet and Moneta, a unified interface for different key-value stores.

Tokyo Cabinet is a C library that implements a very fast and space efficient key-value store:

The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array.

Besides bindings for Ruby, there are also APIs for Perl, Java, and Lua available.

To share Tokyo Cabinet across machines, Tokyo Tyrant provides a server for concurrent and remote connections. For some examples and more information on Tokyo Cabinet, you might want to take a look at Ilya Grigorik's introductory article.

Suppose you have decided to use a key-value store, but don't want to decide on a specific implementation yet, Moneta might come in handy. It "aims to provide a unified interface for key/value stores", similar to what Rack does for web servers, and as Yehuda Katz explains, "libraries that want to provide sugar around key/value stores (e.g. Rails and Merb's caching support) can use Moneta as their backend".

Out of the box, Moneta supports a file store, memcache store, in-memory store, the xattrs in a file system, DataMapper, as well as the aforementioned Tokyo Cabinet (through rufus-tokyo, a "ruby-ffi based interface to Tokyo Cabinet and Tokyo Tyrant").

Read more about Moneta on Yehuda's blog or take a look at the github repository.

Rate this Article

Adoption
Style

BT