Skip to content

Commit

Permalink
Fix link walking, thanks to advice.
Browse files Browse the repository at this point in the history
  • Loading branch information
lstoll committed Feb 17, 2010
1 parent a8ba231 commit 580c244
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions 2_link_basics.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
####
# NOT CURRENTLY WORKING - RIAK IS THROWING A 500 ON THE QUERY
# Running the 'same' by hand (e.g)
# curl http://127.0.0.1:8098/raw/test1/852120fe1b2f11df7b81f9cd003fb038/test1,parent,1
# Is working
###


require 'riak'
require 'uuid'

Expand All @@ -15,35 +7,31 @@ def gen_id

# Connect and get a bucket instance
client = Riak::Client.new
bucket = client.bucket("test1")
bucket = client.bucket("test2")

# Ensure bucket is empty. When bugfixed, pass block direct to bucket
bucket.keys.each {|k| bucket.get(k).delete}

# Create and save a simple JSON object
new_one = Riak::RObject.new(bucket, gen_id)
new_one = Riak::RObject.new(bucket, "item1")
new_one.content_type = "application/json" # You must set the content type.
new_one.data = "{'item': 'one'}"
new_one.store

# Create and save a second JSON object, linking to the first
new_two = Riak::RObject.new(bucket, gen_id)
new_two = Riak::RObject.new(bucket, "item2")
new_two.content_type = "application/json" # You must set the content type.
new_two.data = "{'item': 'two'}"
# Linking. Must be a better way to create the URL?. Link is tagged parent
new_two.links << Riak::Link.new("/raw/#{bucket.name}/#{new_two.key}", "parent")
new_two.links << new_one.to_link("parent")
new_two.store

# Walk the link. We start the walk from new_two, and limit the walk to the current
# bucket, and traverse links tagged parent. The last item on the list needs
# keep => true, to return the results
mr = Riak::MapReduce.new(client).add("test1", new_two.key).link(:bucket => 'test1',
:tag => 'parent', :keep => true)
puts "** Query JSON ***"
puts mr.to_json
puts "*** Results of link query ***"
p mr.run
p "** Walk the Parent Link **"
p new_two.walk(:tag => 'parent')

keys = bucket.keys
keys = bucket.keys(:reload => true)

puts "*** All items in bucket ***"
keys.each {|k| p bucket.get(k)}
keys.each {|k| bucket.get(k).delete}
bucket.keys.each {|k| i = bucket.get(k) ; p i ; p i.links}
#bucket.keys.each {|k| bucket.get(k).delete}

0 comments on commit 580c244

Please sign in to comment.