@@ -92,13 +92,13 @@ impl Set {
92
92
93
93
// Attempt to parse another string.
94
94
match parse. next_string ( ) {
95
- Ok ( s) if s == "EX" => {
95
+ Ok ( s) if s. to_uppercase ( ) == "EX" => {
96
96
// An expiration is specified in seconds. The next value is an
97
97
// integer.
98
98
let secs = parse. next_int ( ) ?;
99
99
expire = Some ( Duration :: from_secs ( secs) ) ;
100
100
}
101
- Ok ( s) if s == "PX" => {
101
+ Ok ( s) if s. to_uppercase ( ) == "PX" => {
102
102
// An expiration is specified in milliseconds. The next value is
103
103
// an integer.
104
104
let ms = parse. next_int ( ) ?;
@@ -146,6 +146,16 @@ impl Set {
146
146
frame. push_bulk ( Bytes :: from ( "set" . as_bytes ( ) ) ) ;
147
147
frame. push_bulk ( Bytes :: from ( self . key . into_bytes ( ) ) ) ;
148
148
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
+ }
149
159
frame
150
160
}
151
161
}
0 commit comments