redis 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -0
- data/README.md +172 -5
- data/lib/redis/client.rb +5 -1
- data/lib/redis/commands/arrays.rb +358 -0
- data/lib/redis/commands/bitmaps.rb +24 -0
- data/lib/redis/commands/bless.rb +115 -0
- data/lib/redis/commands/cluster.rb +9 -2
- data/lib/redis/commands/hashes.rb +250 -7
- data/lib/redis/commands/keys.rb +48 -11
- data/lib/redis/commands/modules/json.rb +27 -2
- data/lib/redis/commands/modules/search/aggregation.rb +2 -1
- data/lib/redis/commands/modules/search/field.rb +11 -2
- data/lib/redis/commands/modules/search/hybrid.rb +3 -0
- data/lib/redis/commands/modules/search/index.rb +2 -1
- data/lib/redis/commands/modules/search/miscellaneous.rb +2 -1
- data/lib/redis/commands/modules/search/query.rb +2 -2
- data/lib/redis/commands/modules/search/schema.rb +4 -0
- data/lib/redis/commands/scripting.rb +109 -0
- data/lib/redis/commands/server.rb +158 -7
- data/lib/redis/commands/sets.rb +270 -0
- data/lib/redis/commands/sorted_sets.rb +131 -6
- data/lib/redis/commands/streams.rb +284 -33
- data/lib/redis/commands/strings.rb +232 -6
- data/lib/redis/commands/transactions.rb +6 -1
- data/lib/redis/commands/vector_sets.rb +407 -0
- data/lib/redis/commands.rb +169 -6
- data/lib/redis/distributed.rb +539 -22
- data/lib/redis/hash_ring.rb +2 -1
- data/lib/redis/keyspace_notifications/channels.rb +121 -0
- data/lib/redis/keyspace_notifications/manager.rb +1121 -0
- data/lib/redis/keyspace_notifications/notification.rb +95 -0
- data/lib/redis/keyspace_notifications/parser.rb +170 -0
- data/lib/redis/keyspace_notifications.rb +59 -0
- data/lib/redis/pipeline.rb +17 -5
- data/lib/redis/ractorize.rb +6 -0
- data/lib/redis/subscribe.rb +80 -2
- data/lib/redis/version.rb +1 -1
- data/lib/redis/xxh3.rb +354 -0
- data/lib/redis.rb +29 -8
- metadata +16 -6
data/lib/redis/hash_ring.rb
CHANGED
|
@@ -38,8 +38,9 @@ class Redis
|
|
|
38
38
|
@replicas.times do |i|
|
|
39
39
|
key = server_hash_for("#{node.id}:#{i}")
|
|
40
40
|
@ring.delete(key)
|
|
41
|
-
@sorted_keys.reject! { |k| k == key }
|
|
42
41
|
end
|
|
42
|
+
@sorted_keys.select! { |key| @ring.key?(key) }
|
|
43
|
+
@replicas
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
# get the node in the hash ring for this key
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Redis
|
|
4
|
+
module KeyspaceNotifications
|
|
5
|
+
# Builders for keyspace-notification channel names and psubscribe patterns.
|
|
6
|
+
#
|
|
7
|
+
# All builders return BINARY (ASCII-8BIT) encoded strings so that keys containing
|
|
8
|
+
# arbitrary bytes concatenate safely. The +db:+ argument accepts a non-negative
|
|
9
|
+
# Integer or the literal <tt>"*"</tt> (database wildcard, for pattern subscriptions).
|
|
10
|
+
# The +key+/+event+ arguments may themselves contain glob characters when the
|
|
11
|
+
# channel is meant to be used with +psubscribe+.
|
|
12
|
+
#
|
|
13
|
+
# @example Watch every event on keys under a prefix
|
|
14
|
+
# redis.psubscribe(Redis::KeyspaceNotifications::Channels.keyspace("user:*", db: 0)) { |on| ... }
|
|
15
|
+
module Channels
|
|
16
|
+
FAMILIES = {
|
|
17
|
+
keyspace: "__keyspace@",
|
|
18
|
+
keyevent: "__keyevent@",
|
|
19
|
+
subkeyspace: "__subkeyspace@",
|
|
20
|
+
subkeyevent: "__subkeyevent@",
|
|
21
|
+
subkeyspaceitem: "__subkeyspaceitem@",
|
|
22
|
+
subkeyspaceevent: "__subkeyspaceevent@"
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
module_function
|
|
26
|
+
|
|
27
|
+
# Channel carrying every event happening to +key+; the message payload is the event name.
|
|
28
|
+
#
|
|
29
|
+
# @param key [String] key name or glob pattern
|
|
30
|
+
# @param db [Integer, String] database index or "*"
|
|
31
|
+
# @return [String] <tt>__keyspace@<db>__:<key></tt> (BINARY encoded)
|
|
32
|
+
def keyspace(key, db: 0)
|
|
33
|
+
build(:keyspace, db, key)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Channel carrying every key receiving +event+; the message payload is the key name.
|
|
37
|
+
#
|
|
38
|
+
# @param event [String] event name (e.g. "expired") or glob pattern
|
|
39
|
+
# @param db [Integer, String] database index or "*"
|
|
40
|
+
# @return [String] <tt>__keyevent@<db>__:<event></tt> (BINARY encoded)
|
|
41
|
+
def keyevent(event, db: 0)
|
|
42
|
+
build(:keyevent, db, event)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Subkey channel for +key+; the payload carries the event and the affected subkeys.
|
|
46
|
+
# Requires Redis 8.8+ with the `S` flag in `notify-keyspace-events`.
|
|
47
|
+
#
|
|
48
|
+
# @param key [String] key name or glob pattern
|
|
49
|
+
# @param db [Integer, String] database index or "*"
|
|
50
|
+
# @return [String] <tt>__subkeyspace@<db>__:<key></tt> (BINARY encoded)
|
|
51
|
+
def subkeyspace(key, db: 0)
|
|
52
|
+
build(:subkeyspace, db, key)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Subkey channel for +event+; the payload carries the key and the affected subkeys.
|
|
56
|
+
# Requires Redis 8.8+ with the `T` flag in `notify-keyspace-events`.
|
|
57
|
+
#
|
|
58
|
+
# @param event [String] event name (e.g. "hdel") or glob pattern
|
|
59
|
+
# @param db [Integer, String] database index or "*"
|
|
60
|
+
# @return [String] <tt>__subkeyevent@<db>__:<event></tt> (BINARY encoded)
|
|
61
|
+
def subkeyevent(event, db: 0)
|
|
62
|
+
build(:subkeyevent, db, event)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Exact key + subkey channel; the payload is the event name. The server only emits
|
|
66
|
+
# this family for keys that contain no newline, so such keys are rejected here.
|
|
67
|
+
# Requires Redis 8.8+ with the `I` flag in `notify-keyspace-events`.
|
|
68
|
+
#
|
|
69
|
+
# @param key [String] key name (must not contain "\n")
|
|
70
|
+
# @param subkey [String] subkey (e.g. hash field) or glob pattern
|
|
71
|
+
# @param db [Integer, String] database index or "*"
|
|
72
|
+
# @return [String] <tt>__subkeyspaceitem@<db>__:<key>\n<subkey></tt> (BINARY encoded)
|
|
73
|
+
# @raise [ArgumentError] when +key+ contains "\n"
|
|
74
|
+
def subkeyspaceitem(key, subkey, db: 0)
|
|
75
|
+
raise ArgumentError, "subkeyspaceitem keys must not contain \"\\n\"" if key.include?("\n")
|
|
76
|
+
|
|
77
|
+
channel = build(:subkeyspaceitem, db, key)
|
|
78
|
+
channel << "\n" << subkey.b
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Event + key channel; the payload carries the affected subkeys. The key part may be
|
|
82
|
+
# a glob pattern (e.g. <tt>subkeyspaceevent("hset", "user:*")</tt> with psubscribe).
|
|
83
|
+
# Requires Redis 8.8+ with the `V` flag in `notify-keyspace-events`.
|
|
84
|
+
#
|
|
85
|
+
# @param event [String] event name (e.g. "hset") or glob pattern
|
|
86
|
+
# @param key [String] key name or glob pattern
|
|
87
|
+
# @param db [Integer, String] database index or "*"
|
|
88
|
+
# @return [String] <tt>__subkeyspaceevent@<db>__:<event>|<key></tt> (BINARY encoded)
|
|
89
|
+
def subkeyspaceevent(event, key, db: 0)
|
|
90
|
+
channel = build(:subkeyspaceevent, db, event)
|
|
91
|
+
channel << "|" << key.b
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Escapes Redis glob metacharacters (`*`, `?`, `[`, `]`, `\`) so a literal
|
|
95
|
+
# key can be embedded in a psubscribe pattern without matching other keys.
|
|
96
|
+
#
|
|
97
|
+
# @param value [String]
|
|
98
|
+
# @return [String] the escaped value (BINARY encoded)
|
|
99
|
+
def glob_escape(value)
|
|
100
|
+
# The replacement must be built in BINARY: interpolating a high byte into a
|
|
101
|
+
# UTF-8 literal raises Encoding::CompatibilityError, and keys are arbitrary
|
|
102
|
+
# bytes by contract.
|
|
103
|
+
value.b.gsub(/[*?\[\]\\]/) { |char| "\\".b << char }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# @api private
|
|
107
|
+
def build(family, db, suffix)
|
|
108
|
+
validate_db!(db)
|
|
109
|
+
prefix = "#{FAMILIES.fetch(family)}#{db}__:"
|
|
110
|
+
prefix.b << suffix.b
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @api private
|
|
114
|
+
def validate_db!(db)
|
|
115
|
+
return if db == "*" || (db.is_a?(Integer) && db >= 0)
|
|
116
|
+
|
|
117
|
+
raise ArgumentError, "db must be a non-negative Integer or \"*\", got #{db.inspect}"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|