Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A DataMapper adapter for redis
Ruby
Branch: master
Pull request Compare This branch is 151 commits behind whoahbot:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
benchmark
lib
spec
MIT-LICENSE
README.textile
Rakefile
dm-redis-adapter.gemspec

README.textile

dm-redis-adapter

This is a DataMapper adapter for the Redis key-value database.

Redis is a very fast key-value store with some interesting data structures added. You can have a key that is a SET, LIST, or a STRING 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: redis. Redis is also a persistent data store, and can be used in large-scale environments with master-slave replication.

DataMapper is a brilliant ORM that is based on the IdentityMap 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.

Install

Prerequisites:

I installed the redis gem from the redis .tgz file like so:

  
    > tar -xvzf redis-0.100.tar.gz
    > cd redis-0.100/client-libraries/ruby
    > sudo rake install
  

Usage

Setup your adapter, define your models and properties:

  
    require 'rubygems'
    require 'dm-core'
    require 'dm_redis'
    
    DataMapper.setup(:default, {:adapter  => "redis"})
    
    class Cafe
      include DataMapper::Resource
      
      property :id,     Serial
      property :name,   Text
    end
    
    Cafe.create(:name => "Whoahbot's Caffienitorium")
  

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

Something went wrong with that request. Please try again.