From: Sho Hashimoto Date: Sun, 4 Jul 2010 13:33:46 +0000 (+0900) Subject: add sample X-Git-Url: http://shokai.org/projects/git/?a=commitdiff_plain;h=c729303f48c033bca5411d4dc977ba3e5d3e2d06;p=shinagawaseaside%2F.git add sample --- diff --git a/samples/with_yaml/Rakefile b/samples/with_yaml/Rakefile new file mode 100644 index 0000000..bc5836b --- /dev/null +++ b/samples/with_yaml/Rakefile @@ -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 index 0000000..efc2c88 --- /dev/null +++ b/samples/with_yaml/config.yaml @@ -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 index 0000000..f7a05c4 --- /dev/null +++ b/samples/with_yaml/tokyotyrant-read-write.rb @@ -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 +} +