@@ -1014,7 +1014,8 @@ def restore(self, name, ttl, value, replace=False, absttl=False):
1014
1014
return self .execute_command ('RESTORE' , * params )
1015
1015
1016
1016
def set (self , name , value ,
1017
- ex = None , px = None , nx = False , xx = False , keepttl = False , get = False ):
1017
+ ex = None , px = None , nx = False , xx = False , keepttl = False , get = False ,
1018
+ exat = None , pxat = None ):
1018
1019
"""
1019
1020
Set the value at key ``name`` to ``value``
1020
1021
@@ -1034,6 +1035,12 @@ def set(self, name, value,
1034
1035
``get`` if True, set the value at key ``name`` to ``value`` and return
1035
1036
the old value stored at key, or None when key did not exist.
1036
1037
(Available since Redis 6.2)
1038
+
1039
+ ``exat`` sets an expire flag on key ``name`` for ``ex`` seconds,
1040
+ specified in unix time.
1041
+
1042
+ ``pxat`` sets an expire flag on key ``name`` for ``ex`` milliseconds,
1043
+ specified in unix time.
1037
1044
"""
1038
1045
pieces = [name , value ]
1039
1046
options = {}
@@ -1047,15 +1054,26 @@ def set(self, name, value,
1047
1054
if isinstance (px , datetime .timedelta ):
1048
1055
px = int (px .total_seconds () * 1000 )
1049
1056
pieces .append (px )
1057
+ if exat is not None :
1058
+ pieces .append ('EXAT' )
1059
+ if isinstance (exat , datetime .datetime ):
1060
+ s = int (exat .microsecond / 1000000 )
1061
+ exat = int (time .mktime (exat .timetuple ())) + s
1062
+ pieces .append (exat )
1063
+ if pxat is not None :
1064
+ pieces .append ('PXAT' )
1065
+ if isinstance (pxat , datetime .datetime ):
1066
+ ms = int (pxat .microsecond / 1000 )
1067
+ pxat = int (time .mktime (pxat .timetuple ())) * 1000 + ms
1068
+ pieces .append (pxat )
1069
+ if keepttl :
1070
+ pieces .append ('KEEPTTL' )
1050
1071
1051
1072
if nx :
1052
1073
pieces .append ('NX' )
1053
1074
if xx :
1054
1075
pieces .append ('XX' )
1055
1076
1056
- if keepttl :
1057
- pieces .append ('KEEPTTL' )
1058
-
1059
1077
if get :
1060
1078
pieces .append ('GET' )
1061
1079
options ["get" ] = True
0 commit comments