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.
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
-
install redis and ezras excellent redis-rb ruby client:
$ brew install redis $ gem install redis
-
start redis:
$ ./redis-server
-
now the tests should run successfully:
$ rake Started ....................................................................................... Finished in 0.072304 seconds. 87 tests, 138 assertions, 0 failures, 0 errors
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>
- how to redis — good overview of different mapping options by mattmatt.
- hurl — basically defunkts Hurl::Model is what i started with.
- ohm — object-hash mapping for redis. somewhat similar, but instead of serializing to json, stores each attribute under a separate key.
- better docs
find_by
- make serializer (json, messagepack, marshal ...) configurable
- benchmarks
still pretty alpha — play around at your own risk :)
MIT, baby!