-
-
Save uu59/1079428 to your computer and use it in GitHub Desktop.
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
# -- coding: utf-8 | |
require "kyotocabinet" | |
class Stash | |
include Enumerable | |
def initialize(&block) | |
@buf = [] | |
@filter = block | |
end | |
def each(&block) | |
@buf.each{|v| block.call(v)} | |
end | |
def visit_full(key, value) | |
@buf << key if @filter.call(key, value) | |
KyotoCabinet::Visitor::NOP | |
end | |
end | |
KyotoCabinet::DB.process('bar.kct') {|db| | |
1.upto(100){|v| | |
db[v.to_s] = v.to_s + "-value" | |
} | |
visitor = Stash.new{|k,v| | |
k.match(/3/) | |
} | |
db.iterate(visitor) | |
p visitor.take(2).map{|k| db[k]} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment