Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

bsm/redpear

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redpear

<img src=“https://travis-ci.org/bsm/redpear.png?branch=master” alt=“Build Status” />

A simple, elegant & efficient ORM for Redis, optimised for speed!

Redis is a simple key/value store, hence storing structured data can be a challenge. Redpear allows you to store/find/associate “records” in a Redis DB very efficiently, minimising IO operations and storage space where possible.

Examples

class Post < Redpear::Model
  column :title
  column :body
end

class Comment < Redpear::Model
  column :body
  index :post_id
end

Let’s create a post and a comment:

post = Post.new :title => "Hi!", :body => "I'm a new post"
post.id # => 100, automatically persisted
comment = Comment.new :post_id => post.id, :body => "I like this!"
comment.id # => 200

Now let’s find and update a Comment:

comment = Comment.find 200
comment.body = "This is fun!"

Under the hood:

Redis.current.keys
# => [ "posts:[~]",   # => Set { 1 } - stores the primary keys of all posts
#      "posts:[+]",   # => Counter value: "100" - stores last primary key value
#      "posts:100",   # => Hash { title: "Hi!", body: "I'm a new post" }
#      "comments:[~]" # => Set, as above, just for comments
#      "comments:[+]" # => Counter, as above, just for comments
#      "comments:200" # => Hash { post_id: 100, body: "I like this!" }
#      "comments:[post_id]:100" # => Set { 200 } - lookup for comments that
#                               # belong to post #100
#    ]

Installation

You should be familiar with gembundler.com/. Simply include redpear in your Gemfile:

gem "redpear"

You can additionally include the hiredis extension (written in C), you you want to make use of it:

gem "hiredis", "~> 0.3.1"
gem "redis", "~> 2.2.0", :require => ["redis/connection/hiredis", "redis"]

Please see github.com/pietern/hiredis-rb for more details.

Highlights

Redpear is VERY lightweight. Compared with other ORMs, it offers raw speed at the expense of convenience.

  • Uses the latest Redis features

  • Minimises number of IO operations

  • Minimises storage space (memory)

  • Thread-safe

  • “Lazy” where possible/reasonable

LICENSE

Copyright (c) 2011-2013 Black Square Media

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A simple, elegant & efficient ORM for Redis, optimised for speed!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages