Sha256: 5210e6b6a5f073308ca046d87297acae57cf3cbfd9bcb8f9f9de1fe4746b7e3e

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'tokyotyrant'
module Monkeyshines
  module Store

    #
    # Implementation of KeyStore with a Local TokyoCabinet hash database (RDB)
    #
    class TyrantRdbKeyStore < Monkeyshines::Store::KeyStore
      attr_accessor :db_host, :db_port

      # pass in the host:port uri of the key store.
      def initialize options
        raise "URI for #{self.class} is required" if options[:uri].blank?
        self.db_host, self.db_port = options[:uri].to_s.split(':')
        super options
      end

      def db
        return @db if @db
        @db ||= TokyoTyrant::RDB.new
        @db.open(db_host, db_port) or raise("Can't open DB #{db_host}:#{db_port}. Pass in host:port' #{@db.ecode}: #{@db.errmsg(@db.ecode)}")
        @db
      end

      def close
        @db.close if @db
        @db = nil
      end

      # Save the value into the database without waiting for a response.
      def set_nr(key, val)
        db.putnr key, val if val
      end

      def size()        db.rnum  end
      def include? *args
        db.has_key? *args
      end

      # require 'memcache'
      # def initialize db_uri=nil, *args
      #   # db_uri ||= ':1978'
      #   # self.db_host, self.db_port = db_uri.split(':')
      #   self.db = MemCache.new(db_uri, :no_reply => true)
      #   if !self.db then raise("Can't open DB #{db_uri}. Pass in host:port, default is ':1978' #{db.ecode}: #{db.errmsg(db.ecode)}") end
      #   super *args
      # end
      #
      # def size
      #   db.stats
      # end

    end #class
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
monkeyshines-0.2.1 lib/monkeyshines/store/tyrant_rdb_key_store.rb
monkeyshines-0.2.0 lib/monkeyshines/store/tyrant_rdb_key_store.rb
monkeyshines-0.0.2 lib/monkeyshines/store/tyrant_rdb_key_store.rb