Sha256: 28abf87cb944a742235d9ed26152f4ae07cf1c19ea17360a9fffe6f3bdebde3b
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
# frozen_string_literal: true module RSpeed module Redis require 'redis' module_function def clean RSpeed::Logger.log('[RSpeed::Redis#clean] Cleaning pipes and profiles.') destroy(RSpeed::Variable::PIPES_PATTERN) destroy(RSpeed::Variable::PROFILE_PATTERN) end def client @client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port) end def destroy(pattern = RSpeed::Variable::DEFAULT_PATTERN) RSpeed::Logger.log(%([RSpeed::Redis#destroy] Destroying pattern "#{pattern}".)) keys(pattern).each { |key| client.del(key) } end def get(key) client.get(key) end def keys(pattern = RSpeed::Variable::DEFAULT_PATTERN) cursor = 0 result = [] loop do cursor, results = client.scan(cursor, match: pattern) result += results break if cursor.to_i.zero? end result end def result? keys(RSpeed::Env.result_key).any? end def set(key, value) client.set(key, value) end def specs_finished? (RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes).tap do |boo| RSpeed::Logger.log("[RSpeed::Redis#specs_finished?] Specs #{boo ? 'finished.' : 'not fineshed yet.'}") end end def specs_initiated? RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).any?.tap do |boo| RSpeed::Logger.log("[RSpeed::Redis#specs_initiated?] Specs #{boo ? 'initialized.' : 'not initialized yet.'}") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rspeed-0.5.2 | lib/rspeed/redis.rb |