Replace couchbase counters with drb version
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# This is a non thread safe replacement for the
|
||||
# couchbase counter mechanism since every test needs
|
||||
# a clean start and Hash#clear is soooo much faster than
|
||||
# a couchbase bucket flush
|
||||
class InMemoryQCounter
|
||||
attr_reader :store
|
||||
|
||||
def initialize
|
||||
@store = {}
|
||||
end
|
||||
|
||||
def get(key, options = {})
|
||||
store[key]
|
||||
end
|
||||
|
||||
def set(key, value)
|
||||
store[key] = value
|
||||
end
|
||||
|
||||
def incr(key, options = {})
|
||||
# store[key] ||= options[:initial].to_i
|
||||
# store[key] += 1
|
||||
if store[key]
|
||||
store[key] += 1
|
||||
else
|
||||
store[key] = options[:initial].to_i
|
||||
end
|
||||
end
|
||||
|
||||
def decr(key, options = {})
|
||||
# store[key] ||= options[:initial].to_i
|
||||
# store[key] -= 1
|
||||
if store[key]
|
||||
store[key] -= 1
|
||||
else
|
||||
store[key] = options[:initial].to_i
|
||||
end
|
||||
end
|
||||
|
||||
def flush
|
||||
store.clear
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user