Skip to main content

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    /// Set members (for SINTER/SUNION/SDIFF).
16    Set,
17    /// Scored members: zsets as-is, plain sets at score 1.0 (for the
18    /// zset algebra family — Redis lets sets participate).
19    Scored,
20}
21
22/// A single key's gathered payload.
23pub(crate) enum Gathered {
24    Str(Option<Vec<u8>>),
25    Members(Vec<Vec<u8>>),
26    /// `(member, score)` payload for [`GatherKind::Scored`].
27    Scored(Vec<(Vec<u8>, f64)>),
28    WrongType,
29}
30
31/// The multi-key gather reductions computed on the originating shard.
32/// Public: [`crate::Route::Gather`] carries it, and embedders' `route()`
33/// implementations construct it.
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum MultiOp {
36    /// `MGET` — values gathered in request order.
37    Mget,
38    /// `SINTER`.
39    SInter,
40    /// `SUNION`.
41    SUnion,
42    /// `SDIFF`.
43    SDiff,
44    /// `ZINTERCARD numkeys key… [LIMIT n]` — read-only gathered count.
45    /// The `LIMIT` cap is parsed from the argv by the gather builder
46    /// (it sits after the keys), not carried here.
47    ZInterCard,
48}
49
50/// Which algebra combination a `*STORE` orchestrator runs after its
51/// gather completes. Public: [`crate::Route::ZAlgebraStore`]
52/// carries it, and embedders' `route()` implementations construct it.
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub enum ZCombine {
55    /// `ZINTERSTORE`.
56    ZInter,
57    /// `ZUNIONSTORE`.
58    ZUnion,
59    /// `ZDIFFSTORE`.
60    ZDiff,
61    /// `SINTERSTORE`.
62    SInter,
63    /// `SUNIONSTORE`.
64    SUnion,
65    /// `SDIFFSTORE`.
66    SDiff,
67}
68
69/// Write-side facts the origin's `resolve()` already computed, carried
70/// with a dispatched command so the executing shard never re-parses the
71/// verb. Before this rode along, every forwarded write re-ran THREE
72/// full verb matches (`is_write` + `route` for the WATCH bump +
73/// `wake_idx`) on the owning shard — measurable at -c50 (SET trailed
74/// GET by the cost of those walks).
75#[derive(Clone, Copy)]
76pub(crate) struct DispatchMeta {
77    pub(crate) is_write: bool,
78    /// `Some(i)` = waking writes (LPUSH/RPUSH/XADD): argv[i] is the key
79    /// whose blocked waiters should be woken after the write.
80    pub(crate) wake_idx: Option<u8>,
81    /// `Some(i)` = argv[i] is the routed key (Route::Single) — the WATCH
82    /// version bump target. `None` for keyless `Route::Local` cmds.
83    pub(crate) key_idx: Option<u8>,
84}
85
86
87