Files
mozo-backend/lib/qwaiter/counter.rb
T
2014-07-21 20:31:11 +02:00

30 lines
713 B
Ruby

module Qwaiter
module Counter
mattr_accessor :connection
# mainly for testing purposes
def self.set(key, value)
connection.set(key, value) rescue value
end
def self.get(key)
connection.get(key, quiet: true).to_i rescue 0
end
def self.incr(key, options = {})
options[:initial] ||= 1
connection.incr(key, options) rescue 1
end
def self.decr(key, options = {})
options[:initial] ||= 0
connection.decr(key, options) rescue 0
end
end
end
# use the connection from couchbase-structures/documents
# will be overwritten in the specs since flushing the real
# thing is difficult
Qwaiter::Counter.connection = $cb unless Rails.env.test?