@@ -409,21 +409,33 @@ var _ = Describe("Commands", func() {
409409 })
410410
411411 It ("should ExpireAt" , func () {
412- set := client .Set (ctx , "key" , "Hello" , 0 )
413- Expect (set .Err ()).NotTo (HaveOccurred ())
414- Expect (set .Val ()).To (Equal ("OK" ))
412+ setCmd := client .Set (ctx , "key" , "Hello" , 0 )
413+ Expect (setCmd .Err ()).NotTo (HaveOccurred ())
414+ Expect (setCmd .Val ()).To (Equal ("OK" ))
415415
416416 n , err := client .Exists (ctx , "key" ).Result ()
417417 Expect (err ).NotTo (HaveOccurred ())
418418 Expect (n ).To (Equal (int64 (1 )))
419419
420- expireAt := client .ExpireAt (ctx , "key" , time .Now ().Add (- time .Hour ))
421- Expect (expireAt .Err ()).NotTo (HaveOccurred ())
422- Expect (expireAt .Val ()).To (Equal (true ))
420+ // Check correct expiration time is set in the future
421+ expireAt := time .Now ().Add (time .Minute )
422+ expireAtCmd := client .ExpireAt (ctx , "key" , expireAt )
423+ Expect (expireAtCmd .Err ()).NotTo (HaveOccurred ())
424+ Expect (expireAtCmd .Val ()).To (Equal (true ))
425+
426+ timeCmd := client .ExpireTime (ctx , "key" )
427+ Expect (timeCmd .Err ()).NotTo (HaveOccurred ())
428+ Expect (timeCmd .Val ().Seconds ()).To (BeNumerically ("==" , expireAt .Unix ()))
429+
430+ // Check correct expiration in the past
431+ expireAtCmd = client .ExpireAt (ctx , "key" , time .Now ().Add (- time .Hour ))
432+ Expect (expireAtCmd .Err ()).NotTo (HaveOccurred ())
433+ Expect (expireAtCmd .Val ()).To (Equal (true ))
423434
424435 n , err = client .Exists (ctx , "key" ).Result ()
425436 Expect (err ).NotTo (HaveOccurred ())
426437 Expect (n ).To (Equal (int64 (0 )))
438+
427439 })
428440
429441 It ("should Keys" , func () {
@@ -569,6 +581,28 @@ var _ = Describe("Commands", func() {
569581 Expect (pttl .Val ()).To (BeNumerically ("~" , expiration , 100 * time .Millisecond ))
570582 })
571583
584+ It ("should PExpireTime" , func () {
585+
586+ // The command returns -1 if the key exists but has no associated expiration time.
587+ // The command returns -2 if the key does not exist.
588+ pExpireTime := client .PExpireTime (ctx , "key" )
589+ Expect (pExpireTime .Err ()).NotTo (HaveOccurred ())
590+ Expect (pExpireTime .Val () < 0 ).To (Equal (true ))
591+
592+ set := client .Set (ctx , "key" , "hello" , 0 )
593+ Expect (set .Err ()).NotTo (HaveOccurred ())
594+ Expect (set .Val ()).To (Equal ("OK" ))
595+
596+ timestamp := time .Now ().Add (time .Minute )
597+ expireAt := client .PExpireAt (ctx , "key" , timestamp )
598+ Expect (expireAt .Err ()).NotTo (HaveOccurred ())
599+ Expect (expireAt .Val ()).To (Equal (true ))
600+
601+ pExpireTime = client .PExpireTime (ctx , "key" )
602+ Expect (pExpireTime .Err ()).NotTo (HaveOccurred ())
603+ Expect (pExpireTime .Val ().Milliseconds ()).To (BeNumerically ("==" , timestamp .UnixMilli ()))
604+ })
605+
572606 It ("should PTTL" , func () {
573607 set := client .Set (ctx , "key" , "Hello" , 0 )
574608 Expect (set .Err ()).NotTo (HaveOccurred ())
@@ -786,7 +820,32 @@ var _ = Describe("Commands", func() {
786820 Expect (touch .Val ()).To (Equal (int64 (2 )))
787821 })
788822
823+ It ("should ExpireTime" , func () {
824+
825+ // The command returns -1 if the key exists but has no associated expiration time.
826+ // The command returns -2 if the key does not exist.
827+ expireTimeCmd := client .ExpireTime (ctx , "key" )
828+ Expect (expireTimeCmd .Err ()).NotTo (HaveOccurred ())
829+ Expect (expireTimeCmd .Val () < 0 ).To (Equal (true ))
830+
831+ set := client .Set (ctx , "key" , "hello" , 0 )
832+ Expect (set .Err ()).NotTo (HaveOccurred ())
833+ Expect (set .Val ()).To (Equal ("OK" ))
834+
835+ expireAt := time .Now ().Add (time .Minute )
836+ expireAtCmd := client .ExpireAt (ctx , "key" , expireAt )
837+ Expect (expireAtCmd .Err ()).NotTo (HaveOccurred ())
838+ Expect (expireAtCmd .Val ()).To (Equal (true ))
839+
840+ expireTimeCmd = client .ExpireTime (ctx , "key" )
841+ Expect (expireTimeCmd .Err ()).NotTo (HaveOccurred ())
842+ Expect (expireTimeCmd .Val ().Seconds ()).To (BeNumerically ("==" , expireAt .Unix ()))
843+ })
844+
789845 It ("should TTL" , func () {
846+
847+ // The command returns -1 if the key exists but has no associated expire
848+ // The command returns -2 if the key does not exist.
790849 ttl := client .TTL (ctx , "key" )
791850 Expect (ttl .Err ()).NotTo (HaveOccurred ())
792851 Expect (ttl .Val () < 0 ).To (Equal (true ))
0 commit comments