Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ActiveKai - Rails plugin for Kai.
Ruby
Branch: master
Pull request Compare This branch is 8 commits behind sawamur:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tasks
test
MIT-LICENSE
README
Rakefile
init.rb
install.rb
uninstall.rb

README

ActiveKai
=========

Rails Plugin for Kai ( http://sourceforge.net/projects/kai/ )


Example
=======

You can write model class inheriting from ActiveKai.

 class Book < ActiveKai
   kai_servers ['192.168.10.1:11211','192.168.10.2:11211','192.168.10.3:11211']
 end

 book = Book.new(:id => 12345,:title => "Learning Erlang",:author => "John")
 puts book.author #=> john
 book.save 
 # The key on Kai is generated by :id parameter.

 b2 = Book.find(12345)
 b2.title = "Learning Erlang 2nd Ed."
 b2.save
 
 p b2.key #=> "your_app.Book.development/112345" 


DESCRIPTION
===========
You can read/write any data on Kai with ActiveRecord-like style.Notice that
Kai is key-value storage,so you have to specify key by some means.Now,this plugin 
generates key string from :id parameter.

The key is a string made from :id,class name,namespace (defailt:base directory name) 
and RAILS_ENV,so you can use string value on :id as well.If you want to see exact 
key string,call #key method on the object.

INSTALL
=======

 script/plugin install git://github.com/sawamur/active_kai.git


CONFIGURATION
=============

KAI HOSTS
---------

You can specify hosts and ports as follows.

1.In a enviroments/(development|test|production).rb
 
 ActiveKai.servers = ['192.168.10.1:11211','192.168.10.2:11211','192.168.10.3:11211']

2.In a subclass

 class Book < ActiveKai
   kai_servers ['192.168.10.1:11211','192.168.10.2:11211','192.168.10.3:11211']
 end

Notice that server setting is shared in all subclass in a application.So the way 1 
is preferable.


KEY PREFIX
----------

 class Book < ActiveKai
    kai_key_prefix "MyBook"
 end

 b = Book.new(:id => "great_book",:name => "john")
 puts  b.key #=> "MyBook/great_book"

KEY INDEX
---------

 class Book < ActiveKai
    kai_key_index :name
 end
 b = Book.new(:name => "john",:title => "bar foo")
 puts b.key #=> "yourapp.Book.development/john"

KEY NAMEPSACE
-------------

You can specify a namespace of each key.Write as follows on enviroment.rb (or 
config/enviroment/development.rb etc)

 ActiveKai.namespace = "com.yourdomain.yourapp"

That namespace will be shared ALL subclass of ActiveKai.So if you set as shown
above extact key will be;
  
 class City < ActiveKai
 end
 # if you run this code on production environment
 tokyo = City.new(:id => 8,:name => "tokyo",:contry => "japan")
 p tokyo.key #=> "com.yourdomain.yourapp.City.production/8"


MIGRATIONS?
===========

Kai is not a RDB.It has no schema in value data.So you don't have migrate first.
You can set any properties when you create object.
  
 class Drink < ActiveKai
 end 

 beer = Drink.new(:id => 1,:name => "Foo Beer",:company => "Kirin",:made_in => "japan")
 p beer.made_in #=> "japan"
 wine1 = Drink.new(:id => 2,:made_in => "France",:region => "bordeaux",:color => "red")
 p wine1.region #=> "bordeaux"
 wine2 = Drink.new(:id => 3,:some_param => [1,3,4,5],:bar_foo => { :aaa => 1,:bbb => 2} )
 p wine2.some_param.size #=> 4


ABOUT KAI
=========

Kai ( http://sourceforge.net/projects/kai/ ) is a key-value storage,you can read/write
data via memcache protocol.

VERSION
=======

version 0.1.0 


Copyright (c) 2009 Masaki Sawamura, released under the MIT license
Something went wrong with that request. Please try again.