<commit_before>h1. dm-redis-adapter

This is a <a href="http://datamapper.org">DataMapper</a> adapter for the <a href="http://redis.io/">Redis</a> key-value store.

Redis is a very fast key-value store with some interesting data structures added, and oh so much more. You can have a key that is a SET, LIST, STRING or HASH that is binary safe. Data structures like SET and LIST allow for even more interesting things. Redis is a fabulous and fast engine for data structures, and you can read more about it here: <a href="http://code.google.com/p/redis/">redis</a>. Redis is also a persistent data store, and can be used in large-scale environments with master-slave replication and consistent hashing on the client side. Redis makes everyone happy and has been known to cause sunshine to spontaneously break out in clouded areas.

<a href="http://datamapper.org">DataMapper</a> is a brilliant ORM that is based on the <a href="http://www.martinfowler.com/eaaCatalog/identityMap.html">IdentityMap</a> pattern.  Usage of DataMapper resembles that of ActiveRecord, the popular ORM bundled with Ruby on Rails, but with some very important differences. A quote from the DM wiki: "One row in the database should equal one object reference. Pretty simple idea. Pretty profound impact." Having an identity map allows for very efficient queries to the database, as well as interesting forms of lazy loading of attributes or associations.

Marrying DataMapper to Redis allows for schema-less models, you can add fields at any time without having to create a migration.  DataMapper also allows us to store non-native Redis types in the db, like Date fields.

h1. Changelog

* v0.4.0  Support for dm-core v1.1.0
* v0.3.0  Updates to support ruby 1.9.2 (thanks arbarlow!)
* v0.2.1  Fixes to sorting
* v0.1.1  Update to redis-rb v2.0.0
* v0.1    Update to store records as redis hash values
* v0.0.11 Updates to support newer versions of the redis client, support for JSON datatypes

h1. Install

Prerequisites:
* Redis:
** <a href="http://code.google.com/p/redis/">Redis, v2.2 series</a>

Install the dm-redis adapter:
<pre>
  <code>
    > gem install dm-redis-adapter
  </code>
</pre>

h1. Usage

Setup your adapter, define your models and properties:

<pre>
  <code>
    require 'rubygems'
    require 'dm-core'
    require 'dm-redis-adapter'

    DataMapper.setup(:default, {:adapter  => "redis"})

    class Cafe
      include DataMapper::Resource

      property :id,     Serial
      property :name,   Text
    end

    Cafe.create(:name => "Whoahbot's Caffienitorium")
  </code>
</pre>

Now you can use redis in a ORM style, and take advantage of all of the amazing things that DataMapper offers.

If you want to do finds on specific String fields, add an index:

<pre>
  <code>
    class Coffee
      include DataMapper::Resource

      property :id,            Serial
      property :description,   String, :index => true
    end

    Coffee.create(:description => "Notes of crude oil and sulphur")
    Coffee.first(:description => "Notes of crude oil and sulphur") # will now work
  </code><commit_msg>Make the example complete by adding a finalize call.<commit_after>h1. dm-redis-adapter

This is a <a href="http://datamapper.org">DataMapper</a> adapter for the <a href="http://redis.io/">Redis</a> key-value store.

Redis is a very fast key-value store with some interesting data structures added, and oh so much more. You can have a key that is a SET, LIST, STRING or HASH that is binary safe. Data structures like SET and LIST allow for even more interesting things. Redis is a fabulous and fast engine for data structures, and you can read more about it here: <a href="http://code.google.com/p/redis/">redis</a>. Redis is also a persistent data store, and can be used in large-scale environments with master-slave replication and consistent hashing on the client side. Redis makes everyone happy and has been known to cause sunshine to spontaneously break out in clouded areas.

<a href="http://datamapper.org">DataMapper</a> is a brilliant ORM that is based on the <a href="http://www.martinfowler.com/eaaCatalog/identityMap.html">IdentityMap</a> pattern.  Usage of DataMapper resembles that of ActiveRecord, the popular ORM bundled with Ruby on Rails, but with some very important differences. A quote from the DM wiki: "One row in the database should equal one object reference. Pretty simple idea. Pretty profound impact." Having an identity map allows for very efficient queries to the database, as well as interesting forms of lazy loading of attributes or associations.

Marrying DataMapper to Redis allows for schema-less models, you can add fields at any time without having to create a migration.  DataMapper also allows us to store non-native Redis types in the db, like Date fields.

h1. Changelog

* v0.4.0  Support for dm-core v1.1.0
* v0.3.0  Updates to support ruby 1.9.2 (thanks arbarlow!)
* v0.2.1  Fixes to sorting
* v0.1.1  Update to redis-rb v2.0.0
* v0.1    Update to store records as redis hash values
* v0.0.11 Updates to support newer versions of the redis client, support for JSON datatypes

h1. Install

Prerequisites:
* Redis:
** <a href="http://code.google.com/p/redis/">Redis, v2.2 series</a>

Install the dm-redis adapter:
<pre>
  <code>
    > gem install dm-redis-adapter
  </code>
</pre>

h1. Usage

Setup your adapter, define your models and properties:

<pre>
  <code>
    require 'rubygems'
    require 'dm-core'
    require 'dm-redis-adapter'

    DataMapper.setup(:default, {:adapter  => "redis"})

    class Cafe
      include DataMapper::Resource

      property :id,     Serial
      property :name,   Text
    end

    Cafe.finalize

    Cafe.create(:name => "Whoahbot's Caffienitorium")
  </code>
</pre>

Now you can use redis in a ORM style, and take advantage of all of the amazing things that DataMapper offers.

If you want to do finds on specific String fields, add an index:

<pre>
  <code>
    class Coffee
      include DataMapper::Resource

      property :id,            Serial
      property :description,   String, :index => true
    end

    Coffee.create(:description => "Notes of crude oil and sulphur")
    Coffee.first(:description => "Notes of crude oil and sulphur") # will now work
  </code>
{'fraction_non_alphanumeric': 0.08535805626598465, 'fraction_numerical': 0.010549872122762148, 'mean_word_length': 3.6109064112011793, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6763099', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1809, 'n_words': 828}