Class: DTVTournaments::Cache

Inherits:
Struct
  • Object
show all
Defined in:
lib/dtv_tournaments/cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

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

#redisObject

Returns the value of attribute redis

Returns:

  • (Object)

    the current value of 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