Commit 74b1ce0a authored by Marc Gravell's avatar Marc Gravell

implement KeyIdleTime (OBJECT IDLETIME) - #449

parent 21f0f32c
......@@ -498,6 +498,15 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>https://redis.io/commands/persist</remarks>
bool KeyExpire(RedisKey key, DateTime? expiry, CommandFlags flags = CommandFlags.None);
/// <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="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>
TimeSpan? KeyIdleTime(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Move key from the currently selected database (see SELECT) to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.
/// </summary>
......
......@@ -461,6 +461,15 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>https://redis.io/commands/persist</remarks>
Task<bool> KeyExpireAsync(RedisKey key, DateTime? expiry, CommandFlags flags = CommandFlags.None);
/// <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="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>
Task<TimeSpan?> KeyIdleTimeAsync(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Move key from the currently selected database (see SELECT) to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.
/// </summary>
......
......@@ -226,6 +226,11 @@ public bool KeyExpire(RedisKey key, TimeSpan? expiry, CommandFlags flags = Comma
return Inner.KeyExpire(ToInner(key), expiry, flags);
}
public TimeSpan? KeyIdleTime(RedisKey key, CommandFlags flags = CommandFlags.None)
{
return Inner.KeyIdleTime(ToInner(key), flags);
}
public void KeyMigrate(RedisKey key, EndPoint toServer, int toDatabase = 0, int timeoutMilliseconds = 0, MigrateOptions migrateOptions = MigrateOptions.None, CommandFlags flags = CommandFlags.None)
{
Inner.KeyMigrate(ToInner(key), toServer, toDatabase, timeoutMilliseconds, migrateOptions, flags);
......
......@@ -208,6 +208,11 @@ public Task<bool> KeyExpireAsync(RedisKey key, TimeSpan? expiry, CommandFlags fl
return Inner.KeyExpireAsync(ToInner(key), expiry, flags);
}
public Task<TimeSpan?> KeyIdleTimeAsync(RedisKey key,CommandFlags flags = CommandFlags.None)
{
return Inner.KeyIdleTimeAsync(ToInner(key), flags);
}
public Task KeyMigrateAsync(RedisKey key, EndPoint toServer, int toDatabase = 0, int timeoutMilliseconds = 0, MigrateOptions migrateOptions = MigrateOptions.None, CommandFlags flags = CommandFlags.None)
{
return Inner.KeyMigrateAsync(ToInner(key), toServer, toDatabase, timeoutMilliseconds, migrateOptions, flags);
......
......@@ -648,6 +648,17 @@ public Task<bool> KeyExpireAsync(RedisKey key, DateTime? expiry, CommandFlags fl
return ExecuteAsync(msg, ResultProcessor.Boolean, server: server);
}
public TimeSpan? KeyIdleTime(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.OBJECT, RedisLiterals.IDLETIME, key);
return ExecuteSync(msg, ResultProcessor.TimeSpanFromSeconds);
}
public Task<TimeSpan?> KeyIdleTimeAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.OBJECT, RedisLiterals.IDLETIME, key);
return ExecuteAsync(msg, ResultProcessor.TimeSpanFromSeconds);
}
public void KeyMigrate(RedisKey key, EndPoint toServer, int toDatabase = 0, int timeoutMilliseconds = 0, MigrateOptions migrateOptions = MigrateOptions.None, CommandFlags flags = CommandFlags.None)
{
if (timeoutMilliseconds <= 0) timeoutMilliseconds = multiplexer.TimeoutMilliseconds;
......
using System;
using System;
using System.Text;
namespace StackExchange.Redis
......@@ -25,6 +25,7 @@ public static readonly RedisValue
GET = "GET",
GETNAME = "GETNAME",
ID = "ID",
IDLETIME = "IDLETIME",
KILL = "KILL",
LIMIT = "LIMIT",
LIST = "LIST",
......
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