3e4bcc80c8
- Add Mozo::Counter::Redis with same get/set/incr/decr interface - Add redis gem (~> 5.0) to Gemfile - Update cable.yml to use Redis adapter in production (shared with counters) - Document DrbCounter → Redis migration in broadcasting-migration.md - Redis installed and running on vmi3300327 - Leave Faye as current broadcaster; both switches are one-line changes DrbCounter problems solved: - In-memory → persistent (RDB + AOF) - Single-process DRb → multi-process safe Redis - Atomic INCR/DECR across Puma workers - One less custom process to manage
28 lines
570 B
Ruby
28 lines
570 B
Ruby
module Mozo
|
|
module Counter
|
|
extend ActiveSupport::Autoload
|
|
autoload :Redis
|
|
|
|
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
|