kevy_rt/message_kinds.rs
1//! The small value types the messages carry: what a gather fetches, what it
2//! got back, which multi-key reduction it is, which set/zset algebra
3//! combination, how a keyspace-collection reply is shaped, and the per-write
4//! metadata the dispatch path hands to its housekeeping.
5//!
6//! Split out of `message.rs` to keep it under the 500-LOC house cap. These are
7//! parameters of the messages, not messages themselves — `Op` and `Part` stay
8//! next to the runtime that folds them.
9
10/// What to fetch per key in a cross-shard gather.
11#[derive(Clone, Copy)]
12pub(crate) enum GatherKind {
13 /// String value (for MGET).
14 Str,
15 /// String value, with a wrong-type key reported AS wrong-type
16 /// rather than as absent (for BITOP, which Redis errors on where
17 /// MGET answers nil).
18 StrStrict,
19 /// Set members (for SINTER/SUNION/SDIFF).
20 Set,
21 /// Scored members: zsets as-is, plain sets at score 1.0 (for the
22 /// zset algebra family — Redis lets sets participate).
23 Scored,
24}
25
26/// A single key's gathered payload.
27pub(crate) enum Gathered {
28 Str(Option<Vec<u8>>),
29 Members(Vec<Vec<u8>>),
30 /// `(member, score)` payload for [`GatherKind::Scored`].
31 Scored(Vec<(Vec<u8>, f64)>),
32 WrongType,
33}
34
35/// The multi-key gather reductions computed on the originating shard.
36/// Public: [`crate::Route::Gather`] carries it, and embedders' `route()`
37/// implementations construct it.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum MultiOp {
40 /// `MGET` — values gathered in request order.
41 Mget,
42 /// `SINTER`.
43 SInter,
44 /// `SUNION`.
45 SUnion,
46 /// `SDIFF`.
47 SDiff,
48 /// `ZINTERCARD numkeys key… [LIMIT n]` — read-only gathered count.
49 /// The `LIMIT` cap is parsed from the argv by the gather builder
50 /// (it sits after the keys), not carried here.
51 ZInterCard,
52}
53
54/// Which algebra combination a `*STORE` orchestrator runs after its
55/// gather completes. Public: [`crate::Route::ZAlgebraStore`]
56/// carries it, and embedders' `route()` implementations construct it.
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum ZCombine {
59 /// `ZINTERSTORE`.
60 ZInter,
61 /// `ZUNIONSTORE`.
62 ZUnion,
63 /// `ZDIFFSTORE`.
64 ZDiff,
65 /// `SINTERSTORE`.
66 SInter,
67 /// `SUNIONSTORE`.
68 SUnion,
69 /// `SDIFFSTORE`.
70 SDiff,
71}
72
73/// Write-side facts the origin's `resolve()` already computed, carried
74/// with a dispatched command so the executing shard never re-parses the
75/// verb. Before this rode along, every forwarded write re-ran THREE
76/// full verb matches (`is_write` + `route` for the WATCH bump +
77/// `wake_idx`) on the owning shard — measurable at -c50 (SET trailed
78/// GET by the cost of those walks).
79#[derive(Clone, Copy)]
80pub(crate) struct DispatchMeta {
81 pub(crate) is_write: bool,
82 /// `Some(i)` = waking writes (LPUSH/RPUSH/XADD): argv[i] is the key
83 /// whose blocked waiters should be woken after the write.
84 pub(crate) wake_idx: Option<u8>,
85 /// `Some(i)` = argv[i] is the routed key (Route::Single) — the WATCH
86 /// version bump target. `None` for keyless `Route::Local` cmds.
87 pub(crate) key_idx: Option<u8>,
88}