Skip to content

Commit 3395d06

Browse files
committed
Encode the command manually
1 parent b8f2739 commit 3395d06

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/cmd.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@ impl<'a, T: FromRedisValue> Iterator for Iter<'a, T> {
6565
}
6666

6767
fn encode_command(args: &Vec<Arg>, cursor: u64) -> Vec<u8> {
68-
let mut cmd = vec![];
69-
cmd.extend(format!("*{}\r\n", args.len()).as_bytes().iter().cloned());
68+
let mut cmd = Vec::with_capacity(8192);
69+
cmd.push('*' as u8);
70+
cmd.extend(args.len().to_string().as_bytes());
71+
cmd.push('\r' as u8);
72+
cmd.push('\n' as u8);
7073

7174
{
7275
let mut encode = |item: &[u8]| {
73-
cmd.extend(format!("${}\r\n", item.len()).as_bytes().iter().cloned());
74-
cmd.extend(item.iter().cloned());
75-
cmd.extend(b"\r\n".iter().cloned());
76+
cmd.push('$' as u8);
77+
cmd.extend(item.len().to_string().as_bytes());
78+
cmd.push('\r' as u8);
79+
cmd.push('\n' as u8);
80+
cmd.extend(item.iter());
81+
cmd.push('\r' as u8);
82+
cmd.push('\n' as u8);
7683
};
7784

7885
for item in args.iter() {

0 commit comments

Comments
 (0)