Class: Juno::Adapters::TokyoCabinet

Inherits:
Memory show all
Defined in:
lib/juno/adapters/tokyocabinet.rb

Overview

TokyoCabinet backend

Instance Method Summary collapse

Methods inherited from Memory

#clear, #load, #store

Methods inherited from Base

#[], #[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ TokyoCabinet

Constructor

Options:

  • :file - Database file

  • :type - Database type (default :hdb, :bdb and :hdb possible)

Parameters:

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

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/juno/adapters/tokyocabinet.rb', line 15

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

Instance Method Details

#closeObject



39
40
41
42
# File 'lib/juno/adapters/tokyocabinet.rb', line 39

def close
  @memory.close
  nil
end

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



31
32
33
34
35
36
37
# File 'lib/juno/adapters/tokyocabinet.rb', line 31

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

#key?(key, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/juno/adapters/tokyocabinet.rb', line 27

def key?(key, options = {})
  !!load(key, options)
end