-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTE: having problem returning only one row at search
- Loading branch information
Makoto Inoue
committed
Mar 7, 2010
1 parent
d4cd2f0
commit fe7577e
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# start tyrant like so: | ||
# ttserver example.tct | ||
require 'rubygems' | ||
require 'tokyo_tyrant' | ||
require 'pp' | ||
t = TokyoTyrant::Table.new('127.0.0.1', 1978) | ||
|
||
|
||
# bulk operations | ||
h = {} | ||
h[0] = { :name => 'A: Joe task one', :region => 'us', :priority => 2, :url => 'http://example.com/0', :status => 'new'} | ||
h[1] = { :name => 'B: Bob task one', :region => 'us', :priority => 2, :url => 'http://example.com/1', :status => 'new'} | ||
h[2] = { :name => 'C: Joe task two', :region => 'us', :priority => 2, :url => 'http://example.com/2', :status => 'new'} | ||
h[3] = { :name => 'D: Bob task two', :region => 'eu', :priority => 1, :url => 'http://example.com/3', :status => 'new'} | ||
h[4] = { :name => 'E: Bob task three', :region => 'us', :priority => 1, :url => 'http://example.com/3', :status => 'new'} | ||
|
||
t.mput(h) | ||
# t.mget(0..3) | ||
|
||
p "Fetch only new tasks" | ||
# q = t.query | ||
# q.condition('status', :streq, 'new') | ||
# q.limit(1) | ||
# p q.get | ||
# # => [{"name"=>"A: Joe task one", "region"=>"us", "priority"=>"2", "url"=>"http://example.com/0", "__id"=>"0", "status"=>"new"}] | ||
p "Changing to pending" | ||
p t.ext(:update_new_task, 1, 2) | ||
|
||
|
||
p "Fetch only new tasks order by priority" | ||
# q = t.query | ||
# q.condition('status', :streq, 'new') | ||
# q.order_by(:priority, :strasc) | ||
# q.limit(1) | ||
# p q.get | ||
# => [{"name"=>"D: Bob task two", "region"=>"eu", "priority"=>"1", "url"=>"http://example.com/3", "__id"=>"3", "status"=>"new"}] | ||
|
||
p "Changing to pending" | ||
p t.ext(:priority, 1, 2) | ||
|
||
p "Fetch only Bob's US new tasks" | ||
# q = t.query | ||
# q.condition('status', :streq, 'new') | ||
# q.condition('region', :streq, 'us') | ||
# q.condition('name', :strinc, 'Bob') | ||
# q.limit(1) | ||
# p q.get | ||
# => [{"name"=>"B: Bob task one", "region"=>"us", "priority"=>"2", "url"=>"http://example.com/1", "__id"=>"1", "status"=>"new"}] | ||
|
||
p "Changing to pending" | ||
p t.ext(:combo, 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Equivalent to this sql | ||
-- update table set status ="pending" where status = "new" limit 1 | ||
function update_new_task() | ||
-- body | ||
local args = {}; | ||
table.insert(args, "addcond\0status\0streq\0new") | ||
table.insert(args, "setlimit\01") | ||
table.insert(args, "columns") | ||
local res = _misc("search", args) | ||
if not res then | ||
_log("failed", 2) | ||
end | ||
for key,value in pairs(res) do | ||
print(":"..tostring(key).."="..tostring(value)..":") | ||
end | ||
-- The below is not working because re[1] is empty | ||
-- return _strstr(res[1], "new", "pending") | ||
return res[1] | ||
end | ||
|
||
function priority() | ||
-- body | ||
local args = {}; | ||
table.insert(args, "addcond\0status\0streq\0new") | ||
table.insert(args, "setorder\0priority\0strasc") | ||
table.insert(args, "setlimit\01") | ||
table.insert(args, "columns") | ||
|
||
|
||
local res = _misc("search", args) | ||
if not res then | ||
_log("failed", 2) | ||
end | ||
return res[1] | ||
end | ||
|
||
function combo() | ||
-- body | ||
local args = {}; | ||
|
||
table.insert(args, "addcond\0status\0streq\0new") | ||
table.insert(args, "addcond\0region\0streq\0us") | ||
table.insert(args, "addcond\0name\0strinc\0Bob") | ||
table.insert(args, "setlimit\01") | ||
table.insert(args, "columns") | ||
|
||
local res = _misc("search", args) | ||
if not res then | ||
_log("failed", 2) | ||
end | ||
return res[1] | ||
end |