Module: RSpeed::Redis
- Defined in:
- lib/rspeed/redis.rb
Class Method Summary collapse
- .clean ⇒ Object
- .client ⇒ Object
- .destroy(pattern:) ⇒ Object
- .get(key) ⇒ Object
- .keys(pattern:) ⇒ Object
- .list(key) ⇒ Object
- .profiles_content(pattern: 'rspeed:profile_*') ⇒ Object
- .result? ⇒ Boolean
- .set(key, value) ⇒ Object
- .specs_finished? ⇒ Boolean
- .specs_initiated? ⇒ Boolean
- .version_the_result ⇒ Object
Class Method Details
.clean ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rspeed/redis.rb', line 9 def clean RSpeed::Logger.log(self, __method__, 'Cleaning pipes and profiles.') destroy(pattern: RSpeed::Variable::PIPES_PATTERN) destroy(pattern: RSpeed::Variable::PROFILE_PATTERN) end |
.client ⇒ Object
16 17 18 |
# File 'lib/rspeed/redis.rb', line 16 def client @client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port) end |
.destroy(pattern:) ⇒ Object
20 21 22 23 24 |
# File 'lib/rspeed/redis.rb', line 20 def destroy(pattern:) RSpeed::Logger.log(self, __method__, %(Destroying pattern "#{pattern}".)) keys(pattern: pattern).each { |key| client.del(key) } end |
.get(key) ⇒ Object
26 27 28 |
# File 'lib/rspeed/redis.rb', line 26 def get(key) client.get(key) end |
.keys(pattern:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rspeed/redis.rb', line 30 def keys(pattern:) cursor = 0 result = [] loop do cursor, results = client.scan(cursor, match: pattern) result += results break if cursor.to_i.zero? end result end |
.list(key) ⇒ Object
44 45 46 |
# File 'lib/rspeed/redis.rb', line 44 def list(key) client.lrange(key, 0, -1) end |
.profiles_content(pattern: 'rspeed:profile_*') ⇒ Object
48 49 50 |
# File 'lib/rspeed/redis.rb', line 48 def profiles_content(pattern: 'rspeed:profile_*') client.keys(pattern).map { |key| list(key) }.flatten end |
.result? ⇒ Boolean
52 53 54 |
# File 'lib/rspeed/redis.rb', line 52 def result? keys(pattern: RSpeed::Variable.result).any? end |
.set(key, value) ⇒ Object
56 57 58 |
# File 'lib/rspeed/redis.rb', line 56 def set(key, value) client.set(key, value) end |
.specs_finished? ⇒ Boolean
60 61 62 63 64 |
# File 'lib/rspeed/redis.rb', line 60 def specs_finished? (RSpeed::Redis.keys(pattern: RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes).tap do |boo| RSpeed::Logger.log(self, __method__, "Specs #{boo ? 'finished.' : 'not fineshed yet.'}") end end |