Skip to content

Commit d6982ee

Browse files
authored
Maintain ttl on update (#340)
1 parent dc2e33e commit d6982ee

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Redis.OM/Scripts.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ local second_op
8181
/// Unlinks a JSON object and sets the key again with a fresh new JSON object.
8282
/// </summary>
8383
internal const string UnlinkAndSendJson = @"
84+
local expiry = tonumber(redis.call('PTTL', KEYS[1]))
8485
redis.call('UNLINK', KEYS[1])
8586
redis.call('JSON.SET', KEYS[1], '.', ARGV[1])
87+
if expiry > 0 then
88+
redis.call('PEXPIRE', KEYS[1], expiry)
89+
end
8690
return 0
8791
";
8892

@@ -100,8 +104,8 @@ local second_op
100104
redis.call('HSET', KEYS[1], unpack(hashArgs))
101105
if expiry > 0 then
102106
redis.call('PEXPIRE', KEYS[1], expiry)
103-
end
104-
return 1
107+
end
108+
return 1
105109
end
106110
return 0
107111
";
@@ -151,7 +155,7 @@ local second_op
151155
/// <summary>
152156
/// The scripts.
153157
/// </summary>
154-
internal static readonly Dictionary<string, string> ScriptCollection = new ()
158+
internal static readonly Dictionary<string, string> ScriptCollection = new()
155159
{
156160
{ nameof(JsonDiffResolution), JsonDiffResolution },
157161
{ nameof(HashDiffResolution), HashDiffResolution },
@@ -166,6 +170,6 @@ local second_op
166170
/// <summary>
167171
/// Gets or sets collection of SHAs.
168172
/// </summary>
169-
internal static ConcurrentDictionary<string, string> ShaCollection { get; set; } = new ();
173+
internal static ConcurrentDictionary<string, string> ShaCollection { get; set; } = new();
170174
}
171-
}
175+
}

0 commit comments

Comments
 (0)