Class: Moneta::Adapters::TokyoCabinet

Inherits:
Memory
  • Object
show all
Defined in:
lib/moneta/adapters/tokyocabinet.rb

Overview

TokyoCabinet backend

Instance Method Summary collapse

Methods included from Mixins::HashAdapter

#clear, #key?, #load, #store

Methods included from Mixins::IncrementSupport

#increment

Methods inherited from Base

#[], #[]=, #decrement, #fetch, #increment, #key?

Methods included from Mixins::WithOptions

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ TokyoCabinet

Constructor

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :file (String)

    Database file

  • :type (Symbol) — default: :hdb

    Database type (:bdb and :hdb possible)

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/moneta/adapters/tokyocabinet.rb', line 13

def initialize(options = {})
  file = options[:file]
  raise ArgumentError, 'Option :file is required' unless options[:file]
  if options[:type] == :bdb
    @hash = ::TokyoCabinet::BDB.new
    @hash.open(file, ::TokyoCabinet::BDB::OWRITER | ::TokyoCabinet::BDB::OCREAT)
  else
    @hash = ::TokyoCabinet::HDB.new
    @hash.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT)
  end or raise @hash.errmsg(@hash.ecode)
end

Instance Method Details

#closeObject



33
34
35
36
# File 'lib/moneta/adapters/tokyocabinet.rb', line 33

def close
  @hash.close
  nil
end

#delete(key, options = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/moneta/adapters/tokyocabinet.rb', line 25

def delete(key, options = {})
  value = load(key, options)
  if value
    @hash.delete(key)
    value
  end
end