diff --git a/src/StackExchange.Redis/Enums/ExpireResult.cs b/src/StackExchange.Redis/Enums/ExpireResult.cs index 90b660104..825bc5710 100644 --- a/src/StackExchange.Redis/Enums/ExpireResult.cs +++ b/src/StackExchange.Redis/Enums/ExpireResult.cs @@ -3,24 +3,24 @@ namespace StackExchange.Redis; /// -/// Specifies when to set the expiry for a key. +/// Specifies the result of operation to set expire time. /// public enum ExpireResult { /// - /// Set expiry whether or not there is an existing expiry. + /// Field deleted because the specified expiration time is due, /// Due = 2, /// - /// Set expiry only when the new expiry is greater than current one. + /// Expiration time/duration updated successfully /// Success = 1, /// - /// Set expiry only when the key has an existing expiry. + /// Expiration not set because of a specified NX | XX | GT | LT condition not met /// ConditionNotMet = 0, /// - /// Set expiry only when the key has no expiry. + /// No such field. /// NoSuchField = -2, diff --git a/src/StackExchange.Redis/Enums/HashFieldFlags.cs b/src/StackExchange.Redis/Enums/HashFieldFlags.cs index f38b6c348..e901e3512 100644 --- a/src/StackExchange.Redis/Enums/HashFieldFlags.cs +++ b/src/StackExchange.Redis/Enums/HashFieldFlags.cs @@ -15,59 +15,46 @@ public enum HashFieldFlags /// No options specified. /// None = 0, + /// /// When DC (“Don’t Create”) is specified: if key does not exist: do nothing (don’t create key) /// - DC = 1, + DontCreate = 1, + /// /// When DCF (“Don’t Create Fields”) is specified: for each specified field: if the field already exists: set the field's value and expiration time; ignore fields that do not exist /// - DCF = 2, + DontCreateFields = 2, + /// /// When DOF (“Don’t Overwrite Fields”) is specified: for each specified field: if such field does not exist: create field and set its value and expiration time; ignore fields that already exists /// - DOF = 4, + DontOverwriteFields = 4, + /// /// When GETNEW is specified: returns the new value of given fields /// - GETNEW = 8, + GetNew = 8, + /// /// When GETOLD is specified: returns the old value of given fields /// - GETOLD = 16, + GetOld = 16, } internal static class HashFieldFlagsExtensions { - internal static bool isNone(this HashFieldFlags flags) => - flags == HashFieldFlags.None; - internal static bool isDC(this HashFieldFlags flags) => - flags.HasFlag(HashFieldFlags.DC); - - internal static bool isDCF(this HashFieldFlags flags) => - flags.HasFlag(HashFieldFlags.DCF); - - internal static bool isDOF(this HashFieldFlags flags) => - flags.HasFlag(HashFieldFlags.DOF); - - internal static bool isGETNEW(this HashFieldFlags flags) => - flags.HasFlag(HashFieldFlags.GETNEW); - - internal static bool isGETOLD(this HashFieldFlags flags) => - flags.HasFlag(HashFieldFlags.GETOLD); - + internal static bool HasAny(this HashFieldFlags value, HashFieldFlags flag) => (value & flag) != 0; internal static List ToRedisValueList(this HashFieldFlags flags) { List values = new(); - if (flags.isNone()) return values; - if (flags.isDC()) values.Add(HashFieldFlags.DC.ToString()); - if (flags.isDCF()) values.Add(HashFieldFlags.DCF.ToString()); - if (flags.isDOF()) values.Add(HashFieldFlags.DOF.ToString()); - if (flags.isGETNEW()) values.Add(HashFieldFlags.GETNEW.ToString()); - if (flags.isGETOLD()) values.Add(HashFieldFlags.GETOLD.ToString()); + if (flags == HashFieldFlags.None) return values; + if (flags.HasAny(HashFieldFlags.DontCreate)) values.Add(RedisLiterals.DC); + if (flags.HasAny(HashFieldFlags.DontCreateFields)) values.Add(RedisLiterals.DCF); + if (flags.HasAny(HashFieldFlags.DontOverwriteFields)) values.Add(RedisLiterals.DOF); + if (flags.HasAny(HashFieldFlags.GetNew)) values.Add(RedisLiterals.GETNEW); + if (flags.HasAny(HashFieldFlags.GetOld)) values.Add(RedisLiterals.GETOLD); return values; - } - } diff --git a/src/StackExchange.Redis/Enums/PersistResult.cs b/src/StackExchange.Redis/Enums/PersistResult.cs new file mode 100644 index 000000000..acee5141d --- /dev/null +++ b/src/StackExchange.Redis/Enums/PersistResult.cs @@ -0,0 +1,22 @@ +using System; + +namespace StackExchange.Redis; + +/// +/// Specifies the result of operation to remove the expire time. +/// +public enum PersistResult +{ + /// + /// Expiration removed successfully + /// + Success = 1, + /// + /// Expiration not removed because of a specified NX | XX | GT | LT condition not met + /// + ConditionNotMet = -1, + /// + /// No such field. + /// + NoSuchField = -2, +} diff --git a/src/StackExchange.Redis/Interfaces/IDatabase.cs b/src/StackExchange.Redis/Interfaces/IDatabase.cs index d44bc4d43..9ad2a9d6e 100644 --- a/src/StackExchange.Redis/Interfaces/IDatabase.cs +++ b/src/StackExchange.Redis/Interfaces/IDatabase.cs @@ -405,7 +405,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long? HashFieldExpireTime(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + long? HashFieldGetExpireDateTime(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it gets the expiration time as a Unix timestamp in milliseconds (milliseconds since the Unix epoch) @@ -418,7 +418,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long[]? HashFieldExpireTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + long[]? HashFieldGetExpireDateTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// For specified field, it removes the expiration time @@ -431,7 +431,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + PersistResult? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it removes the expiration time @@ -444,7 +444,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + PersistResult[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// For specified field, it gets the remaining time to live in milliseconds @@ -457,7 +457,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long? HashFieldTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + long? HashFieldGetTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it gets the remaining time to live in milliseconds @@ -470,7 +470,7 @@ public interface IDatabase : IRedis, IDatabaseAsync /// -1: if field has no associated expiration time /// -2: no such field /// - long[]? HashFieldTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + long[]? HashFieldGetTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// Returns the value associated with field in the hash stored at key. diff --git a/src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs b/src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs index f65af5e48..2ef2dd839 100644 --- a/src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs +++ b/src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs @@ -391,7 +391,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldExpireTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it gets the expiration time as a Unix timestamp in milliseconds (milliseconds since the Unix epoch) @@ -404,7 +404,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldExpireTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// For specified field, it removes the expiration time @@ -417,7 +417,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it removes the expiration time @@ -430,7 +430,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// For specified field, it gets the remaining time to live in milliseconds @@ -443,7 +443,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); + Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it gets the remaining time to live in milliseconds @@ -456,7 +456,7 @@ public interface IDatabaseAsync : IRedisAsync /// -1: if field has no associated expiration time /// -2: no such field /// - Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); + Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None); /// /// For each specified field, it gets the value and sets the field's remaining time to live diff --git a/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs b/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs index 704f62b53..9c356cd1b 100644 --- a/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs +++ b/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixed.cs @@ -96,23 +96,23 @@ public Task HashExistsAsync(RedisKey key, RedisValue hashField, CommandFla public Task HashFieldExpireAsync(RedisKey key, RedisValue[] hashFields, DateTime expiry, ExpireWhen when = ExpireWhen.Always, CommandFlags flags = CommandFlags.None) => Inner.HashFieldExpireAsync(ToInner(key), hashFields, expiry, when, flags); - public Task HashFieldExpireTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => - Inner.HashFieldExpireTimeAsync(ToInner(key), hashField, flags); + public Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => + Inner.HashFieldGetExpireDateTimeAsync(ToInner(key), hashField, flags); - public Task HashFieldExpireTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => - Inner.HashFieldExpireTimeAsync(ToInner(key), hashFields, flags); + public Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + Inner.HashFieldGetExpireDateTimeAsync(ToInner(key), hashFields, flags); - public Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => + public Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => Inner.HashFieldPersistAsync(ToInner(key), hashField, flags); - public Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + public Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => Inner.HashFieldPersistAsync(ToInner(key), hashFields, flags); - public Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => - Inner.HashFieldTimeToLiveAsync(ToInner(key), hashField, flags); + public Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags) => + Inner.HashFieldGetTimeToLiveAsync(ToInner(key), hashField, flags); - public Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => - Inner.HashFieldTimeToLiveAsync(ToInner(key), hashFields, flags); + public Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + Inner.HashFieldGetTimeToLiveAsync(ToInner(key), hashFields, flags); public Task HashGetAndSetExpiryAsync(RedisKey key, RedisValue[] hashFields, TimeSpan expireDuration, ExpireWhen when, CommandFlags flags) => Inner.HashGetAndSetExpiryAsync(ToInner(key), hashFields, expireDuration, when, flags); diff --git a/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedDatabase.cs b/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedDatabase.cs index 2ecfdaf05..94cbbe161 100644 --- a/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedDatabase.cs +++ b/src/StackExchange.Redis/KeyspaceIsolation/KeyPrefixedDatabase.cs @@ -93,23 +93,23 @@ public bool HashExists(RedisKey key, RedisValue hashField, CommandFlags flags = public ExpireResult[]? HashFieldExpire(RedisKey key, RedisValue[] hashFields, DateTime expiry, ExpireWhen when = ExpireWhen.Always, CommandFlags flags = CommandFlags.None) => Inner.HashFieldExpire(ToInner(key), hashFields, expiry, when, flags); - public long? HashFieldExpireTime(RedisKey key, RedisValue hashField, CommandFlags flags) => - Inner.HashFieldExpireTime(ToInner(key), hashField, flags); + public long? HashFieldGetExpireDateTime(RedisKey key, RedisValue hashField, CommandFlags flags) => + Inner.HashFieldGetExpireDateTime(ToInner(key), hashField, flags); - public long[]? HashFieldExpireTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => - Inner.HashFieldExpireTime(ToInner(key), hashFields, flags); + public long[]? HashFieldGetExpireDateTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + Inner.HashFieldGetExpireDateTime(ToInner(key), hashFields, flags); - public long? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags) => + public PersistResult? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags) => Inner.HashFieldPersist(ToInner(key), hashField, flags); - public long[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + public PersistResult[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => Inner.HashFieldPersist(ToInner(key), hashFields, flags); - public long? HashFieldTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags) => - Inner.HashFieldTimeToLive(ToInner(key), hashField, flags); + public long? HashFieldGetTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags) => + Inner.HashFieldGetTimeToLive(ToInner(key), hashField, flags); - public long[]? HashFieldTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => - Inner.HashFieldTimeToLive(ToInner(key), hashFields, flags); + public long[]? HashFieldGetTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags) => + Inner.HashFieldGetTimeToLive(ToInner(key), hashFields, flags); public HashEntry[] HashGetAll(RedisKey key, CommandFlags flags = CommandFlags.None) => Inner.HashGetAll(ToInner(key), flags); diff --git a/src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt b/src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt index df6cc78a9..e455b4044 100644 --- a/src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt +++ b/src/StackExchange.Redis/PublicAPI/PublicAPI.Shipped.txt @@ -463,11 +463,11 @@ StackExchange.Redis.HashEntry.Key.get -> StackExchange.Redis.RedisValue StackExchange.Redis.HashEntry.Name.get -> StackExchange.Redis.RedisValue StackExchange.Redis.HashEntry.Value.get -> StackExchange.Redis.RedisValue StackExchange.Redis.HashFieldFlags -StackExchange.Redis.HashFieldFlags.DC = 1 -> StackExchange.Redis.HashFieldFlags -StackExchange.Redis.HashFieldFlags.DCF = 2 -> StackExchange.Redis.HashFieldFlags -StackExchange.Redis.HashFieldFlags.DOF = 4 -> StackExchange.Redis.HashFieldFlags -StackExchange.Redis.HashFieldFlags.GETNEW = 8 -> StackExchange.Redis.HashFieldFlags -StackExchange.Redis.HashFieldFlags.GETOLD = 16 -> StackExchange.Redis.HashFieldFlags +StackExchange.Redis.HashFieldFlags.DontCreate = 1 -> StackExchange.Redis.HashFieldFlags +StackExchange.Redis.HashFieldFlags.DontCreateFields = 2 -> StackExchange.Redis.HashFieldFlags +StackExchange.Redis.HashFieldFlags.DontOverwriteFields = 4 -> StackExchange.Redis.HashFieldFlags +StackExchange.Redis.HashFieldFlags.GetNew = 8 -> StackExchange.Redis.HashFieldFlags +StackExchange.Redis.HashFieldFlags.GetOld = 16 -> StackExchange.Redis.HashFieldFlags StackExchange.Redis.HashFieldFlags.None = 0 -> StackExchange.Redis.HashFieldFlags StackExchange.Redis.HashSlotMovedEventArgs StackExchange.Redis.HashSlotMovedEventArgs.HashSlot.get -> int @@ -555,12 +555,12 @@ StackExchange.Redis.IDatabase.HashFieldExpire(StackExchange.Redis.RedisKey key, StackExchange.Redis.IDatabase.HashFieldExpire(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, System.TimeSpan expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.ExpireResult? StackExchange.Redis.IDatabase.HashFieldExpire(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, System.DateTime expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.ExpireResult[]? StackExchange.Redis.IDatabase.HashFieldExpire(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, System.TimeSpan expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.ExpireResult[]? -StackExchange.Redis.IDatabase.HashFieldExpireTime(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long? -StackExchange.Redis.IDatabase.HashFieldExpireTime(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long[]? -StackExchange.Redis.IDatabase.HashFieldPersist(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long? -StackExchange.Redis.IDatabase.HashFieldPersist(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long[]? -StackExchange.Redis.IDatabase.HashFieldTimeToLive(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long? -StackExchange.Redis.IDatabase.HashFieldTimeToLive(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long[]? +StackExchange.Redis.IDatabase.HashFieldGetExpireDateTime(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long? +StackExchange.Redis.IDatabase.HashFieldGetExpireDateTime(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long[]? +StackExchange.Redis.IDatabase.HashFieldPersist(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.PersistResult? +StackExchange.Redis.IDatabase.HashFieldPersist(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.PersistResult[]? +StackExchange.Redis.IDatabase.HashFieldGetTimeToLive(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long? +StackExchange.Redis.IDatabase.HashFieldGetTimeToLive(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> long[]? StackExchange.Redis.IDatabase.HashGet(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.RedisValue StackExchange.Redis.IDatabase.HashGet(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.RedisValue[]! StackExchange.Redis.IDatabase.HashGetAndSetExpiry(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, System.DateTime expireTime, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> StackExchange.Redis.RedisValue[]? @@ -802,12 +802,12 @@ StackExchange.Redis.IDatabaseAsync.HashFieldExpireAsync(StackExchange.Redis.Redi StackExchange.Redis.IDatabaseAsync.HashFieldExpireAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, System.TimeSpan expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! StackExchange.Redis.IDatabaseAsync.HashFieldExpireAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, System.DateTime expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! StackExchange.Redis.IDatabaseAsync.HashFieldExpireAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, System.TimeSpan expiry, StackExchange.Redis.ExpireWhen when = StackExchange.Redis.ExpireWhen.Always, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldExpireTimeAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldExpireTimeAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldPersistAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldPersistAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldTimeToLiveAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! -StackExchange.Redis.IDatabaseAsync.HashFieldTimeToLiveAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldGetExpireDateTimeAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldGetExpireDateTimeAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldPersistAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldPersistAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldGetTimeToLiveAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! +StackExchange.Redis.IDatabaseAsync.HashFieldGetTimeToLiveAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! StackExchange.Redis.IDatabaseAsync.HashGetAllAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! StackExchange.Redis.IDatabaseAsync.HashGetAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue hashField, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! StackExchange.Redis.IDatabaseAsync.HashGetAsync(StackExchange.Redis.RedisKey key, StackExchange.Redis.RedisValue[]! hashFields, StackExchange.Redis.CommandFlags flags = StackExchange.Redis.CommandFlags.None) -> System.Threading.Tasks.Task! @@ -1271,6 +1271,10 @@ StackExchange.Redis.NameValueEntry.Value.get -> StackExchange.Redis.RedisValue StackExchange.Redis.Order StackExchange.Redis.Order.Ascending = 0 -> StackExchange.Redis.Order StackExchange.Redis.Order.Descending = 1 -> StackExchange.Redis.Order +StackExchange.Redis.PersistResult +StackExchange.Redis.PersistResult.ConditionNotMet = -1 -> StackExchange.Redis.PersistResult +StackExchange.Redis.PersistResult.NoSuchField = -2 -> StackExchange.Redis.PersistResult +StackExchange.Redis.PersistResult.Success = 1 -> StackExchange.Redis.PersistResult StackExchange.Redis.Profiling.IProfiledCommand StackExchange.Redis.Profiling.IProfiledCommand.Command.get -> string! StackExchange.Redis.Profiling.IProfiledCommand.CommandCreated.get -> System.DateTime diff --git a/src/StackExchange.Redis/RedisDatabase.cs b/src/StackExchange.Redis/RedisDatabase.cs index 20a3c1dd3..5c7fe9ec7 100644 --- a/src/StackExchange.Redis/RedisDatabase.cs +++ b/src/StackExchange.Redis/RedisDatabase.cs @@ -479,62 +479,62 @@ private T HashFieldExecute(RedisCommand cmd, RedisKey key, CustomExecutor< #endregion helper stuff for HFE - public long? HashFieldExpireTime(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public long? HashFieldGetExpireDateTime(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPEXPIRETIME, key, SyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); } - public long[]? HashFieldExpireTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public long[]? HashFieldGetExpireDateTime(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPEXPIRETIME, key, SyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); } - public Task HashFieldExpireTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPEXPIRETIME, key, AsyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); } - public Task HashFieldExpireTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public Task HashFieldGetExpireDateTimeAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPEXPIRETIME, key, AsyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); } - public long? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public PersistResult? HashFieldPersist(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { - return HashFieldExecute(RedisCommand.HPERSIST, key, SyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); + return HashFieldExecute(RedisCommand.HPERSIST, key, SyncCustomExecutor>, ResultProcessor.PersistResult, flags, hashField); } - public long[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public PersistResult[]? HashFieldPersist(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { - return HashFieldExecute(RedisCommand.HPERSIST, key, SyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); + return HashFieldExecute(RedisCommand.HPERSIST, key, SyncCustomArrExecutor>, ResultProcessor.PersistResultArray, flags, hashFields); } - public Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public Task HashFieldPersistAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { - return HashFieldExecute(RedisCommand.HPERSIST, key, AsyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); + return HashFieldExecute(RedisCommand.HPERSIST, key, AsyncCustomExecutor>, ResultProcessor.PersistResult, flags, hashField); } - public Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public Task HashFieldPersistAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { - return HashFieldExecute(RedisCommand.HPERSIST, key, AsyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); + return HashFieldExecute(RedisCommand.HPERSIST, key, AsyncCustomArrExecutor>, ResultProcessor.PersistResultArray, flags, hashFields); } - public long? HashFieldTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public long? HashFieldGetTimeToLive(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPTTL, key, SyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); } - public long[]? HashFieldTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public long[]? HashFieldGetTimeToLive(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPTTL, key, SyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); } - public Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) + public Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPTTL, key, AsyncCustomExecutor>, ResultProcessor.NullableInt64, flags, hashField); } - public Task HashFieldTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) + public Task HashFieldGetTimeToLiveAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None) { return HashFieldExecute(RedisCommand.HPTTL, key, AsyncCustomArrExecutor>, ResultProcessor.Int64NullableArray, flags, hashFields); } diff --git a/src/StackExchange.Redis/RedisLiterals.cs b/src/StackExchange.Redis/RedisLiterals.cs index 2f54a8fff..ab56a97f2 100644 --- a/src/StackExchange.Redis/RedisLiterals.cs +++ b/src/StackExchange.Redis/RedisLiterals.cs @@ -69,9 +69,12 @@ public static readonly RedisValue COPY = "COPY", COUNT = "COUNT", DB = "DB", + DC = "DC", + DCF = "DCF", @default = "default", DESC = "DESC", DOCTOR = "DOCTOR", + DOF = "DOF", ENCODING = "ENCODING", EX = "EX", EXAT = "EXAT", @@ -84,6 +87,8 @@ public static readonly RedisValue GET = "GET", GETKEYS = "GETKEYS", GETNAME = "GETNAME", + GETNEW = "GETNEW", + GETOLD = "GETOLD", GT = "GT", HISTORY = "HISTORY", ID = "ID", diff --git a/src/StackExchange.Redis/ResultProcessor.cs b/src/StackExchange.Redis/ResultProcessor.cs index 297adf974..e9340dc01 100644 --- a/src/StackExchange.Redis/ResultProcessor.cs +++ b/src/StackExchange.Redis/ResultProcessor.cs @@ -72,6 +72,10 @@ public static readonly ResultProcessor public static readonly ResultProcessor ExpireResultArray = new ExpireResultArrayProcessor(); + public static readonly ResultProcessor PersistResult = new PersistResultProcessor(); + + public static readonly ResultProcessor PersistResultArray = new PersistResultArrayProcessor(); + public static readonly ResultProcessor RedisChannelArrayLiteral = new RedisChannelArrayProcessor(RedisChannel.PatternMode.Literal); @@ -911,7 +915,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes if (message?.Command == RedisCommand.CONFIG) { var iter = result.GetItems().GetEnumerator(); - while(iter.MoveNext()) + while (iter.MoveNext()) { ref RawResult key = ref iter.Current; if (!iter.MoveNext()) break; @@ -1513,6 +1517,53 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes } } + + private sealed class PersistResultProcessor : ResultProcessor + { + protected override bool SetResultCore(PhysicalConnection connection, Message message, in RawResult result) + { + switch (result.Resp2TypeBulkString) + { + case ResultType.BulkString: + if (result.IsNull) + { + SetResult(message, null); + return true; + } + break; + case ResultType.Array: + var items = result.GetItems(); + if (items.Length == 1) + { // treat an array of 1 like a single reply (for example, SCRIPT EXISTS) + if (items[0].TryGetInt64(out long value)) + { + SetResult(message, (PersistResult)value); + return true; + } + } + break; + } + return false; + + } + } + + + private sealed class PersistResultArrayProcessor : ResultProcessor + { + protected override bool SetResultCore(PhysicalConnection connection, Message message, in RawResult result) + { + if (result.Resp2TypeArray == ResultType.Array || result.IsNull) + { + var arr = result.ToArray((in RawResult x) => (PersistResult)(long)x.AsRedisValue())!; + + SetResult(message, arr); + return true; + } + return false; + } + } + private sealed class RedisChannelArrayProcessor : ResultProcessor { private readonly RedisChannel.PatternMode mode; @@ -2341,7 +2392,7 @@ internal static bool TryRead(Sequence pairs, in CommandBytes key, ref internal static bool TryRead(Sequence pairs, in CommandBytes key, ref int value) { long tmp = default; - if(TryRead(pairs, key, ref tmp)) + if (TryRead(pairs, key, ref tmp)) { value = checked((int)tmp); return true; diff --git a/tests/StackExchange.Redis.Tests/HashFieldTests.cs b/tests/StackExchange.Redis.Tests/HashFieldTests.cs index 4bb91c0bc..296623f37 100644 --- a/tests/StackExchange.Redis.Tests/HashFieldTests.cs +++ b/tests/StackExchange.Redis.Tests/HashFieldTests.cs @@ -107,7 +107,7 @@ public async void HashFieldExpireAsyncNoKey() } [Fact] - public void HashFieldExpireTimeIsDue() + public void HashFieldGetExpireDateTimeIsDue() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); @@ -177,7 +177,7 @@ public void HashFieldExpireConditionsNotSatisfied() } [Fact] - public void HashFieldExpireTime() + public void HashFieldGetExpireDateTime() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); @@ -185,10 +185,10 @@ public void HashFieldExpireTime() db.HashFieldExpire(hashKey, fields, nextCentury); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); - var result = db.HashFieldExpireTime(hashKey, "f1"); + var result = db.HashFieldGetExpireDateTime(hashKey, "f1"); Assert.Equal(ms, result); - var fieldsResult = db.HashFieldExpireTime(hashKey, fields); + var fieldsResult = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new[] { ms, ms }, fieldsResult); } @@ -199,43 +199,43 @@ public void HashFieldExpireFieldNoExpireTime() var hashKey = Me(); db.HashSet(hashKey, entries); - var result = db.HashFieldExpireTime(hashKey, "f1"); + var result = db.HashFieldGetExpireDateTime(hashKey, "f1"); Assert.Equal(-1, result); - var fieldsResult = db.HashFieldExpireTime(hashKey, fields); + var fieldsResult = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1, }, fieldsResult); } [Fact] - public void HashFieldExpireTimeNoKey() + public void HashFieldGetExpireDateTimeNoKey() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); - var result = db.HashFieldExpireTime(hashKey, "f1"); + var result = db.HashFieldGetExpireDateTime(hashKey, "f1"); Assert.Null(result); - var fieldsResult = db.HashFieldExpireTime(hashKey, fields); + var fieldsResult = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Null(fieldsResult); } [Fact] - public void HashFieldExpireTimeNoField() + public void HashFieldGetExpireDateTimeNoField() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); db.HashSet(hashKey, entries); db.HashFieldExpire(hashKey, fields, oneYearInMs); - var result = db.HashFieldExpireTime(hashKey, "notExistingField1"); + var result = db.HashFieldGetExpireDateTime(hashKey, "notExistingField1"); Assert.Equal(-2, result); - var fieldsResult = db.HashFieldExpireTime(hashKey, new RedisValue[] { "notExistingField1", "notExistingField2" }); + var fieldsResult = db.HashFieldGetExpireDateTime(hashKey, new RedisValue[] { "notExistingField1", "notExistingField2" }); Assert.Equal(new long[] { -2, -2, }, fieldsResult); } [Fact] - public void HashFieldTimeToLive() + public void HashFieldGetTimeToLive() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); @@ -243,55 +243,55 @@ public void HashFieldTimeToLive() db.HashFieldExpire(hashKey, fields, oneYearInMs); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); - var result = db.HashFieldTimeToLive(hashKey, "f1"); + var result = db.HashFieldGetTimeToLive(hashKey, "f1"); Assert.NotNull(result); Assert.True(result > 0); - var fieldsResult = db.HashFieldTimeToLive(hashKey, fields); + var fieldsResult = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(fieldsResult); Assert.True(fieldsResult.Length > 0); Assert.True(fieldsResult.All(x => x > 0)); } [Fact] - public void HashFieldTimeToLiveNoExpireTime() + public void HashFieldGetTimeToLiveNoExpireTime() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); db.HashSet(hashKey, entries); - var result = db.HashFieldTimeToLive(hashKey, "f1"); + var result = db.HashFieldGetTimeToLive(hashKey, "f1"); Assert.Equal(-1, result); - var fieldsResult = db.HashFieldTimeToLive(hashKey, fields); + var fieldsResult = db.HashFieldGetTimeToLive(hashKey, fields); Assert.Equal(new long[] { -1, -1, }, fieldsResult); } [Fact] - public void HashFieldTimeToLiveNoKey() + public void HashFieldGetTimeToLiveNoKey() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); - var result = db.HashFieldTimeToLive(hashKey, "f1"); + var result = db.HashFieldGetTimeToLive(hashKey, "f1"); Assert.Null(result); - var fieldsResult = db.HashFieldTimeToLive(hashKey, fields); + var fieldsResult = db.HashFieldGetTimeToLive(hashKey, fields); Assert.Null(fieldsResult); } [Fact] - public void HashFieldTimeToLiveNoField() + public void HashFieldGetTimeToLiveNoField() { var db = Create(require: RedisFeatures.v7_2_0_rc1).GetDatabase(); var hashKey = Me(); db.HashSet(hashKey, entries); db.HashFieldExpire(hashKey, fields, oneYearInMs); - var result = db.HashFieldTimeToLive(hashKey, "notExistingField1"); + var result = db.HashFieldGetTimeToLive(hashKey, "notExistingField1"); Assert.Equal(-2, result); - var fieldsResult = db.HashFieldTimeToLive(hashKey, new RedisValue[] { "notExistingField1", "notExistingField2" }); + var fieldsResult = db.HashFieldGetTimeToLive(hashKey, new RedisValue[] { "notExistingField1", "notExistingField2" }); Assert.Equal(new long[] { -2, -2, }, fieldsResult); } @@ -305,12 +305,12 @@ public void HashFieldPersist() long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); var result = db.HashFieldPersist(hashKey, "f1"); - Assert.Equal(1, result); + Assert.Equal(PersistResult.Success, result); db.HashFieldExpire(hashKey, fields, oneYearInMs); var fieldsResult = db.HashFieldPersist(hashKey, fields); - Assert.Equal(new long[] { 1, 1, }, fieldsResult); + Assert.Equal(new[] { PersistResult.Success, PersistResult.Success }, fieldsResult); } [Fact] @@ -321,10 +321,10 @@ public void HashFieldPersistNoExpireTime() db.HashSet(hashKey, entries); var result = db.HashFieldPersist(hashKey, "f1"); - Assert.Equal(-1, result); + Assert.Equal(PersistResult.ConditionNotMet, result); var fieldsResult = db.HashFieldPersist(hashKey, fields); - Assert.Equal(new long[] { -1, -1, }, fieldsResult); + Assert.Equal(new[] { PersistResult.ConditionNotMet, PersistResult.ConditionNotMet }, fieldsResult); } [Fact] @@ -349,10 +349,10 @@ public void HashFieldPersistNoField() db.HashFieldExpire(hashKey, fields, oneYearInMs); var result = db.HashFieldPersist(hashKey, "notExistingField1"); - Assert.Equal(-2, result); + Assert.Equal(PersistResult.NoSuchField, result); var fieldsResult = db.HashFieldPersist(hashKey, new RedisValue[] { "notExistingField1", "notExistingField2" }); - Assert.Equal(new long[] { -2, -2, }, fieldsResult); + Assert.Equal(new[] { PersistResult.NoSuchField, PersistResult.NoSuchField }, fieldsResult); } [Fact] @@ -365,7 +365,7 @@ public void HashFieldGet() var fieldsResult = db.HashGetAndSetExpiry(hashKey, fields, oneYearInMs); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var ttlResults = db.HashFieldTimeToLive(hashKey, fields); + var ttlResults = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(ttlResults); Assert.True(ttlResults.Length > 0); Assert.True(ttlResults.All(x => x > 0)); @@ -373,7 +373,7 @@ public void HashFieldGet() fieldsResult = db.HashGetAndSetExpiry(hashKey, fields, nextCentury); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var expireDates = db.HashFieldExpireTime(hashKey, fields); + var expireDates = db.HashFieldGetExpireDateTime(hashKey, fields); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); Assert.Equal(new[] { ms, ms }, expireDates); @@ -381,7 +381,7 @@ public void HashFieldGet() fieldsResult = db.HashGetAndPersistFields(hashKey, fields); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var fieldsNoExpireDates = db.HashFieldExpireTime(hashKey, fields); + var fieldsNoExpireDates = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1 }, fieldsNoExpireDates); } @@ -395,7 +395,7 @@ public void HashFieldGetWithExpireConditions() var fieldsResult = db.HashGetAndSetExpiry(hashKey, fields, oneYearInMs, ExpireWhen.HasNoExpiry); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var ttlResults = db.HashFieldTimeToLive(hashKey, fields); + var ttlResults = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(ttlResults); Assert.True(ttlResults.Length > 0); Assert.True(ttlResults.All(x => x > 0)); @@ -403,7 +403,7 @@ public void HashFieldGetWithExpireConditions() fieldsResult = db.HashGetAndSetExpiry(hashKey, fields, nextCentury, ExpireWhen.HasNoExpiry); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var expireDates = db.HashFieldExpireTime(hashKey, fields); + var expireDates = db.HashFieldGetExpireDateTime(hashKey, fields); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); Assert.NotEqual(new[] { ms, ms }, expireDates); @@ -411,7 +411,7 @@ public void HashFieldGetWithExpireConditions() fieldsResult = db.HashGetAndPersistFields(hashKey, fields); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var fieldsNoExpireDates = db.HashFieldExpireTime(hashKey, fields); + var fieldsNoExpireDates = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1 }, fieldsNoExpireDates); } @@ -455,7 +455,7 @@ public void HashFieldSet() var fieldsResult = db.HashSetAndSetExpiry(hashKey, new[] { new HashEntry("f1", 1), new HashEntry("f2", 2) }, oneYearInMs); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var ttlResults = db.HashFieldTimeToLive(hashKey, fields); + var ttlResults = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(ttlResults); Assert.True(ttlResults.Length > 0); Assert.True(ttlResults.All(x => x > 0)); @@ -463,14 +463,14 @@ public void HashFieldSet() fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, nextCentury); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var expireDates = db.HashFieldExpireTime(hashKey, fields); + var expireDates = db.HashFieldGetExpireDateTime(hashKey, fields); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); Assert.Equal(new[] { ms, ms }, expireDates); fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, false); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var fieldsNoExpireDates = db.HashFieldExpireTime(hashKey, fields); + var fieldsNoExpireDates = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1 }, fieldsNoExpireDates); } @@ -513,7 +513,7 @@ public void HashFieldSetWithExpireConditions() var fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var ttlResults = db.HashFieldTimeToLive(hashKey, fields); + var ttlResults = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(ttlResults); Assert.True(ttlResults.Length > 0); Assert.True(ttlResults.All(x => x > 0)); @@ -521,14 +521,14 @@ public void HashFieldSetWithExpireConditions() fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, nextCentury, ExpireWhen.HasNoExpiry); Assert.Equal(new RedisValue[] { 1, 1, }, fieldsResult); - var expireDates = db.HashFieldExpireTime(hashKey, fields); + var expireDates = db.HashFieldGetExpireDateTime(hashKey, fields); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); Assert.NotEqual(new[] { ms, ms }, expireDates); fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, false); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var fieldsNoExpireDates = db.HashFieldExpireTime(hashKey, fields); + var fieldsNoExpireDates = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1 }, fieldsNoExpireDates); } @@ -539,32 +539,32 @@ public void HashFieldSetWithFlags() var hashKey = Me(); db.KeyDelete(hashKey); - var fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DC); + var fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DontCreate); Assert.Null(fieldsResult); - fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DCF); + fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DontCreateFields); Assert.Null(fieldsResult); - fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DOF); + fieldsResult = db.HashSetAndSetExpiry(hashKey, entries, oneYearInMs, ExpireWhen.HasNoExpiry, HashFieldFlags.DontOverwriteFields); Assert.Equal(new RedisValue[] { 3, 3 }, fieldsResult); - var ttlResults = db.HashFieldTimeToLive(hashKey, fields); + var ttlResults = db.HashFieldGetTimeToLive(hashKey, fields); Assert.NotNull(ttlResults); Assert.True(ttlResults.Length > 0); Assert.True(ttlResults.All(x => x > 0)); - fieldsResult = db.HashSetAndSetExpiry(hashKey, new HashEntry[] { new("f1", "a"), new("f2", "b") }, nextCentury, ExpireWhen.HasNoExpiry, HashFieldFlags.GETOLD); + fieldsResult = db.HashSetAndSetExpiry(hashKey, new HashEntry[] { new("f1", "a"), new("f2", "b") }, nextCentury, ExpireWhen.HasNoExpiry, HashFieldFlags.GetOld); Assert.Equal(entries.Select(i => i.Value).ToArray(), fieldsResult); - var expireDates = db.HashFieldExpireTime(hashKey, fields); + var expireDates = db.HashFieldGetExpireDateTime(hashKey, fields); long ms = new DateTimeOffset(nextCentury).ToUnixTimeMilliseconds(); Assert.NotEqual(new[] { ms, ms }, expireDates); - fieldsResult = db.HashSetAndSetExpiry(hashKey, new HashEntry[] { new("f1", "x"), new("f2", "y") }, false, HashFieldFlags.GETNEW); + fieldsResult = db.HashSetAndSetExpiry(hashKey, new HashEntry[] { new("f1", "x"), new("f2", "y") }, false, HashFieldFlags.GetNew); Assert.Equal(new RedisValue[] { "x", "y" }, fieldsResult); - var fieldsNoExpireDates = db.HashFieldExpireTime(hashKey, fields); + var fieldsNoExpireDates = db.HashFieldGetExpireDateTime(hashKey, fields); Assert.Equal(new long[] { -1, -1 }, fieldsNoExpireDates); } }