Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'riak'
- require 'json'
- require 'benchmark'
- require 'pp'
- $client = Riak::Client.new :protocol => :pbc
- def latest_10_via_values
- mr = Riak::MapReduce.new($client).
- add("events").
- map(<<-MAP).
- function(v) {
- var data = Riak.mapValuesJson(v)[0]
- var epoch_ms = parseInt(data.created_at, 16);
- return [ { time : epoch_ms, key : v.key } ];
- }
- MAP
- reduce(<<-REDUCE, :keep => true)
- function(vs) {
- var vs_sorted = vs.sort(function(a,b){ return b.time - a.time; });
- return vs_sorted.slice(0,10);
- }
- REDUCE
- results = mr.run
- puts results
- end
- puts Benchmark.measure { latest_10_via_values }
Add Comment
Please, Sign In to add comment