module Tiny::Redis::ClassMethods

Public Instance Methods

load(index) click to toggle source
# File lib/tiny/redis.rb, line 21
def load(index)
  key, crypt = setup(index)

  $redis.with do |r|
    encrypted = r.get(key)
    return nil if encrypted.nil?
    JSON.parse(crypt.decrypt_and_verify(encrypted), object_class: self)
  end
end
setup(index) click to toggle source
# File lib/tiny/redis.rb, line 31
def setup(index)
  key = Digest::SHA1.hexdigest(index)
  encrypt_key = Rails.application.credentials.user[:encryptkey]
  crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
  return [key, crypt]
end