class ActiveSupport::Cache::AerospikeStore
Constants
- AEROSPIKE_DEFAULT_OPTIONS
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
decrement(name, amount = 1, options = nil)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
delete_entry(key, options)
click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 71 def delete_entry(key, options) @client.delete(as_key(key, options)) end
internal_read_entry(key, options)
click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 41 def internal_read_entry(key, options) record = @client.get(as_key(key, options)) if record # single-bin namespaces do not return a bin name (record.bins.length == 1)? record.bins.values.first : record.bins[options[:bin]] else nil end end
read_entry(key, options)
click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 51 def read_entry(key, options) if value = internal_read_entry(key, options) options[:raw]? ActiveSupport::Cache::Entry.new(value) : Marshal.load(value) else nil end end
write_entry(key, entry, options)
click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 59 def write_entry(key, entry, options) options[:expiration] ||= options[:expires_in] if options[:expires_in] options[:record_exists_action] ||= options[:unless_exist]? Aerospike::RecordExistsAction::CREATE_ONLY : Aerospike::RecordExistsAction::REPLACE value = options[:raw]? entry.value : Marshal.dump(entry) begin @client.put(as_key(key, options), {options[:bin] => value}, options) rescue Aerospike::Exceptions::Aerospike => e raise unless (e.result_code == Aerospike::ResultCode::KEY_EXISTS_ERROR) false end end
Private Instance Methods
as_key(key, options)
click to toggle source
# File lib/active_support/cache/aerospike_store.rb, line 77 def as_key(key, options) Aerospike::Key.new(options[:ns], options[:set], key) end