From 66c8ee9a7922ecef208bbf41b44521a72659ac27 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 31 Jul 2023 12:08:43 +0200 Subject: [PATCH] Use `u64` instead of `Uuid` to match Redis behaviour https://redis.io/commands/xadd/ --- todored/Cargo.toml | 1 - todored/src/op.rs | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/todored/Cargo.toml b/todored/Cargo.toml index e76d818..a2df0e8 100644 --- a/todored/Cargo.toml +++ b/todored/Cargo.toml @@ -17,4 +17,3 @@ redis = { version = "0.23.1", features = ["r2d2", "ahash", "cluster", "tokio-com serde = { version = "1.0.178", features = ["derive"] } tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.4.3", features = ["cors"] } -uuid = { version = "1.4.1", features = ["v5", "serde"] } diff --git a/todored/src/op.rs b/todored/src/op.rs index ee56699..ffc3e06 100644 --- a/todored/src/op.rs +++ b/todored/src/op.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use uuid::Uuid; use super::task::Task; @@ -9,7 +8,7 @@ pub enum ClientOperation { /// Set the board's title. Title(String), /// Create a new [`Task`], or update or delete the task with the given [`Uuid`]. - Task(Option, Option), + Task(Option, Option), } /// An operation sent from the server to the clients, and stored on the database. @@ -18,5 +17,32 @@ pub enum ServerOperation { /// Set the board's title. Title(String), /// Create, update, or delete the [`Task`] with the given [`Uuid`]. - Task(Uuid, Option), + Task(u64, Option), +} + +impl ClientOperation { + fn handle(self) { + todo!() + } +} + +impl ServerOperation { + fn store(&self, rconn: redis::aio::Connection, board: &str) -> Result<()> { + log::debug!("Storing ServerOperation in Redis: {:?}", &self); + + log::trace!("Serializing ServerOperation to JSON..."); + let data = serde_json::ser::to_string(self) + .expect_or_500_and_log("Failed to serialize ServerOperation"); + + log::trace!("Computing Redis key..."); + let stream_key = format!("board:{{{board}}}:stream"); + + log::trace!("Adding to the Redis stream {stream_key:?}..."); + let response = redis::cmd("XADD") + .arg(stream_key) + .arg() + + + Ok(()) + } }