An open API service indexing awesome lists of open source software.

https://github.com/makevoid/redismapper

Basic ORM for Redis key/value store - ruby/redis project of mine done in 2009
https://github.com/makevoid/redismapper

Last synced: 9 months ago
JSON representation

Basic ORM for Redis key/value store - ruby/redis project of mine done in 2009

Awesome Lists containing this project

README

          

= RedisMapper

== a basic ORM for Redis key/value store

by: @makevoid
commits time range: Nov-Dec, 2009
language: Ruby

== 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):
[#, #, #]

users (2):
[#, #]

find an user:
#