metropolis.git  about / heads / tags
key-value store for Rack
blob 68c8bf57d575572091dc15b13852900c1320c768 464 bytes (raw)
$ git show HEAD:lib/metropolis/tdb/multi.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 
# -*- encoding: binary -*-
module Metropolis::TDB::Multi
  def self.extended(obj)
    obj.instance_eval do
      @multi_hash ||= :tdb_hash_murmur2
      extend Metropolis::MultiHash
      @dbv = (0...@nr_slots).to_a.map do |slot|
        path = sprintf(@path_pattern, slot)
        ::TDB.new(path, @tdb_opts)
      end
    end
  end

  def db(key, &block)
    yield @dbv[multi_hash(key) % @nr_slots]
  end

  def close!
    @dbv.each { |tdb| tdb.close }
  end
end

git clone https://yhbt.net/metropolis.git