1use crate::ValkeyResult;
5use crate::cmd::Cmd;
6use crate::executor::CommandExecutor;
7use crate::value::FromValkeyValue;
8use crate::value::ValkeyValue;
9use crate::write::ToValkeyArgs;
10use async_trait::async_trait;
11use bytes::Bytes;
12
13#[async_trait]
15pub trait StringCommands: CommandExecutor {
16 async fn lcs_len<K1: ToValkeyArgs + Send, K2: ToValkeyArgs + Send>(
18 &self,
19 key1: K1,
20 key2: K2,
21 ) -> ValkeyResult<i64> {
22 let mut cmd = Cmd::new();
23 cmd.arg("LCS").arg(key1).arg(key2).arg("LEN");
24 i64::from_owned_valkey_value(self.execute_command(cmd, None).await?)
25 }
26
27 async fn lcs<K1: ToValkeyArgs + Send, K2: ToValkeyArgs + Send>(
29 &self,
30 key1: K1,
31 key2: K2,
32 ) -> ValkeyResult<Bytes> {
33 let mut cmd = Cmd::new();
34 cmd.arg("LCS").arg(key1).arg(key2);
35 Bytes::from_owned_valkey_value(self.execute_command(cmd, None).await?)
36 }
37
38 async fn lcs_idx<K1: ToValkeyArgs + Send, K2: ToValkeyArgs + Send>(
42 &self,
43 key1: K1,
44 key2: K2,
45 min_match_len: Option<i64>,
46 with_match_len: bool,
47 ) -> ValkeyResult<ValkeyValue> {
48 let mut cmd = Cmd::new();
49 cmd.arg("LCS").arg(key1).arg(key2).arg("IDX");
50 if let Some(m) = min_match_len {
51 cmd.arg("MINMATCHLEN").arg(m);
52 }
53 if with_match_len {
54 cmd.arg("WITHMATCHLEN");
55 }
56 self.execute_command(cmd, None).await
57 }
58}
59
60impl<T: CommandExecutor + ?Sized> StringCommands for T {}