Class: Canery::Tub

Inherits:
Object
  • Object
show all
Defined in:
lib/canery/tub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, name) ⇒ Tub

Returns a new instance of Tub.

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/canery/tub.rb', line 10

def initialize(backend, name)
  raise ArgumentError, "unknown backend type" unless Canery::Backend === backend
  raise ArgumentError, "name of tub must be a String" unless String === name
  @backend, @name = backend, name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/canery/tub.rb', line 8

def name
  @name
end

Instance Method Details

#clearObject



38
39
40
# File 'lib/canery/tub.rb', line 38

def clear
  backend.call(:clear, name)
end

#delete(key) ⇒ Object



34
35
36
# File 'lib/canery/tub.rb', line 34

def delete(key)
  backend.call(:delete, name, key)
end

#get(key) ⇒ Object Also known as: []



16
17
18
# File 'lib/canery/tub.rb', line 16

def get(key)
  backend.call(:get, name, key)
end

#has_key?(key) ⇒ Boolean Also known as: key?

Returns:

  • (Boolean)


42
43
44
# File 'lib/canery/tub.rb', line 42

def has_key?(key)
  backend.call(:has_key?, name, key)
end

#keysObject



47
48
49
# File 'lib/canery/tub.rb', line 47

def keys
  backend.call(:keys, name)
end

#lengthObject Also known as: size, count



67
68
69
# File 'lib/canery/tub.rb', line 67

def length
  backend.call(:count, name)
end

#mget(keys) ⇒ Object



21
22
23
# File 'lib/canery/tub.rb', line 21

def mget(keys)
  backend.call(:mget, name, keys)
end

#mset(data) ⇒ Object



30
31
32
# File 'lib/canery/tub.rb', line 30

def mset(data)
  backend.call(:mset, name, data)
end

#rename(old_key, new_key) ⇒ Object



63
64
65
# File 'lib/canery/tub.rb', line 63

def rename(old_key, new_key)
  backend.call(:rename, name, old_key, new_key)
end

#set(key, value) ⇒ Object Also known as: []=



25
26
27
# File 'lib/canery/tub.rb', line 25

def set(key, value)
  backend.call(:set, name, key || uuid, value)
end

#sort(order, limit = nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/canery/tub.rb', line 55

def sort(order, limit = nil)
  begin
    backend.call(:sort, name, order, limit)
  rescue ArgumentError => e
    raise Canery::CaneryError, e
  end
end

#valuesObject



51
52
53
# File 'lib/canery/tub.rb', line 51

def values
  backend.call(:values, name)
end