Class: Chip::RedisClient

Inherits:
Object
  • Object
show all
Defined in:
lib/chip/redis_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ RedisClient

Returns a new instance of RedisClient.



11
12
13
14
# File 'lib/chip/redis_client.rb', line 11

def initialize(key)
  @redis_namespace = Redis::Namespace.new(namespace, redis: $redis)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/chip/redis_client.rb', line 5

def key
  @key
end

#redis_namespaceObject (readonly)

Returns the value of attribute redis_namespace.



5
6
7
# File 'lib/chip/redis_client.rb', line 5

def redis_namespace
  @redis_namespace
end

Class Method Details

.build(key) ⇒ Object



7
8
9
# File 'lib/chip/redis_client.rb', line 7

def self.build(key)
  new(key)
end

Instance Method Details

#getObject



16
17
18
# File 'lib/chip/redis_client.rb', line 16

def get
  redis_namespace.get(key)
end

#namespaceObject



28
29
30
# File 'lib/chip/redis_client.rb', line 28

def namespace
  @namespace ||= REDIS_CONFIG[:chip][:namespace]
end

#save(token:) ⇒ Object



20
21
22
# File 'lib/chip/redis_client.rb', line 20

def save(token:)
  redis_namespace.set(key, token, ex: ttl)
end

#ttlObject



24
25
26
# File 'lib/chip/redis_client.rb', line 24

def ttl
  @ttl ||= REDIS_CONFIG[:chip][:each_ttl]
end