Skip to content

Instantly share code, notes, and snippets.

@bcg
Created June 27, 2011 18:25
Show Gist options
  • Save bcg/1049435 to your computer and use it in GitHub Desktop.
Save bcg/1049435 to your computer and use it in GitHub Desktop.
Trivial JSON Riak Importer
require 'riak'
@host = ARGV[0]
@port = ARGV[1].to_i
@bucket = ARGV[2]
@dir = ARGV[3]
@riak_client = Riak::Client.new(:host => @host, :http_port => @port)
@riak_bucket = @riak_client.bucket(@bucket)
Dir.glob(@dir + '/*.json') do |file_path|
json = File.read(file_path)
w_props = {
:w => 0,
:dw => 0,
:returnbody => false
}
o = @riak_bucket.new(File.basename(file_path, ".json"))
o.data = json
o.content_type = 'application/json'
o.store(w_props)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment