Skip to content

Support for new HGETDEL, HGETEX and HSETEX commands #2863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/StackExchange.Redis/Enums/RedisCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ internal enum RedisCommand
HEXPIREAT,
HEXPIRETIME,
HGET,
HGETEX,
HGETDEL,
HGETALL,
HINCRBY,
HINCRBYFLOAT,
Expand All @@ -85,6 +87,7 @@ internal enum RedisCommand
HRANDFIELD,
HSCAN,
HSET,
HSETEX,
HSETNX,
HSTRLEN,
HVALS,
Expand Down Expand Up @@ -289,13 +292,16 @@ internal static bool IsPrimaryOnly(this RedisCommand command)
case RedisCommand.HDEL:
case RedisCommand.HEXPIRE:
case RedisCommand.HEXPIREAT:
case RedisCommand.HGETDEL:
case RedisCommand.HGETEX:
case RedisCommand.HINCRBY:
case RedisCommand.HINCRBYFLOAT:
case RedisCommand.HMSET:
case RedisCommand.HPERSIST:
case RedisCommand.HPEXPIRE:
case RedisCommand.HPEXPIREAT:
case RedisCommand.HSET:
case RedisCommand.HSETEX:
case RedisCommand.HSETNX:
case RedisCommand.INCR:
case RedisCommand.INCRBY:
Expand Down
143 changes: 143 additions & 0 deletions src/StackExchange.Redis/Interfaces/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,149 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks><seealso href="https://redis.io/commands/hmget"/></remarks>
RedisValue[] HashGet(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Returns the value associated with field in the hash stored at key.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value associated with field, or <see cref="RedisValue.Null"/> when field is not present in the hash or key does not exist.</returns>
/// <remarks><seealso href="https://redis.io/commands/hget"/></remarks>
RedisValue HashFieldGetAndDelete(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Returns the value associated with field in the hash stored at key.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value associated with field, or <see langword="null"/> when field is not present in the hash or key does not exist.</returns>
/// <remarks><seealso href="https://redis.io/commands/hget"/></remarks>
Lease<byte>? HashFieldGetLeaseAndDelete(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Returns the values associated with the specified fields in the hash stored at key.
/// For every field that does not exist in the hash, a <see langword="RedisValue.Null"/> value is returned.
/// Because non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of <see langword="RedisValue.Null"/> values.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashFields">The fields in the hash to get.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>List of values associated with the given fields, in the same order as they are requested.</returns>
/// <remarks><seealso href="https://redis.io/commands/hmget"/></remarks>
RedisValue[] HashFieldGetAndDelete(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the value of the specified hash field and sets its expiration time.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get and set the expiration for.</param>
/// <param name="expiry">The expiration time to set.</param>
/// <param name="persist">If true, the expiration will be removed. And 'expiry' parameter is ignored.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value of the specified hash field.</returns>
RedisValue HashFieldGetAndSetExpiry(RedisKey key, RedisValue hashField, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the value of the specified hash field and sets its expiration time.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get and set the expiration for.</param>
/// <param name="expiry">The exact date and time to set the expiration to.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value of the specified hash field.</returns>
RedisValue HashFieldGetAndSetExpiry(RedisKey key, RedisValue hashField, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the value of the specified hash field and sets its expiration time, returning a lease.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get and set the expiration for.</param>
/// <param name="expiry">The expiration time to set.</param>
/// <param name="persist">If true, the expiration will be removed. And 'expiry' parameter is ignored.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value of the specified hash field as a lease.</returns>
Lease<byte>? HashFieldGetLeaseAndSetExpiry(RedisKey key, RedisValue hashField, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the value of the specified hash field and sets its expiration time, returning a lease.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field in the hash to get and set the expiration for.</param>
/// <param name="expiry">The exact date and time to set the expiration to.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The value of the specified hash field as a lease.</returns>
Lease<byte>? HashFieldGetLeaseAndSetExpiry(RedisKey key, RedisValue hashField, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the values of the specified hash fields and sets their expiration times.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashFields">The fields in the hash to get and set the expiration for.</param>
/// <param name="expiry">The expiration time to set.</param>
/// <param name="persist">If true, the expiration will be removed. And 'expiry' parameter is ignored.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The values of the specified hash fields.</returns>
RedisValue[] HashFieldGetAndSetExpiry(RedisKey key, RedisValue[] hashFields, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Gets the values of the specified hash fields and sets their expiration times.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashFields">The fields in the hash to get and set the expiration for.</param>
/// <param name="expiry">The exact date and time to set the expiration to.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The values of the specified hash fields.</returns>
RedisValue[] HashFieldGetAndSetExpiry(RedisKey key, RedisValue[] hashFields, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Sets the value of the specified hash field and sets its expiration time.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="field">The field in the hash to set and set the expiration for.</param>
/// <param name="value">The value in the hash to set and set the expiration for.</param>
/// <param name="expiry">The expiration time to set.</param>
/// <param name="keepTtl">Whether to maintain the existing field's TTL (KEEPTTL flag).</param>
/// <param name="when">Which conditions to set the value under (defaults to always).</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>0 if no fields were set, 1 if all the fields were set.</returns>
RedisValue HashFieldSetAndSetExpiry(RedisKey key, RedisValue field, RedisValue value, TimeSpan? expiry = null, bool keepTtl = false, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Sets the value of the specified hash field and sets its expiration time.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="field">The field in the hash to set and set the expiration for.</param>
/// <param name="value">The value in the hash to set and set the expiration for.</param>
/// <param name="expiry">The exact date and time to set the expiration to.</param>
/// <param name="when">Which conditions to set the value under (defaults to always).</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>0 if no fields were set, 1 if all the fields were set.</returns>
RedisValue HashFieldSetAndSetExpiry(RedisKey key, RedisValue field, RedisValue value, DateTime expiry, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Sets the values of the specified hash fields and sets their expiration times.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashFields">The fields in the hash to set and set the expiration for.</param>
/// <param name="expiry">The expiration time to set.</param>
/// <param name="keepTtl">Whether to maintain the existing fields' TTL (KEEPTTL flag).</param>
/// <param name="when">Which conditions to set the values under (defaults to always).</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>0 if no fields were set, 1 if all the fields were set.</returns>
RedisValue HashFieldSetAndSetExpiry(RedisKey key, HashEntry[] hashFields, TimeSpan? expiry = null, bool keepTtl = false, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Sets the values of the specified hash fields and sets their expiration times.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashFields">The fields in the hash to set and set the expiration for.</param>
/// <param name="expiry">The exact date and time to set the expiration to.</param>
/// <param name="when">Which conditions to set the values under (defaults to always).</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>0 if no fields were set, 1 if all the fields were set.</returns>
RedisValue HashFieldSetAndSetExpiry(RedisKey key, HashEntry[] hashFields, DateTime expiry, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Returns all fields and values of the hash stored at key.
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,45 @@ public interface IDatabaseAsync : IRedisAsync
/// <inheritdoc cref="IDatabase.HashExists(RedisKey, RedisValue, CommandFlags)"/>
Task<bool> HashExistsAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndDelete(RedisKey, RedisValue, CommandFlags)"/>
Task<RedisValue> HashFieldGetAndDeleteAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetLeaseAndDelete(RedisKey, RedisValue, CommandFlags)"/>
Task<Lease<byte>?> HashFieldGetLeaseAndDeleteAsync(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndDelete(RedisKey, RedisValue[], CommandFlags)"/>
Task<RedisValue[]> HashFieldGetAndDeleteAsync(RedisKey key, RedisValue[] hashFields, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndSetExpiry(RedisKey, RedisValue, TimeSpan?, bool, CommandFlags)"/>
Task<RedisValue> HashFieldGetAndSetExpiryAsync(RedisKey key, RedisValue hashField, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndSetExpiry(RedisKey, RedisValue, DateTime, CommandFlags)"/>
Task<RedisValue> HashFieldGetAndSetExpiryAsync(RedisKey key, RedisValue hashField, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetLeaseAndSetExpiry(RedisKey, RedisValue, TimeSpan?, bool, CommandFlags)"/>
Task<Lease<byte>?> HashFieldGetLeaseAndSetExpiryAsync(RedisKey key, RedisValue hashField, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetLeaseAndSetExpiry(RedisKey, RedisValue, DateTime, CommandFlags)"/>
Task<Lease<byte>?> HashFieldGetLeaseAndSetExpiryAsync(RedisKey key, RedisValue hashField, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndSetExpiry(RedisKey, RedisValue[], TimeSpan?, bool, CommandFlags)"/>
Task<RedisValue[]> HashFieldGetAndSetExpiryAsync(RedisKey key, RedisValue[] hashFields, TimeSpan? expiry = null, bool persist = false, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldGetAndSetExpiry(RedisKey, RedisValue[], DateTime, CommandFlags)"/>
Task<RedisValue[]> HashFieldGetAndSetExpiryAsync(RedisKey key, RedisValue[] hashFields, DateTime expiry, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldSetAndSetExpiry(RedisKey, RedisValue, RedisValue, TimeSpan?, bool, When, CommandFlags)"/>
Task<RedisValue> HashFieldSetAndSetExpiryAsync(RedisKey key, RedisValue field, RedisValue value, TimeSpan? expiry = null, bool keepTtl = false, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldSetAndSetExpiry(RedisKey, RedisValue, RedisValue, DateTime, When, CommandFlags)"/>
Task<RedisValue> HashFieldSetAndSetExpiryAsync(RedisKey key, RedisValue field, RedisValue value, DateTime expiry, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldSetAndSetExpiry(RedisKey, HashEntry[], TimeSpan?, bool, When, CommandFlags)"/>
Task<RedisValue> HashFieldSetAndSetExpiryAsync(RedisKey key, HashEntry[] hashFields, TimeSpan? expiry = null, bool keepTtl = false, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldSetAndSetExpiry(RedisKey, HashEntry[], DateTime, When, CommandFlags)"/>
Task<RedisValue> HashFieldSetAndSetExpiryAsync(RedisKey key, HashEntry[] hashFields, DateTime expiry, When when = When.Always, CommandFlags flags = CommandFlags.None);

/// <inheritdoc cref="IDatabase.HashFieldExpire(RedisKey, RedisValue[], TimeSpan, ExpireWhen, CommandFlags)"/>
Task<ExpireResult[]> HashFieldExpireAsync(RedisKey key, RedisValue[] hashFields, TimeSpan expiry, ExpireWhen when = ExpireWhen.Always, CommandFlags flags = CommandFlags.None);

Expand Down
Loading
Loading