What is this?
It is a Riak ruby client design for eventmachine.
Concept
I tried to implement em-riak with goals : Easy to use, ORM, Fast, Flexible, Hybrid.
Easy To use (ToDo)
I tried to use the same behaviors as active-record or sequel.
So when you use em-riak, you don't tackling the "Key Design".
Instead, just add an extension into your model, and everygthings goes fine.
ORM (ToDo)
The same idea as upon, just add the plugins and you gain the ORM ability with NoSQL.
It only support Sequel gem currently.
Flexible
Concurrency is one reasons to use nosql, we may face huge read / write in the same time but our sql hard to scale.
Riak provide easy to use script that you can install, add nodes easily.
Also, you can read/write data directly, or deferrable-aware.
With Deferrable-aware, you don't block & wait for your I/O.
Getting Start
EmRiak::Connection.new({:bucket=>"member",:async=>false,:hosts=>["http://127.0.0.1:8091"]})
member=EmRiak.create("member1",{:name=>"Von",:age=>18})
member.handsome=true # or EmRaik.udpate("member1",{:handsome=>true})
member.save # or EmRiak.save("member1")
member.destory
member_two=EmRiak.create("member2",{:name=>"Jack",:age=>22})
member_two.add_tag(:interests,"programmer","backpacker","trader")
member_three=EmRiak.create("member3",{:name=>"Lisa",:age=>17})
member_three.add_tag(:interests,"backpacker","delicious","cocktail","movie")
member_three.remove_tag(:interest,"delicious")
EmRiak.search(:secondary_index, {:bin=>:interests}, "delicious") #=> {}
EmRiak.search(:secondary_index, {:bin=>:interests}, "movie") #=> {:member=>["member3"]}
EmRiak.search(:secondary_index, {:bin=>:interests}, "backpacker") #=> same above
EmRiak.search(:secondary_index, {:bin=>:interests}, "backpacker","movie") #=> {:member=>["member2","member3"]}
EmRiak::Util.clean_bucket("member") #=> Clean all the data inside bucket
Work with Async
With asynchornize, you just set following at anywhere :
EmRiak.async=true
And the code behind will become asynchornize.
You can also do dependent async call like following :
EmRiak.find("xxx",values){ callback_proc_here }
EmRiak.create("xxx",values){ callback_proc_here }
EmRiak.delete("xxx",values){ callback_proc_here }
EmRiak.search(:search_mode,{:callback=>callback_proc_here},search_conditions)
# or
EmRiak.search(:search_mode,{options},search_conditions){ your_call_back }
Hybrid is also possible :
EmRiak.create("member5",{:name=>"5",:created_at=>Time.now}){|result| # Async req
EmRiak.find("member5"){|member| # Async req
EmRiak.destroy(member.riak_key){|result| # Async req
EmRiak.create("member5",{:name=>"5",:created_at=>Time.now,:new=>true}) # Direct req
member=EmRiak.find("member5") # Direct req
}
}
}
Some options for your convenient
Here provide some options that can do with each seperate request
Format
EmRiak.your_riak_action(key_name,,values)
Example
EmRiak.create("member5",{:replication=>{:n_val=>3}},{:name=>"HandsomeGuy"})
Available Options
- :bucket=>String
- :replication=>Hash
- :vclock=>String
- :sibling=>String
- :content_type=>String
- :etag=>String
- :last_modified=>String
- :returnbody=>true/false (alias return_body)
I know there are some more, but I currently need only these on my project.
So if you would like more options to deal with data, hack it or let me know.
Write some map-reduce
Use it directly as following :
EmRiak::MapReduce.submit({
"inputs" => {"bucket"=> "member","index"=> "123", "key"=>["member1","member2","member3"]},
"query" => [{"map"=> {"language"=> "erlang", "module"=>"riak_kv_mapreduce", "function"=>""} },
{"reduce"=> {"language"=> "erlang", "module"=>"riak_kv_mapreduce", "function"=>"reduce_identity", "keep"=>true} }
]})
Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
TO-DO
Full Text Seacrh (This will not going to implement because Basho will replace search with yakozuna)
Deployment & Management
ORM with Model