Skip to content

Commit

Permalink
Avoid exceptions accessing nonexistent etags in RedisGrainStorage (#9147
Browse files Browse the repository at this point in the history
)

* Properly translate null etags

* Handle nulls on the LUA side
  • Loading branch information
hendrikdevloed authored Oct 1, 2024
1 parent 9c5a1b6 commit ac1a3b5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Redis/Orleans.Persistence.Redis/Storage/RedisGrainStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -149,7 +149,7 @@ public async Task WriteStateAsync<T>(string grainType, GrainId grainId, IGrainSt
const string WriteScript =
"""
local etag = redis.call('HGET', KEYS[1], 'etag')
if (not etag and (ARGV[1] == nil or ARGV[1] == '')) or etag == ARGV[1] then
if ((not etag or etag == '') and (not ARGV[1] or ARGV[1] == '')) or etag == ARGV[1] then
redis.call('HMSET', KEYS[1], 'etag', ARGV[2], 'data', ARGV[3])
if ARGV[4] ~= '-1' then
redis.call('EXPIRE', KEYS[1], ARGV[4])
Expand Down Expand Up @@ -234,7 +234,7 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainId, IGrainSt
const string DeleteScript =
"""
local etag = redis.call('HGET', KEYS[1], 'etag')
if (not etag and not ARGV[1]) or etag == ARGV[1] then
if ((not etag or etag == '') and (not ARGV[1] or ARGV[1] == '')) or etag == ARGV[1] then
redis.call('DEL', KEYS[1])
return 0
else
Expand All @@ -249,7 +249,7 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainId, IGrainSt
const string ClearScript =
"""
local etag = redis.call('HGET', KEYS[1], 'etag')
if (not etag and not ARGV[1]) or etag == ARGV[1] then
if ((not etag or etag == '') and (not ARGV[1] or ARGV[1] == '')) or etag == ARGV[1] then
redis.call('HMSET', KEYS[1], 'etag', ARGV[2], 'data', '')
return 0
else
Expand Down Expand Up @@ -282,4 +282,4 @@ private async Task Close(CancellationToken cancellationToken)
_connection.Dispose();
}
}
}
}

0 comments on commit ac1a3b5

Please sign in to comment.