Skip to content

Commit

Permalink
Simplifying the script restoring the last value of the key
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzyk committed Jul 8, 2016
1 parent ece16d8 commit fba976e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Microsoft.AspNet.SignalR.Redis/RedisConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,19 @@ public async Task RestoreLatestValueForKey(int database, string key)
{
try
{
// Workaround for StackExchange.Redis/issues/61 that sometimes Redis connection is not connected in ConnectionRestored event
// Workaround for StackExchange.Redis/issues/61 that sometimes Redis connection is not connected in ConnectionRestored event
while (!_connection.GetDatabase(database).IsConnected(key))
{
await Task.Delay(200);
}

var redisResult = await _connection.GetDatabase(database).ScriptEvaluateAsync(
@"local newvalue=-1
if redis.call('EXISTS', KEYS[1]) == 1 then
newvalue = tonumber(redis.call('GET', KEYS[1]))
end
if newvalue < tonumber(ARGV[1]) then
return redis.call('SET', KEYS[1], ARGV[1])
else
return nil
end",
@"local newvalue = redis.call('GET', KEYS[1])
if not newvalue or newvalue < ARGV[1] then
return redis.call('SET', KEYS[1], ARGV[1])
else
return nil
end",
new RedisKey[] { key },
new RedisValue[] { _latestMessageId });

Expand Down

0 comments on commit fba976e

Please sign in to comment.