lib/verdict/storage/redis_storage.rb in verdict-0.11.0 vs lib/verdict/storage/redis_storage.rb in verdict-0.12.0

- old
+ new

@@ -8,10 +8,12 @@ def initialize(redis = nil, options = {}) @redis = redis @key_prefix = options[:key_prefix] || 'experiments/' end + protected + def get(scope, key) redis.hget(scope_key(scope), key) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.message}" end @@ -26,12 +28,12 @@ redis.hdel(scope_key(scope), key) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.message}" end - def cleanup(scope) - clear(scope) + def clear(scope, options) + scrub(scope) redis.del(scope_key(scope)) rescue ::Redis::BaseError => e raise Verdict::StorageError, "Redis error: #{e.message}" end @@ -39,15 +41,15 @@ def scope_key(scope) "#{@key_prefix}#{scope}" end - def clear(scope, cursor: 0) + def scrub(scope, cursor: 0) cursor, results = redis.hscan(scope_key(scope), cursor, count: PAGE_SIZE) results.map(&:first).each do |key| remove(scope, key) end - clear(scope, cursor: cursor) unless cursor.to_i.zero? + scrub(scope, cursor: cursor) unless cursor.to_i.zero? end end end end