Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redis record
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
You can’t perform that action at this time.