Class: ActiveSupport::Cache::AerospikeStore

Inherits:
Store
  • Object
show all
Defined in:
lib/active_support/cache/aerospike_store.rb

Constant Summary collapse

AEROSPIKE_DEFAULT_OPTIONS =
{
    :host => '127.0.0.1',
    :port => 3000,
    :ns   => 'test',
    :set  => 'cache',
    :bin  => 'entry'
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AerospikeStore

Returns a new instance of AerospikeStore.



16
17
18
19
20
21
# File 'lib/active_support/cache/aerospike_store.rb', line 16

def initialize(options = {})
  options.merge!(self.class::AEROSPIKE_DEFAULT_OPTIONS) { |key, v1| v1 }
  @client = options.delete(:client) ||
      Aerospike::Client.new(Aerospike::Host.new(options.delete(:host), options.delete(:port)))
  super
end

Instance Method Details

#decrement(name, amount = 1, options = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/active_support/cache/aerospike_store.rb', line 31

def decrement(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:decrement, name, :amount => amount) do
    key = namespaced_key(name, options)
    @client.add(as_key(key, options), {options[:bin] => -1 * amount}, options)
  end
end

#increment(name, amount = 1, options = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/active_support/cache/aerospike_store.rb', line 23

def increment(name, amount = 1, options = nil)
  options = merged_options(options)
  instrument(:increment, name, :amount => amount) do
    key = namespaced_key(name, options)
    @client.add(as_key(key, options), {options[:bin] => amount}, options)
  end
end