Skip to content

Commit c3bc304

Browse files
authored
Fix expiration and upppercase check (#72)
1 parent 31e3a7d commit c3bc304

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/cmd/set.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ impl Set {
9292

9393
// Attempt to parse another string.
9494
match parse.next_string() {
95-
Ok(s) if s == "EX" => {
95+
Ok(s) if s.to_uppercase() == "EX" => {
9696
// An expiration is specified in seconds. The next value is an
9797
// integer.
9898
let secs = parse.next_int()?;
9999
expire = Some(Duration::from_secs(secs));
100100
}
101-
Ok(s) if s == "PX" => {
101+
Ok(s) if s.to_uppercase() == "PX" => {
102102
// An expiration is specified in milliseconds. The next value is
103103
// an integer.
104104
let ms = parse.next_int()?;
@@ -146,6 +146,16 @@ impl Set {
146146
frame.push_bulk(Bytes::from("set".as_bytes()));
147147
frame.push_bulk(Bytes::from(self.key.into_bytes()));
148148
frame.push_bulk(self.value);
149+
if let Some(ms) = self.expire {
150+
// Expirations in Redis procotol can be specified in two ways
151+
// 1. SET key value EX seconds
152+
// 2. SET key value PX milliseconds
153+
// We the second option because it allows greater precision and
154+
// src/bin/cli.rs parses the expiration argument as milliseconds
155+
// in duration_from_ms_str()
156+
frame.push_bulk(Bytes::from("px".as_bytes()));
157+
frame.push_int(ms.as_millis() as u64);
158+
}
149159
frame
150160
}
151161
}

0 commit comments

Comments
 (0)