Class: Sidekiq::AttrPackage
- Inherits:
-
Object
- Object
- Sidekiq::AttrPackage
- Defined in:
- lib/sidekiq/attr_package.rb
Constant Summary collapse
- REDIS_NAMESPACE =
'sidekiq_attr_package'
Class Method Summary collapse
-
.create(expires_in: 7.days, **attrs) ⇒ String
Create a new attribute package.
-
.find(key) ⇒ Hash?
Find an attribute package by key.
Class Method Details
.create(expires_in: 7.days, **attrs) ⇒ String
Create a new attribute package
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sidekiq/attr_package.rb', line 12 def create(expires_in: 7.days, **attrs) json_attrs = attrs.to_json key = Digest::SHA256.hexdigest(json_attrs) redis.set(key, json_attrs, ex: expires_in) key rescue => e raise AttrPackageError.new('create', e.) end |
.find(key) ⇒ Hash?
Find an attribute package by key
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sidekiq/attr_package.rb', line 26 def find(key) json_value = redis.get(key) return nil unless json_value JSON.parse(json_value, symbolize_names: true).tap do redis.del(key) end rescue => e raise AttrPackageError.new('find', e.) end |