Permalink
Browse files

Refactor utils, add some more tips.

  • Loading branch information...
lstoll committed Feb 17, 2010
1 parent 71cd318 commit 45dc1ca7feee4bef11c5ff30731dc49971f3e68b
Showing with 40 additions and 18 deletions.
  1. +3 −7 1_ripple_basics.rb
  2. +1 −5 2_link_basics.rb
  3. +1 −6 3_map_basics.rb
  4. +23 −0 TIPS.md
  5. +12 −0 lib/utils.rb
  6. 0 { → lib}/uuid.rb
View
@@ -1,9 +1,5 @@
require 'riak'
-require 'uuid'
-
-def gen_id
- UUID.create.to_s.gsub('-','')
-end
+require 'lib/utils'
# Connect and get a bucket instance
client = Riak::Client.new
@@ -13,13 +9,13 @@ def gen_id
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, gen_uuid)
new_one.content_type = "application/json" # You must set the content type.
new_one.data = "{'item': 'one'}"
new_one.store
# Create and save a simple JSON object
-new_two = Riak::RObject.new(bucket, gen_id)
+new_two = Riak::RObject.new(bucket, gen_uuid)
new_two.content_type = "application/json" # You must set the content type.
new_two.data = "{'item': 'two'}"
new_two.store
View
@@ -1,9 +1,5 @@
require 'riak'
-require 'uuid'
-
-def gen_id
- UUID.create.to_s.gsub('-','')
-end
+require 'lib/utils'
# Connect and get a bucket instance
client = Riak::Client.new
View
@@ -1,9 +1,5 @@
require 'riak'
-require 'uuid'
-
-def gen_id
- UUID.create.to_s.gsub('-','')
-end
+require 'lib/utils'
# Connect and get a bucket instance
client = Riak::Client.new
@@ -29,7 +25,6 @@ def gen_id
puts "*** Simple Query ***"
p Riak::MapReduce.new(client).
add(bucket.name). # run on all items in bucket
- # next line is same as map("Riak.mapValuesJson", :keep => true)
map("function(v) {
// Load the items data, and parse it
obj = JSON.parse(v.values[0].data);
View
23 TIPS.md
@@ -12,3 +12,26 @@ If you want to have multiple map phases, the first map phase should return [buck
Then enter the query json, return, ^D
+== Connect an erlang process
+
+ # replace linc with your machines hostname
+ /usr/local/Cellar/riak/0.8/erts-5.7.4/bin/erl -setcookie riak -name linc@127.0.0.1
+ Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]
+
+ Eshell V5.7.4 (abort with ^G)
+ (linc@127.0.0.1)1> RiakNode = riak_util:str_to_node(riak).
+ 'riak@127.0.0.1'
+ (linc@127.0.0.1)2> net_adm:ping(RiakNode).
+ pong
+ (linc@127.0.0.1)3> {ok, C} = riak:client_connect(RiakNode).
+ {ok,{riak_client,'riak@127.0.0.1',<<7,217,74,71>>}}
+
+== Bulk delete from an erlang process
+
+This can probably be done more effiecently with key streaming. Look into mapred_bucket
+
+ linc@127.0.0.1)4> {ok, Keys} = C:list_keys(<<"test5">>),
+ (linc@127.0.0.1)4> lists:map(fun(Key)->
+ (linc@127.0.0.1)4> C:delete(Name, Key, 1)
+ (linc@127.0.0.1)4> end, Keys).
+
View
@@ -0,0 +1,12 @@
+ROOT_DIR = ::File.expand_path(::File.join(::File.dirname(__FILE__), ".."))
+require ROOT_DIR + "/lib/uuid"
+
+def time(name="Method")
+ start = Time.now
+ yield
+ puts "#{name} execution time: #{Time.now - start}"
+end
+
+def gen_uuid
+ UUID.create.to_s.gsub('-','')
+end
View
File renamed without changes.

0 comments on commit 45dc1ca

Please sign in to comment.