Class: Stoplight::Infrastructure::Redis::Storage::KeySpace
- Inherits:
-
Data
- Object
- Data
- Stoplight::Infrastructure::Redis::Storage::KeySpace
- Defined in:
- lib/stoplight/infrastructure/redis/storage/key_space.rb,
lib/stoplight/infrastructure/redis/storage/key_space.rb
Overview
Immutable key namespace for a light within a system.
Produces keys following entity-first structure:
stoplight:v6:{system_id}:{light_id}:locks:recovery
stoplight:v6:{system_id}:{light_id}:metrics:successes
stoplight:v6:{system_id}:{light_id}:state
Identifiers are derived from SHA-256 and truncated to 12 characters. Collisions are extremely unlikely at expected system scale.
Instance Attribute Summary collapse
-
#light_id ⇒ Object
readonly
Returns the value of attribute light_id.
-
#system_id ⇒ Object
readonly
Returns the value of attribute system_id.
Class Method Summary collapse
- .build(system_name:, light_name:) ⇒ Object
-
.hash_name(name) ⇒ Object
Generates a truncated SHA256 hash for use in Redis keys.
Instance Method Summary collapse
-
#key(*pieces) ⇒ Object
Builds a Redis key within this namespace.
Instance Attribute Details
#light_id ⇒ Object (readonly)
Returns the value of attribute light_id
23 24 25 |
# File 'lib/stoplight/infrastructure/redis/storage/key_space.rb', line 23 def light_id @light_id end |
#system_id ⇒ Object (readonly)
Returns the value of attribute system_id
23 24 25 |
# File 'lib/stoplight/infrastructure/redis/storage/key_space.rb', line 23 def system_id @system_id end |
Class Method Details
.build(system_name:, light_name:) ⇒ Object
33 34 35 36 |
# File 'lib/stoplight/infrastructure/redis/storage/key_space.rb', line 33 def build(system_name:, light_name:) = new( system_id: hash_name(system_name), light_id: hash_name(light_name) ) |
.hash_name(name) ⇒ Object
Generates a truncated SHA256 hash for use in Redis keys.
39 |
# File 'lib/stoplight/infrastructure/redis/storage/key_space.rb', line 39 def hash_name(name) = Digest::SHA256.hexdigest(name.to_s)[0, 12] #: String |
Instance Method Details
#key(*pieces) ⇒ Object
Builds a Redis key within this namespace.
46 |
# File 'lib/stoplight/infrastructure/redis/storage/key_space.rb', line 46 def key(*pieces) = [:stoplight, :v6, system_id, "{#{light_id}}", *pieces].join(":") |