<commit_before># Moneta: A unified interface for key/value stores

[![Build Status](https://secure.travis-ci.org/minad/moneta.png?branch=master)](http://travis-ci.org/minad/moneta) [![Dependency Status](https://gemnasium.com/minad/moneta.png?travis)](https://gemnasium.com/minad/moneta) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/minad/moneta)

Moneta provides a standard interface for interacting with various kinds of key/value stores. A short overview of the features:

* Supports a lot of backends (See below)
* Allows a full configuration of the serialization -> compression -> adapter stack using proxies (Similar to [Rack middlewares](http://rack.github.com/))
    * Configurable serialization via `Moneta::Transformer` proxy (Marshal/JSON/YAML and many more)
    * Configurable value compression via `Moneta::Transformer` proxy (Zlib, Snappy, LZMA, ...)
    * Configurable key transformation via `Moneta::Transformer` proxy
* Expiration for all stores (Added via proxy `Moneta::Expires` if not supported natively)
* Atomic incrementation and decrementation for most stores (Method `#increment` and `#decrement`)
* Includes a very simple key/value server (`Moneta::Server`) and client (`Moneta::Adapters::Client`)
* Integration with [Rails](http://rubyonrails.org/), [Rack](http://rack.github.com/), [Sinatra](http://sinatrarb.com/) and [Rack-Cache](https://github.com/rtomayko/rack-cache)

Moneta is tested thoroughly using [Travis-CI](http://travis-ci.org/minad/moneta).

## Links

* Source: <http://github.com/minad/moneta>
* Bugs:   <http://github.com/minad/moneta/issues>
* API documentation:
    * Latest Gem: <http://rubydoc.info/gems/moneta/frames>
    * GitHub master: <http://rubydoc.info/github/minad/moneta/master/frames>

## Supported backends

Out of the box, it supports the following backends:

* Memory:
    * In-memory store (`:Memory`)
    * LRU hash - prefer this over :Memory! (`:LRUHash`)
    * LocalMemCache (`:LocalMemCache`)
    * Memcached store (`:Memcached`, `:MemcachedNative` and `:MemcachedDalli`)
    * Daybreak database (`:Daybreak`)
* Relational Databases:
    * DataMapper (`:DataMapper`)
    * ActiveRecord (`:ActiveRecord`)
    * Sequel (`:Sequel`)
    * Sqlite3 (`:Sqlite`)
* Filesystem:
    * PStore (`:PStore`)
    * YAML store (`:YAML`)
    * Filesystem directory store (`:File`)
    * Filesystem directory store which spreads files in subdirectories using md5 hash (`:HashFile`)
* Key/value databases:
    * Berkeley DB (`:DBM`)
    * Cassandra (`:Cassandra`)
    * Daybreak (`:Daybreak`)
    * GDBM (`:GDBM`)
    * HBase (`:HBase`)
    * LevelDB (`:LevelDB`)
    * Redis (`:Redis`)
    * Riak (`:Riak`)
    * SDBM (`:SDBM`)
    * TokyoCabinet (`:TokyoCabinet`)
    * Simple Samba database TDB (`:TDB`)
* Document databases:
    * CouchDB (`:Couch`)
    * MongoDB (`:Mongo`)
* Moneta network protocols:
    * Moneta key/value client (`:Client` works with `Moneta::Server`)
    * Moneta HTTP/REST client (`:RestClient` works with `Rack::MonetaRest`)
* Other
    * Fog cloud storage which supports Amazon S3, Rackspace, etc. (`:Fog`)
    * Storage which doesn't store anything (`:Null`)

Some of the backends are not exactly based on key/value stores, e.g. the relational ones. These
are useful if you already use the corresponding backend in your application. You get a key/value
store for free then without installing any additional services and you still have the possibility
to upgrade to a real key/value store.

### Backend feature matrix

<table>
<thead style="font-weight:bold"><tr><th>Adapter</th><th>Required gems</th><th>Multi-thread safe<sup>[1]</sup></th><th>Multi-process safe<sup>[2]</sup></th><th>Atomic increment</th><th>Native expires<sup>[3]</sup></th><th>Persistent</th><th>Description</th></tr></thead>
<tbody>
<tr><td>ActiveRecord</td><td>active_record</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:green">✓</td><td>ActiveRecord ORM</td></tr>
<tr><td>Cassandra</td><td>cassandra</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Cassandra distributed database</td></tr>
<tr><td>Client</td><td>-</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Depends on server</td><td>Depends on server</td><td>Depends on server</td><td>Moneta client adapter</td></tr>
<tr><td>Cookie</td><td>-</td><td style="color:red">✗</td><td>Memory</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td>Cookie in memory store</td></tr>
<tr><td>Couch</td><td>couchrest</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:red">✗</td><td style="color:green">✓</td><td>CouchDB database</td></tr>
<tr><td>DataMapper</td><td>dm-core, dm-migrations</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:green">✓</td><td>DataMapper ORM</td></tr>
<tr><td>Daybreak</td><td>daybreak</td><td style="color:blue">?</td><td style="color:red">✗</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Daybreak ruby key/value store</td></tr><commit_msg>datamapper is thread safe, but doesn't support increment<commit_after># Moneta: A unified interface for key/value stores

[![Build Status](https://secure.travis-ci.org/minad/moneta.png?branch=master)](http://travis-ci.org/minad/moneta) [![Dependency Status](https://gemnasium.com/minad/moneta.png?travis)](https://gemnasium.com/minad/moneta) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/minad/moneta)

Moneta provides a standard interface for interacting with various kinds of key/value stores. A short overview of the features:

* Supports a lot of backends (See below)
* Allows a full configuration of the serialization -> compression -> adapter stack using proxies (Similar to [Rack middlewares](http://rack.github.com/))
    * Configurable serialization via `Moneta::Transformer` proxy (Marshal/JSON/YAML and many more)
    * Configurable value compression via `Moneta::Transformer` proxy (Zlib, Snappy, LZMA, ...)
    * Configurable key transformation via `Moneta::Transformer` proxy
* Expiration for all stores (Added via proxy `Moneta::Expires` if not supported natively)
* Atomic incrementation and decrementation for most stores (Method `#increment` and `#decrement`)
* Includes a very simple key/value server (`Moneta::Server`) and client (`Moneta::Adapters::Client`)
* Integration with [Rails](http://rubyonrails.org/), [Rack](http://rack.github.com/), [Sinatra](http://sinatrarb.com/) and [Rack-Cache](https://github.com/rtomayko/rack-cache)

Moneta is tested thoroughly using [Travis-CI](http://travis-ci.org/minad/moneta).

## Links

* Source: <http://github.com/minad/moneta>
* Bugs:   <http://github.com/minad/moneta/issues>
* API documentation:
    * Latest Gem: <http://rubydoc.info/gems/moneta/frames>
    * GitHub master: <http://rubydoc.info/github/minad/moneta/master/frames>

## Supported backends

Out of the box, it supports the following backends:

* Memory:
    * In-memory store (`:Memory`)
    * LRU hash - prefer this over :Memory! (`:LRUHash`)
    * LocalMemCache (`:LocalMemCache`)
    * Memcached store (`:Memcached`, `:MemcachedNative` and `:MemcachedDalli`)
    * Daybreak database (`:Daybreak`)
* Relational Databases:
    * DataMapper (`:DataMapper`)
    * ActiveRecord (`:ActiveRecord`)
    * Sequel (`:Sequel`)
    * Sqlite3 (`:Sqlite`)
* Filesystem:
    * PStore (`:PStore`)
    * YAML store (`:YAML`)
    * Filesystem directory store (`:File`)
    * Filesystem directory store which spreads files in subdirectories using md5 hash (`:HashFile`)
* Key/value databases:
    * Berkeley DB (`:DBM`)
    * Cassandra (`:Cassandra`)
    * Daybreak (`:Daybreak`)
    * GDBM (`:GDBM`)
    * HBase (`:HBase`)
    * LevelDB (`:LevelDB`)
    * Redis (`:Redis`)
    * Riak (`:Riak`)
    * SDBM (`:SDBM`)
    * TokyoCabinet (`:TokyoCabinet`)
    * Simple Samba database TDB (`:TDB`)
* Document databases:
    * CouchDB (`:Couch`)
    * MongoDB (`:Mongo`)
* Moneta network protocols:
    * Moneta key/value client (`:Client` works with `Moneta::Server`)
    * Moneta HTTP/REST client (`:RestClient` works with `Rack::MonetaRest`)
* Other
    * Fog cloud storage which supports Amazon S3, Rackspace, etc. (`:Fog`)
    * Storage which doesn't store anything (`:Null`)

Some of the backends are not exactly based on key/value stores, e.g. the relational ones. These
are useful if you already use the corresponding backend in your application. You get a key/value
store for free then without installing any additional services and you still have the possibility
to upgrade to a real key/value store.

### Backend feature matrix

<table>
<thead style="font-weight:bold"><tr><th>Adapter</th><th>Required gems</th><th>Multi-thread safe<sup>[1]</sup></th><th>Multi-process safe<sup>[2]</sup></th><th>Atomic increment</th><th>Native expires<sup>[3]</sup></th><th>Persistent</th><th>Description</th></tr></thead>
<tbody>
<tr><td>ActiveRecord</td><td>active_record</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:green">✓</td><td>ActiveRecord ORM</td></tr>
<tr><td>Cassandra</td><td>cassandra</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Cassandra distributed database</td></tr>
<tr><td>Client</td><td>-</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Depends on server</td><td>Depends on server</td><td>Depends on server</td><td>Moneta client adapter</td></tr>
<tr><td>Cookie</td><td>-</td><td style="color:red">✗</td><td>Memory</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td>Cookie in memory store</td></tr>
<tr><td>Couch</td><td>couchrest</td><td style="color:blue">?</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:red">✗</td><td style="color:green">✓</td><td>CouchDB database</td></tr>
<tr><td>DataMapper</td><td>dm-core, dm-migrations</td><td style="color:green">✓</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:red">✗</td><td style="color:green">✓</td><td>DataMapper ORM</td></tr>
<tr><td>Daybreak</td><td>daybreak</td><td style="color:blue">?</td><td style="color:red">✗</td><td style="color:green">✓</td><td style="color:red">✗</td><td style="color:green">✓</td><td>Daybreak ruby key/value store</td></tr>
{'fraction_non_alphanumeric': 0.1970599181243022, 'fraction_numerical': 0.0011164867882396724, 'mean_word_length': 5.6025798525798525, 'pattern_counts': {'":': 0, '<': 319, '<?xml version=': 0, '>': 323, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3535759', 'n_tokens_mistral': 3793, 'n_tokens_neox': 3658, 'n_words': 798}