Commit 30bbb4b6 authored by Nick Craver's avatar Nick Craver

Tests: add KeyIdleTime, and fix the null case

The return differs on OBJECT IDLETIME, it's a bulkstring null when the key does not exist...handle it accordingly.
parent d1e47873
......@@ -512,7 +512,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <summary>
/// Returns the time since the object stored at the specified key is idle (not requested by read or write operations)
/// </summary>
/// <param name="key">The key to get the type of.</param>
/// <param name="key">The key to get the time of.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The time since the object stored at the specified key is idle</returns>
/// <remarks>https://redis.io/commands/object</remarks>
......
......@@ -476,7 +476,7 @@ public interface IDatabaseAsync : IRedisAsync
/// <summary>
/// Returns the time since the object stored at the specified key is idle (not requested by read or write operations)
/// </summary>
/// <param name="key">The key to get the type of.</param>
/// <param name="key">The key to get the time of.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The time since the object stored at the specified key is idle</returns>
/// <remarks>https://redis.io/commands/object</remarks>
......
......@@ -295,6 +295,10 @@ public bool TryParse(RawResult result, out TimeSpan? expiry)
return true;
}
break;
// e.g. OBJECT IDLETIME on a key that doesn't exist
case ResultType.BulkString when result.IsNull:
expiry = null;
return true;
}
expiry = null;
return false;
......
using System.Linq;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
......@@ -105,5 +107,28 @@ public void PrependAppend()
Assert.Equal("helloworld", (string)key3);
}
}
[Fact]
public async Task IdleTime()
{
using (var muxer = Create())
{
RedisKey key = Me();
var db = muxer.GetDatabase();
db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringSet(key, "new value", flags: CommandFlags.FireAndForget);
await Task.Delay(2000).ForAwait();
var idleTime = db.KeyIdleTime(key);
Assert.True(idleTime > TimeSpan.Zero);
db.StringSet(key, "new value2", flags: CommandFlags.FireAndForget);
var idleTime2 = db.KeyIdleTime(key);
Assert.True(idleTime2 < idleTime);
db.KeyDelete(key);
var idleTime3 = db.KeyIdleTime(key);
Assert.Null(idleTime3);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment