Created
October 26, 2017 13:30
-
-
Save rubystar/ac94030f0e4346d92c5afe1e8f15d6c7 to your computer and use it in GitHub Desktop.
Redis record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "redis" | |
$redis = Redis.new | |
class ReportExport | |
attr_reader :id | |
def initialize | |
@id = SecureRandom.uuid | |
end | |
class << self | |
def find(id) | |
$redis.hgetall(namespaced_id(id)).merge({id: id}) | |
end | |
def create(values) | |
id = new.id | |
nm_id = namespaced_id(id) | |
values.each do |key, val| | |
$redis.hset nm_id, key, val | |
end | |
$redis.hgetall(nm_id).merge!({id: id}) | |
end | |
def update(id, values) | |
nm_id = namespaced_id(id) | |
values.each do |key, val| | |
$redis.hset nm_id, key, val | |
end | |
$redis.hgetall(nm_id).merge!({id: id}) | |
end | |
def namespace | |
"modular_server_report_export_record" | |
end | |
def namespaced_id(id) | |
"#{namespace}:#{id}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment