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.
-
.delete(key) ⇒ Integer
Delete an attribute package by key.
-
.find(key) ⇒ Hash?
Find an attribute package by key.
- .redis ⇒ Object private
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 = SecureRandom.hex(32) redis.set(key, json_attrs, ex: expires_in) key rescue => e raise AttrPackageError.new('create', e.) end |
.delete(key) ⇒ Integer
Delete an attribute package by key
38 39 40 41 42 |
# File 'lib/sidekiq/attr_package.rb', line 38 def delete(key) redis.del(key) rescue => e raise AttrPackageError.new('delete', e.) end |
.find(key) ⇒ Hash?
Find an attribute package by key
26 27 28 29 30 31 32 33 |
# 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) rescue => e raise AttrPackageError.new('find', e.) end |
.redis ⇒ Object (private)
46 47 48 |
# File 'lib/sidekiq/attr_package.rb', line 46 def redis @redis ||= Redis::Namespace.new(REDIS_NAMESPACE, redis: $redis) # rubocop:disable ThreadSafety/InstanceVariableInClassMethod end |