reallyme_valkey_kit/command.rs
1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! Generic app-owned command construction.
6
7/// A Valkey command whose response is decoded by [`crate::ValkeyConnector`].
8pub type ValkeyCommand = redis::Cmd;
9
10/// A Valkey command pipeline whose response is decoded by
11/// [`crate::ValkeyConnector`].
12pub type ValkeyPipeline = redis::Pipeline;
13
14/// Starts a command with a compile-time command name.
15///
16/// Restricting the name to a static string ensures external input cannot select
17/// administrative commands. Applications should add untrusted values only as
18/// encoded arguments and namespace every application-owned key with
19/// [`crate::ValkeyConnector::namespaced_key`].
20pub fn valkey_command(name: &'static str) -> ValkeyCommand {
21 redis::cmd(name)
22}
23
24/// Starts a non-atomic command pipeline.
25///
26/// Call [`ValkeyPipeline::atomic`] when all commands must execute as one Valkey
27/// transaction. Pipeline construction stays app-owned because only the app can
28/// define the operation's atomicity and idempotency requirements.
29pub fn valkey_pipeline() -> ValkeyPipeline {
30 redis::pipe()
31}
32
33#[cfg(test)]
34mod tests {
35 use super::{valkey_command, valkey_pipeline};
36
37 #[test]
38 fn command_and_pipeline_factories_construct_driver_values() {
39 let mut command = valkey_command("PING");
40 command.arg("bounded");
41
42 let mut pipeline = valkey_pipeline();
43 pipeline.cmd("PING");
44 pipeline.atomic();
45 }
46}