add sample
Sho Hashimoto [Sun, 4 Jul 2010 13:33:46 +0000 (22:33 +0900)]
samples/with_yaml/Rakefile [new file with mode: 0644]
samples/with_yaml/config.yaml [new file with mode: 0644]
samples/with_yaml/tokyotyrant-read-write.rb [new file with mode: 0644]

diff --git a/samples/with_yaml/Rakefile b/samples/with_yaml/Rakefile
new file mode 100644 (file)
index 0000000..bc5836b
--- /dev/null
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'yaml'
+#require 'shinagawaseaside'
+require '../..//lib/shinagawaseaside'
+
+begin
+  conf = YAML::load open(File.dirname(__FILE__)+'/config.yaml')
+rescue
+  STDERR.puts 'config.yaml load error'
+  exit 1
+end
+
+ShinagawaSeaside::set_tasks(conf['ttdb'], :basedir => File.dirname(__FILE__)+'/ttdb')
diff --git a/samples/with_yaml/config.yaml b/samples/with_yaml/config.yaml
new file mode 100644 (file)
index 0000000..efc2c88
--- /dev/null
@@ -0,0 +1,7 @@
+
+ttdb : 
+     - name : users
+       port : 23240
+     - name : videos
+       port : 23241
+
diff --git a/samples/with_yaml/tokyotyrant-read-write.rb b/samples/with_yaml/tokyotyrant-read-write.rb
new file mode 100644 (file)
index 0000000..f7a05c4
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/ruby
+# -*- coding: utf-8 -*-
+require 'rubygems'
+require 'tokyotyrant'
+include TokyoTyrant
+require 'yaml'
+
+begin
+  conf = YAML::load open(File.dirname(__FILE__)+'/config.yaml')
+rescue
+  STDERR.puts 'config.yaml load error'
+  exit 1
+end
+
+dbs = Hash.new
+conf['ttdb'].each{|db|
+  puts "open #{db['name']}"
+  rdb = RDB::new
+  if !rdb.open('127.0.0.1', db['port'].to_i)
+    STDERR.puts 'error - tokyotyrant : '+rdb.errmsg(rdb.ecode)
+    exit 1
+  else
+    dbs[db['name'].to_sym] = rdb
+  end
+}
+
+dbs[:users][1] = 'shokai'
+dbs[:users][2] = 'hashimoto'
+
+puts dbs[:users][1]
+
+dbs[:users].keys.sort.each{|k|
+  puts "#{k} => #{dbs[:users][k]}"
+}
+
+
+
+for i in 0...10 do
+  dbs[:videos][i] = "#{rand(100)}.mov"
+end
+
+dbs[:videos].keys.sort.each{|k|
+  puts "#{k} => #{dbs[:videos][k]}"
+}
+
+
+dbs.each{|name,rdb|
+  puts "close #{name}"
+  if !rdb.close
+    STDERR.puts 'error - tokyotyrant : '+rdb.errmsg(rdb.ecode)
+  end
+}
+