From 7a264e870629f09fdfaed138cd80320841293be2 Mon Sep 17 00:00:00 2001 From: An Long Date: Tue, 8 Sep 2026 23:46:13 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Return=20errors=20from=20binary?= =?UTF-8?q?=20prepend=20and=20map=20the=20NOT=5FSTORED=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error.rs | 1 + src/protocol/binary.rs | 2 +- tests/tests.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index aab511a..add8109 100644 --- a/src/error.rs +++ b/src/error.rs @@ -125,6 +125,7 @@ impl From for CommandError { 0x2 => CommandError::KeyExists, 0x3 => CommandError::ValueTooLarge, 0x4 => CommandError::InvalidArguments, + 0x5 => CommandError::KeyNotFound, 0x20 => CommandError::AuthenticationRequired, e => CommandError::Unknown(e), } diff --git a/src/protocol/binary.rs b/src/protocol/binary.rs index 1af0f0e..36de433 100644 --- a/src/protocol/binary.rs +++ b/src/protocol/binary.rs @@ -158,7 +158,7 @@ impl ProtocolTrait for BinaryProtocol { self.stream.write_all(key.as_bytes())?; value.write_to(&mut self.stream)?; self.stream.flush()?; - binary_packet::parse_response(&mut self.stream).map(|_| ()) + binary_packet::parse_response(&mut self.stream)?.err().map(|_| ()) } fn delete(&mut self, key: &str) -> Result { diff --git a/tests/tests.rs b/tests/tests.rs index e1ffe5c..06845d7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -113,6 +113,21 @@ fn udp_test() { let value: Option = client.get("foo").unwrap(); assert_eq!(value, None); + assert!(matches!( + client.append("foo", "bar"), + Err(memcache::MemcacheError::CommandError( + memcache::CommandError::KeyNotFound + )) + )); + assert!(matches!( + client.prepend("foo", "bar"), + Err(memcache::MemcacheError::CommandError( + memcache::CommandError::KeyNotFound + )) + )); + let value: Option = client.get("foo").unwrap(); + assert_eq!(value, None); + client.add("foo", "bar", 0).unwrap(); let value: Option = client.get("foo").unwrap(); assert_eq!(value, Some(String::from("bar")));