Last active
December 26, 2015 22:59
-
-
Save kuenishi/7226938 to your computer and use it in GitHub Desktop.
Multi-get emulation by listing keys
This file contains 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 'riak' | |
host = 'localhost' | |
port = 8087 | |
client = Riak::Client.new(:protocol => "pbc", | |
:nodes => [{:host => host, :http_port => port}]) | |
r = Riak::MapReduce.new(client) | |
.add('mybucket', 'spam') # data is foobar | |
.add('mybucket', 'ham') # data is foobar2 | |
.map(:function => [:riak_kv_mapreduce, :map_object_value], | |
:language => 'erlang', :arg => nil, :keep => true) | |
.run | |
p r | |
b = Riak::Bucket.new(client, 'mybucket') | |
r = Riak::Multiget.get_all(client, [[b, 'spam'], [b, 'ham']]) | |
p r[[b, 'spam']].content.raw_data.to_s | |
p r[[b, 'ham']].content.raw_data.to_s |
Author
kuenishi
commented
Oct 30, 2013
Thanks @kuenishi
If you want to ignore not found objects:
r = Riak::MapReduce.new(client)
.add('mybucket', 'spam') # data is foobar
.add('mybucket', 'ham') # data is foobar2
.map(:function => [:riak_kv_mapreduce, :map_object_value],
:language => 'erlang', :arg => 'filter_notfound', :keep => true)
.run
It can be useful for other 😃
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment