Class: DTVTournaments::Cache
- Inherits:
-
Struct
- Object
- Struct
- DTVTournaments::Cache
- Defined in:
- lib/dtv_tournaments/cache.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Class Method Summary collapse
Instance Method Summary collapse
- #get_by_number(number) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #set(tournament) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
26 27 28 29 30 31 |
# File 'lib/dtv_tournaments/cache.rb', line 26 def initialize config = DTVTournaments.cache_configuration active = config.delete(:active) @redis = Redis.new(config) if active end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis
25 26 27 |
# File 'lib/dtv_tournaments/cache.rb', line 25 def redis @redis end |
Class Method Details
.toDataArray(data) ⇒ Object
39 40 41 |
# File 'lib/dtv_tournaments/cache.rb', line 39 def self.toDataArray(data) data.split('|') end |
Instance Method Details
#get_by_number(number) ⇒ Object
33 34 35 36 37 |
# File 'lib/dtv_tournaments/cache.rb', line 33 def get_by_number(number) data = @redis.get(number) unless @redis.nil? return nil if data.nil? Tournament.deserialize(Cache.toDataArray(data)) end |
#set(tournament) ⇒ Object
43 44 45 |
# File 'lib/dtv_tournaments/cache.rb', line 43 def set(tournament) @redis.set(tournament.number, tournament.serialize) unless @redis.nil? end |