Skip to content
remodel -- a minimal ORM (object-redis-mapper) in less than 300 lines of ruby
Find file
Pull request Compare This branch is 74 commits behind tlossen:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin
docs
example
lib
test
.gitignore
LICENSE
README.md
Rakefile
VERSION
remodel.gemspec

README.md

remodel your storage layer

use redis instead of mysql to store your application data.

remodel (= redis model) is an ActiveRecord-like mapping layer which offers familiar syntax like has_many, has_one etc. to build your domain model in ruby.

why redis?

redis offers in-memory read and write performance — on the order of 10K to 100K operations per second, comparable to memcached — plus asynchronous persistence to disk. for example, on my macbook (2 ghz):

$ redis-benchmark -d 100 -r 10000 -q
SET: 13864.27 requests per second
GET: 18152.17 requests per second
INCR: 17006.80 requests per second
LPUSH: 17243.99 requests per second
LPOP: 18706.54 requests per second

how to get started

  1. install redis and ezras excellent redis-rb ruby client:

    $ brew install redis
    $ gem install redis
    
  2. install the super-fast yajl json parser plus ruby bindings:

    $ brew install yajl
    $ gem install yajl-ruby
    
  3. start redis:

    $ redis-server
    
  4. now the tests should run successfully:

    $ rake
    Started
    .................................................................
    Finished in 0.063041 seconds.
    65 tests, 103 assertions, 0 failures, 0 errors
    

example

define your domain model like this:

class Book < Remodel::Entity
  has_many :chapters, :class => 'Chapter', :reverse => :book
  property :title, :class => 'String'
  property :year, :class => 'Integer'
end

class Chapter < Remodel::Entity
  has_one :book, :class => Book, :reverse => :chapters
  property :title, :class => String
end

now you can do:

>> require 'example/book'
=> true
>> book = Book.create :title => 'Moby Dick', :year => 1851
=> #<Book(b:3) title: "Moby Dick", year: 1851>
>> chapter = book.chapters.create :title => 'Ishmael'
=> #<Chapter(c:4) title: "Ishmael">
>> chapter.book
=> #<Book(b:3) title: "Moby Dick", year: 1851>

inspired by

  • how to redis — good overview of different mapping options by mattmatt.
  • hurl — basically i started with defunkts Hurl::Model.
  • ohm — object-hash mapping for redis. somewhat similar, but instead of serializing to json, stores each attribute under a separate key.

todo

  • documentation (rocco)
  • benchmarks
  • delete
  • find_by

status

alpha. play around at your own risk :)

license

MIT, baby!

Something went wrong with that request. Please try again.