Basic ORM for Redis key/value store - ruby/redis project of mine done in 2009
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
spec
Manifest
README.rdoc
TODO
init.rb
rakefile

README.rdoc

RedisMapper

a basic ORM for Redis key/value store

by: @makevoid
commits time range:  Nov-Dec, 2009
language: Ruby
implemented in: Milan
# new idea, call oracle  
#
# degrees_c: oracle.call(temperatures) => returns (and thus you can safely display) # TODO: create a new repo called temperature_oracle

install dependencies

gem sources --add http://gems.github.com
gem install ezmobius-redis-rb

gem install it (gemcutter way)

gem install gemcutter
gem tumble
gem install redismapper

an example

create some models

## models.rb 
class Message < RedisMapper
  property :title, :index => true   # enables Message.find
  property :text
  property :user_id                 # connects it to User (atm it doesn't support model's associations via methods but it will be added soon)
end

class User < RedisMapper
  property :name, :index => true
end

your mainfile (?.rb)

require 'rubygems'
require File.expand_path(File.dirname(__FILE__)) + '/../lib/redismapper'

# setup
RedisMapper.setup(Redis.new :db => 14)
@r = RedisMapper.db

# load your models
require 'models'

# clean db
RedisMapper.delete_db

# insert
u = User.create(:name => "makevoid")
Message.create(:title => "Hello!", :text => "Welcome in the world of redismapper...", :user_id => u.id)
u = User.create(:name => "me")
Message.create(:title => "Hello!", :text => "bla bla...", :user_id => u.id)
Message.create(:title => "Hey", :text => "bla bla..", :user_id => u.id)

# read
puts "messages (#{Message.count}):"
p Message.all
# Message.all(:select => :title) # faster, fetches only the title
puts

puts "users (#{User.count}):"
p User.all
puts

puts "find an user:"
p User.first(:name => "me")

output:

messages (3):
[#<Message:0x1019c2410 @text="Welcome in the world of redismapper...", @title="Hello!", @id=1, @user_id="1">, #<Message:0x1019c1268 @text="bla bla...", @title="Hello!", @id=2, @user_id="2">, #<Message:0x1019c00c0 @text="bla bla..", @title="Hey", @id=3, @user_id="2">]

users (2):
[#<User:0x1019be590 @name="makevoid", @id=1>, #<User:0x1019bdd48 @name="me", @id=2>]

find an user:
#<User:0x1019bd1b8 @name="me", @id=2>