Project

redpear

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Simple, elegant & efficient ORM for Redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0.5
 Project Readme

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.