Skip to content

Instantly share code, notes, and snippets.

@flazz
Created July 7, 2011 18:30
Show Gist options
  • Save flazz/1070195 to your computer and use it in GitHub Desktop.
Save flazz/1070195 to your computer and use it in GitHub Desktop.
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