lib/redistat.rb in redistat-0.2.6 vs lib/redistat.rb in redistat-0.3.0

- old
+ new

@@ -1,10 +1,11 @@ require 'rubygems' require 'date' require 'time' require 'digest/sha1' +require 'monitor' # Active Support 2.x or 3.x require 'active_support' if !{}.respond_to?(:with_indifferent_access) require 'active_support/core_ext/hash/indifferent_access' @@ -13,16 +14,19 @@ require 'time_ext' require 'redis' require 'json' -require 'redistat/options' +require 'redistat/mixins/options' +require 'redistat/mixins/synchronize' +require 'redistat/mixins/database' +require 'redistat/mixins/date_helper' + require 'redistat/connection' -require 'redistat/database' +require 'redistat/buffer' require 'redistat/collection' require 'redistat/date' -require 'redistat/date_helper' require 'redistat/event' require 'redistat/finder' require 'redistat/key' require 'redistat/label' require 'redistat/model' @@ -31,10 +35,11 @@ require 'redistat/summary' require 'redistat/version' require 'redistat/core_ext' + module Redistat KEY_NEXT_ID = ".next_id" KEY_EVENT = ".event:" KEY_LABELS = "Redistat.labels:" # used for reverse label hash lookup @@ -45,10 +50,30 @@ class InvalidOptions < ArgumentError; end class RedisServerIsTooOld < Exception; end class << self + def buffer + Buffer.instance + end + + def buffer_size + buffer.size + end + + def buffer_size=(size) + buffer.size = size + end + + def thread_safe + Synchronize.thread_safe + end + + def thread_safe=(value) + Synchronize.thread_safe = value + end + def connection(ref = nil) Connection.get(ref) end alias :redis :connection @@ -65,6 +90,12 @@ puts "WARNING: Redistat.flush is deprecated. Use Redistat.redis.flushdb instead." connection.flushdb end end +end + + +# ensure buffer is flushed on program exit +Kernel.at_exit do + Redistat.buffer.flush(true) end