Class: DeadCodeDetector::Storage::RedisBackend
- Inherits:
-
Object
- Object
- DeadCodeDetector::Storage::RedisBackend
- Defined in:
- lib/dead_code_detector/storage/redis_backend.rb
Instance Attribute Summary collapse
-
#flush_immediately ⇒ Object
Returns the value of attribute flush_immediately.
Instance Method Summary collapse
- #add(key, values) ⇒ Object
- #clear(key) ⇒ Object
- #delete(key, value) ⇒ Object
- #flush ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ RedisBackend
constructor
A new instance of RedisBackend.
Constructor Details
#initialize ⇒ RedisBackend
Returns a new instance of RedisBackend.
8 9 10 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 8 def initialize @pending_deletions = Hash.new{|h,k| h[k] = Set.new } end |
Instance Attribute Details
#flush_immediately ⇒ Object
Returns the value of attribute flush_immediately.
6 7 8 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 6 def flush_immediately @flush_immediately end |
Instance Method Details
#add(key, values) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 16 def add(key, values) values = Array(values) return if values.empty? DeadCodeDetector.config.redis.sadd(key, values) DeadCodeDetector.config.redis.expire(key, DeadCodeDetector.config.cache_expiry) end |
#clear(key) ⇒ Object
12 13 14 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 12 def clear(key) DeadCodeDetector.config.redis.del(key) end |
#delete(key, value) ⇒ Object
33 34 35 36 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 33 def delete(key, value) @pending_deletions[key] << value.to_s flush if flush_immediately end |
#flush ⇒ Object
38 39 40 41 42 43 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 38 def flush @pending_deletions.each do |key, values| DeadCodeDetector.config.redis.srem(key, values.to_a) end @pending_deletions.clear end |
#get(key) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dead_code_detector/storage/redis_backend.rb', line 23 def get(key) members = DeadCodeDetector.config.redis.smembers(key) members = Set.new(members) if members.is_a?(Array) if @pending_deletions.key?(key) members - @pending_deletions[key] else members end end |