Skip to content

Commit 5e791df

Browse files
Rename SetScript variants. (#38928)
1 parent 7672ca9 commit 5e791df

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Caching/StackExchangeRedis/src/RedisCache.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ public class RedisCache : IDistributedCache, IDisposable
1818
{
1919
// -- Explanation of why two kinds of SetScript are used --
2020
// * Redis 2.0 had HSET key field value for setting individual hash fields,
21-
// and HMSET key field value [field value ...] for setting multiple hash fields (against the same key)
22-
// * Redis 4.0 observes this redundancy, and adds HSET key field value [field value ...],
23-
// and also marks HMSET as deprecated, although it still works fine.
24-
// But HSET doesn't allows multiple field/value pairs for Redis prior 4.0.
21+
// and HMSET key field value [field value ...] for setting multiple hash fields (against the same key).
22+
// * Redis 4.0 added HSET key field value [field value ...] and deprecated HMSET.
23+
//
24+
// On Redis versions that don't have the newer HSET variant, we use SetScriptPreExtendedSetCommand
25+
// which uses the (now deprecated) HMSET.
2526

2627
// KEYS[1] = = key
2728
// ARGV[1] = absolute-expiration - ticks as long (-1 for none)
2829
// ARGV[2] = sliding-expiration - ticks as long (-1 for none)
2930
// ARGV[3] = relative-expiration (long, in seconds, -1 for none) - Min(absolute-expiration - Now, sliding-expiration)
3031
// ARGV[4] = data - byte[]
3132
// this order should not change LUA script depends on it
32-
private const string SetScriptPerExtendedSetCommand = (@"
33+
private const string SetScript = (@"
3334
redis.call('HSET', KEYS[1], 'absexp', ARGV[1], 'sldexp', ARGV[2], 'data', ARGV[4])
3435
if ARGV[3] ~= '-1' then
3536
redis.call('EXPIRE', KEYS[1], ARGV[3])
3637
end
3738
return 1");
38-
private const string DeprecatedSetScript = (@"
39+
private const string SetScriptPreExtendedSetCommand = (@"
3940
redis.call('HMSET', KEYS[1], 'absexp', ARGV[1], 'sldexp', ARGV[2], 'data', ARGV[4])
4041
if ARGV[3] ~= '-1' then
4142
redis.call('EXPIRE', KEYS[1], ARGV[3])
@@ -51,7 +52,7 @@ public class RedisCache : IDistributedCache, IDisposable
5152
private volatile IConnectionMultiplexer _connection;
5253
private IDatabase _cache;
5354
private bool _disposed;
54-
private string _setScript = SetScriptPerExtendedSetCommand;
55+
private string _setScript = SetScript;
5556

5657
private readonly RedisCacheOptions _options;
5758
private readonly string _instance;
@@ -287,7 +288,7 @@ private void ValidateServerFeatures()
287288
{
288289
if (_connection.GetServer(endPoint).Version < ServerVersionWithExtendedSetCommand)
289290
{
290-
_setScript = DeprecatedSetScript;
291+
_setScript = SetScriptPreExtendedSetCommand;
291292
return;
292293
}
293294
}

0 commit comments

Comments
 (0)