Weitere ähnliche Inhalte
Ăhnlich wie Versatile Storage Options With Tokyo Cabinet (20)
KĂźrzlich hochgeladen (20)
Versatile Storage Options With Tokyo Cabinet
- 4. B+ Tree Store
⢠Key/Value
⢠Duplicate Keys
⢠Forward Matching Keys
⢠(Perfect Tag Store)
- 5. Fixed Length DB
⢠Key/Value
⢠Keys As Natural Number
⢠Value Length Limited
⢠Faster than Hash or B+ Tree
⢠Range Query
- 7. How I Use Tokyo
⢠Like Memcache++
⢠Like a Queue
⢠Like a Counter
⢠Like a Tag Cloud
- 9. Like Memcache++
require 'tokyo_tyrant'
t = TokyoTyrant::DB.new
t['example.com/lorem'] = "Lorem..."
t['example.com/lorem']
# => "Lorem..."
t['example.com/lorem/ipsum'] = "Ipsum..."
t.fwmkeys('example.com/')
# => ['example.com/lorem/ipsum', 'example.com/lorem']
- 11. Like a Queue
require 'tokyo_tyrant'
tdb = TokyoTyrant::Table.new
tdb[tdb.genuid] = {
'url' => "http://example.com",
'queue' => "1m",
'created_at' => Time.now.to_i,
'origin' => Socket.hostname
}
- 12. Like a Queue
require 'tokyo_tyrant'
tdb = TokyoTyrant::Table.new
tasks = tdb.find{ |q|
q.condition :queue, :streq, '1m'
q.order_by :created_at
}.each{ |task| run_process(task) }
- 14. Like a Counter
require 'tokyo_tyrant'
COUNTER_DB = TokyoTyrant::DB.new
...
COUNTER_DB.add_int(id)
# => 82169
- 16. Like a Tag Cloud
require 'tokyo_tyrant'
TAG_DB = TokyoTyrant::BDB.new
...
tags = ['foo', 'bar']
tags.collect!{ |tag| "tag:#{tag}:articles" }
hash_tags = TAG_DB.getlist(tags)
article_ids = hash_tags.values.collect.flatten
article_ids = article_ids.uniq.sort.reverse[0..4]
articles = TAG_DB.mget(article_ids)
- 17. Related Content
articles = TAG_DB.mget(article_ids)
unpack = proc{ |k,v| v = MessagePack.unpack(v); v['__id'] = k; v }
articles = articles.collect(&unpack).compact
articles = articles.sort_by{ |v| v['__id'] }
articles.reverse!
content = Mustache.render(@@template, :articles => articles)
response = [200, {"Content-Type" => "text/html"}, [content]]
- 19. More
http://1978th.net/tokyocabinet
http://1978th.net/tokyotyrant/
http://groups.google.com/group/tokyocabinet-users/
http://tokyocabinetwiki.pbworks.com/
http://github.com/actsasďŹinn/ruby-tokyotyrant
http://github.com/jmettraux/rufus-tokyo/