Basic ORM for Redis key/value store - ruby/redis project of mine done in 2009
Latest commit 63ea5c7 Jul 10, 2016 @makevoid committed on GitHub Update README.rdoc



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: => returns (and thus you can safely display) # TODO: create a new repo called temperature_oracle

install dependencies

gem sources --add
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)

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

your mainfile (?.rb)

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

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

# load your models
require 'models'

# clean db

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

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

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

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


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>