Class: Ez::Settings::Backend::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/ez/settings/backend/redis.rb

Constant Summary collapse

PREFIX =
'ez:settings'
NAMESPACE =
'config'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, namespace: NAMESPACE) ⇒ Redis

Returns a new instance of Redis.



14
15
16
17
# File 'lib/ez/settings/backend/redis.rb', line 14

def initialize(connection, namespace: NAMESPACE)
  @connection = connection
  @namespace = namespace
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/ez/settings/backend/redis.rb', line 12

def connection
  @connection
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



12
13
14
# File 'lib/ez/settings/backend/redis.rb', line 12

def namespace
  @namespace
end

Instance Method Details

#readObject



19
20
21
22
# File 'lib/ez/settings/backend/redis.rb', line 19

def read
  value = connection.get(key)
  value.nil? ? {} : JSON.parse(value).deep_symbolize_keys
end

#write(data) ⇒ Object



24
25
26
27
# File 'lib/ez/settings/backend/redis.rb', line 24

def write(data)
  new_data = read.merge(data)
  connection.set(key, JSON.generate(new_data))
end