Project

kvbean

0.0
No commit activity in last 3 years
No release in over 3 years
Make redis on rails life easier
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

~> 3.2.3
~> 2.2.2
 Project Readme

Kvbean

Make redis on rails life easier

Install

put this code in Gemfile

gem 'kvbean'

Usage

class Message
  include Kvbean::Base

  kv_field :content, :title
end

Message.create(title: 'i am title', content: 'i am content')

Message.find_by_title('i am title')
Message.find_all_by_title('i am title')

message = Message.find_or_create_by_title('i am title')

message.id # => 7b4cfa9a1426b5fad5c8cd17aa
message.exists? # => true, alias: persisted?, !new_record?
message.new_record? # => false
message.created_at # => Tue, 08 May 2012 09:54:20 UTC +00:00
message.updated_at # => Tue, 08 May 2012 09:54:20 UTC +00:00
message.update_attributes(title: 'new title')
message.title # => new title
Message.count # => 1

Message.first
Message.last

message.destroy
Message.destroy_all

message = Message.new(title: 'i am title', content: 'i am content')
message.save

Callbacks

class Message
  include Kvbean::Base

  kv_field :content, :title

  before_create :set_content

  private

  def set_content
    self.content = 'some text'
  end
end

Validations

class Message
  include Kvbean::Base

  kv_field :content, :title

  validates_presence_of :title
end

Namespace

class Message
  include Kvbean::Base

  kv_field :content, :title
  kv_namespace :ns
end

Warning: the default namespace is class's name, e.g: Message class's namespace is "message", if you have more than one app is working on redis, i think you need to care about this.