Created
July 7, 2011 18:30
-
-
Save flazz/1070195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'riak' | |
require 'json' | |
require 'benchmark' | |
require 'pp' | |
$client = Riak::Client.new :protocol => :pbc | |
def keys_in_range | |
mr = Riak::MapReduce.new($client). | |
add("events"). | |
map(<<-MAP, :keep => true) | |
function(v) { | |
var data = Riak.mapValuesJson(v)[0] | |
var epoch_ms = parseInt(data.created_at); | |
var end = 1310135095305; | |
var start = end - 86400000; | |
if (start < epoch_ms && epoch_ms < end) { | |
return [v.key]; | |
} else { | |
return []; | |
} | |
} | |
MAP | |
results = mr.run | |
puts results | |
end | |
puts Benchmark.measure { keys_in_range } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment