From fba976ea9a617a32bb3c4450ea7ca1f33c21d7fd Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 8 Jul 2016 11:42:29 -0700 Subject: [PATCH] Simplifying the script restoring the last value of the key --- .../RedisConnection.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.SignalR.Redis/RedisConnection.cs b/src/Microsoft.AspNet.SignalR.Redis/RedisConnection.cs index e1f341ca2a..8f48cb2b3b 100644 --- a/src/Microsoft.AspNet.SignalR.Redis/RedisConnection.cs +++ b/src/Microsoft.AspNet.SignalR.Redis/RedisConnection.cs @@ -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 });