File tree Expand file tree Collapse file tree 4 files changed +121
-77
lines changed Expand file tree Collapse file tree 4 files changed +121
-77
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,6 @@ namespace cpp_redis {
169169 return client_->pexpire (std::move (keys_[0 ]), milliseconds);
170170 }
171171
172-
173172 template <typename T>
174173 bool expire_at (T&& key, std::size_t unix_timestamp)
175174 {
@@ -221,7 +220,6 @@ namespace cpp_redis {
221220 return client_->remove_expire (std::move (keys_[0 ]));
222221 }
223222
224-
225223 template <typename T>
226224 int remainder_ttl (T&& key)
227225 {
@@ -239,6 +237,23 @@ namespace cpp_redis {
239237 return client_->remainder_ttl (std::move (keys_[0 ]));
240238 }
241239
240+ template <typename T>
241+ int remainder_pttl (T&& key)
242+ {
243+ if (client_ == nullptr ) {
244+ return -1 ;
245+ }
246+
247+ reset ();
248+ any_type_to_string (key);
249+
250+ if (keys_.empty ()) {
251+ return -1 ;
252+ }
253+
254+ return client_->remainder_pttl (std::move (keys_[0 ]));
255+ }
256+
242257 template <typename T1,typename T2>
243258 bool rename_key (T1&& src_key, T2&&new_key){
244259 if (client_ == nullptr ) {
Original file line number Diff line number Diff line change @@ -212,6 +212,30 @@ namespace cpp_redis {
212212 return int_results[0 ];
213213 }
214214
215+ // key的剩余时间 -1:表示永久 -2:表示不存在
216+ int64_t remainder_pttl (std::string&& key)
217+ {
218+ check_args ();
219+
220+ std::string msg = request_->req_n_key (request_->get_cmd (redis_cmd::pttl),
221+ std::forward<std::string>(key));
222+
223+ socket_->send_msg (std::move (msg));
224+ const auto res = socket_->get_responese ();
225+
226+ if (res->get_result_code () != status::int_result_) {
227+ return -2 ;
228+ }
229+
230+ const auto int_results = res->get_int_results ();
231+ if (int_results.empty ()) {
232+ return -2 ;
233+ }
234+
235+ return int_results[0 ];
236+ }
237+
238+
215239 bool rename_key (std::string&& key,std::string &&new_key)
216240 {
217241 check_args ();
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ namespace cpp_redis {
1919 const std::string g_pexpire_at_cmd = " PEXPIREAT" ;
2020 const std::string g_remove_expire_cmd = " PERSIST" ;
2121 const std::string g_ttl_cmd = " TTL" ;
22+ const std::string g_pttl_cmd = " PTTL" ;
2223 const std::string g_rename_cmd = " RENAME" ;
2324 const std::string g_renamenx_cmd = " RENAMENX" ;
2425 const std::string g_multi_cmd = " MULTI" ;// ¿ªÆôÊÂÎñ
@@ -144,81 +145,82 @@ namespace cpp_redis {
144145 pexpire_at = 17 ,
145146 remove_expire = 18 ,
146147 ttl = 19 ,
147- multi = 20 ,
148- exec = 21 ,
149- discard = 22 ,
150- rename = 23 ,
151- renamenx = 24 ,
152- get_set = 25 ,
153- substr = 26 ,
154- mget = 27 ,
155- mset = 28 ,
156- msetnx = 29 ,
157- append = 30 ,
158- rpush = 31 ,
159- lpush = 32 ,
160- llen = 33 ,
161- lrange = 34 ,
162- rpop = 35 ,
163- lpop = 36 ,
164- brpop = 37 ,
165- blpop = 38 ,
166- ltrim = 39 ,
167- lindex = 40 ,
168- lset = 41 ,
169- lrem = 42 ,
170- rpoplpush = 43 ,
171- lpushx = 44 ,
172- rpushx = 45 ,
173- list_insert = 46 ,
174- brpoplpush = 47 ,
175- sadd = 48 ,
176- srem = 49 ,
177- sismember = 50 ,
178- spop_elem = 51 ,
179- srandmember = 52 ,
180- smove = 53 ,
181- ssize = 54 ,
182- smembers = 55 ,
183- sinter = 56 ,
184- ssinter_store = 57 ,
185- sunion = 58 ,
186- ssunion_store = 59 ,
187- sdiff = 60 ,
188- sdiff_store = 61 ,
189- zset_add = 62 ,
190- zset_score = 63 ,
191- zset_incrby = 64 ,
192- zset_card = 65 ,
193- zset_count = 66 ,
194- zset_range = 67 ,
195- zset_rank = 68 ,
196- zset_rem = 69 ,
197- zset_revrank = 70 ,
198- zset_revrange = 71 ,
199- zset_lexcount = 72 ,
200- zset_rangebylex = 73 ,
201- zset_union_store = 74 ,
202- zset_inter_store = 75 ,
203- zset_range_score = 76 ,
204- zset_remrangebylex = 77 ,
205- zset_rerange_score = 78 ,
206- zset_remrangebyscore = 79 ,
207- zset_remrangeby_rank = 80 ,
208- hash_set = 81 ,
209- hash_setx = 82 ,
210- hash_exists = 83 ,
211- hash_get = 84 ,
212- hash_del = 85 ,
213- hash_len = 86 ,
214- hash_mset = 87 ,
215- hash_mget = 88 ,
216- hash_vals = 89 ,
217- hash_keys = 90 ,
218- hash_strlen = 91 ,
219- hash_incrby = 92 ,
220- hash_get_all = 93 ,
221- hash_incrby_float = 94 ,
148+ pttl = 20 ,
149+ multi = 21 ,
150+ exec = 22 ,
151+ discard = 23 ,
152+ rename = 24 ,
153+ renamenx = 25 ,
154+ get_set = 26 ,
155+ substr = 27 ,
156+ mget = 28 ,
157+ mset = 29 ,
158+ msetnx = 30 ,
159+ append = 31 ,
160+ rpush = 32 ,
161+ lpush = 33 ,
162+ llen = 34 ,
163+ lrange = 35 ,
164+ rpop = 36 ,
165+ lpop = 37 ,
166+ brpop = 38 ,
167+ blpop = 39 ,
168+ ltrim = 40 ,
169+ lindex = 41 ,
170+ lset = 42 ,
171+ lrem = 43 ,
172+ rpoplpush = 44 ,
173+ lpushx = 45 ,
174+ rpushx = 46 ,
175+ list_insert = 47 ,
176+ brpoplpush = 48 ,
177+ sadd = 49 ,
178+ srem = 50 ,
179+ sismember = 51 ,
180+ spop_elem = 52 ,
181+ srandmember = 53 ,
182+ smove = 54 ,
183+ ssize = 55 ,
184+ smembers = 56 ,
185+ sinter = 57 ,
186+ ssinter_store = 58 ,
187+ sunion = 59 ,
188+ ssunion_store = 60 ,
189+ sdiff = 61 ,
190+ sdiff_store = 62 ,
191+ zset_add = 63 ,
192+ zset_score = 64 ,
193+ zset_incrby = 65 ,
194+ zset_card = 66 ,
195+ zset_count = 67 ,
196+ zset_range = 68 ,
197+ zset_rank = 69 ,
198+ zset_rem = 70 ,
199+ zset_revrank = 71 ,
200+ zset_revrange = 72 ,
201+ zset_lexcount = 73 ,
202+ zset_rangebylex = 74 ,
203+ zset_union_store = 75 ,
204+ zset_inter_store = 76 ,
205+ zset_range_score = 77 ,
206+ zset_remrangebylex = 78 ,
207+ zset_rerange_score = 79 ,
208+ zset_remrangebyscore = 80 ,
209+ zset_remrangeby_rank = 81 ,
210+ hash_set = 82 ,
211+ hash_setx = 83 ,
212+ hash_exists = 84 ,
213+ hash_get = 85 ,
214+ hash_del = 86 ,
215+ hash_len = 87 ,
216+ hash_mset = 88 ,
217+ hash_mget = 89 ,
218+ hash_vals = 90 ,
219+ hash_keys = 91 ,
220+ hash_strlen = 92 ,
221+ hash_incrby = 93 ,
222+ hash_get_all = 94 ,
223+ hash_incrby_float = 95 ,
222224 };
223225
224226 enum request_type
Original file line number Diff line number Diff line change @@ -81,6 +81,9 @@ namespace cpp_redis {
8181 case cpp_redis::ttl:
8282 cmd_str = g_ttl_cmd;
8383 break ;
84+ case redis_cmd::pttl:
85+ cmd_str = g_pttl_cmd;
86+ break ;
8487 case cpp_redis::rename:
8588 cmd_str = g_rename_cmd;
8689 break ;
You can’t perform that action at this time.
0 commit comments