Class: Redis::KeyspaceNotifications::Notification
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/redis/keyspace_notifications/notification.rb |
Overview
A parsed keyspace, keyevent or subkey notification.
Immutable value object produced by Parser.parse. #key and the #subkeys
elements are BINARY (ASCII-8BIT) encoded strings, because ::Redis keys and
subkeys may contain arbitrary bytes; call force_encoding on them if your
application guarantees UTF-8 keys.
Constant Summary
-
FAMILIES =
# File 'lib/redis/keyspace_notifications/notification.rb', line 12%i[keyspace keyevent subkeyspace subkeyevent subkeyspaceitem subkeyspaceevent].freeze
Class Method Summary
Instance Attribute Summary
- #channel ⇒ Symbol, ... readonly
- #db ⇒ Symbol, ... readonly
- #event ⇒ Symbol, ... readonly
- #family ⇒ Symbol, ... readonly
- #key ⇒ Symbol, ... readonly
- #pattern ⇒ Symbol, ... readonly
- #payload ⇒ Symbol, ... readonly
- #subkey_family? ⇒ Boolean readonly
- #subkeys ⇒ Symbol, ... readonly
Instance Method Summary
- #==(other) ⇒ Boolean (also: #eql?)
-
#eql?(other)
Alias for #==.
- #hash ⇒ Integer
-
#subkey ⇒ String?
Convenience accessor for single-subkey families (subkeyspaceitem).
- #to_h ⇒ Hash{Symbol => Object}
- #frozen_copy(value) private
Constructor Details
.new(family:, db:, event:, key:, channel:, payload:, subkeys: [], pattern: nil) ⇒ Notification
# File 'lib/redis/keyspace_notifications/notification.rb', line 35
def initialize(family:, db:, event:, key:, channel:, payload:, subkeys: [], pattern: nil) @family = family @db = frozen_copy(db) # Integers pass through; the "*" String form gets copied @event = frozen_copy(event) @key = frozen_copy(key) @subkeys = subkeys.map { |subkey| frozen_copy(subkey) }.freeze @channel = frozen_copy(channel) @payload = frozen_copy(payload) @pattern = frozen_copy(pattern) # Deep-frozen: the value object implements #hash / #eql?, so no field may be # mutable after construction (a mutated Hash key becomes unreachable). freeze end
Instance Attribute Details
#channel ⇒ Symbol, ... (readonly)
#db ⇒ Symbol, ... (readonly)
#event ⇒ Symbol, ... (readonly)
#family ⇒ Symbol, ... (readonly)
#key ⇒ Symbol, ... (readonly)
#pattern ⇒ Symbol, ... (readonly)
#payload ⇒ Symbol, ... (readonly)
#subkey_family? ⇒ Boolean (readonly)
# File 'lib/redis/keyspace_notifications/notification.rb', line 58
def subkey_family? @family != :keyspace && @family != :keyevent end
#subkeys ⇒ Symbol, ... (readonly)
Instance Method Details
#==(other) ⇒ Boolean
Also known as: #eql?
#eql?(other)
Alias for #==.
# File 'lib/redis/keyspace_notifications/notification.rb', line 81
alias eql? ==
#frozen_copy(value) (private)
[ GitHub ]# File 'lib/redis/keyspace_notifications/notification.rb', line 90
def frozen_copy(value) value.nil? || value.frozen? ? value : value.dup.freeze end
#hash ⇒ Integer
# File 'lib/redis/keyspace_notifications/notification.rb', line 84
def hash to_h.hash end
#subkey ⇒ String?
Convenience accessor for single-subkey families (subkeyspaceitem).
# File 'lib/redis/keyspace_notifications/notification.rb', line 52
def subkey @subkeys.first end
#to_h ⇒ Hash{Symbol => Object}
# File 'lib/redis/keyspace_notifications/notification.rb', line 63
def to_h { family: @family, db: @db, event: @event, key: @key, subkeys: @subkeys, channel: @channel, payload: @payload, pattern: @pattern } end