Skip to content

Instantly share code, notes, and snippets.

@rubystar
Created October 26, 2017 13:30
Show Gist options
  • Save rubystar/ac94030f0e4346d92c5afe1e8f15d6c7 to your computer and use it in GitHub Desktop.
Save rubystar/ac94030f0e4346d92c5afe1e8f15d6c7 to your computer and use it in GitHub Desktop.
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