Skip to content
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
11 changes: 11 additions & 0 deletions sources/Valkey.Glide/BaseClient.GenericCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ public async Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationK
return await Command(Request.KeyCopyAsync(sourceKey, destinationKey, replace));
}

public async Task<bool> KeyMoveAsync(ValkeyKey key, int database, CommandFlags flags = CommandFlags.None)
{
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
return await Command(Request.KeyMoveAsync(key, database));
}

public async Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false, CommandFlags flags = CommandFlags.None)
{
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
return await Command(Request.KeyCopyAsync(sourceKey, destinationKey, destinationDatabase, replace));
}
public async Task<string?> KeyRandomAsync(CommandFlags flags = CommandFlags.None)
{
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
Expand Down
40 changes: 40 additions & 0 deletions sources/Valkey.Glide/Commands/IGenericBaseCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,46 @@ public interface IGenericBaseCommands
/// </remarks>
Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, bool replace = false, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Moves key from the currently selected database 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>
/// <seealso href="https://valkey.io/commands/move"/>
/// <param name="key">The key to move.</param>
/// <param name="database">The database to move the key to.</param>
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
/// <returns><see langword="true"/> if key was moved. <see langword="false"/> if key was not moved.</returns>
/// <remarks>
/// <example>
/// <code>
/// bool result = await client.KeyMoveAsync(key, 2);
/// </code>
/// </example>
/// </remarks>
Task<bool> KeyMoveAsync(ValkeyKey key, int database, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Copies the value stored at the source to the destination key in the specified database. When
/// replace is true, removes the destination key first if it already
/// exists, otherwise performs no action.
/// </summary>
/// <seealso href="https://valkey.io/commands/copy"/>
/// <note>Since Valkey 6.2.0 and above.</note>
/// <param name="sourceKey">The key to the source value.</param>
/// <param name="destinationKey">The key where the value should be copied to.</param>
/// <param name="destinationDatabase">The database ID to store destinationKey in.</param>
/// <param name="replace">Whether to overwrite an existing values at destinationKey.</param>
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
/// <returns><see langword="true"/> if sourceKey was copied. <see langword="false"/> if sourceKey was not copied.</returns>
/// <remarks>
/// <example>
/// <code>
/// bool result = await client.KeyCopyAsync(sourceKey, destKey, 1, replace: true);
/// </code>
/// </example>
/// </remarks>
Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Returns a random key from the database.
/// </summary>
Expand Down
42 changes: 2 additions & 40 deletions sources/Valkey.Glide/Commands/IGenericCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,45 +167,7 @@ public interface IGenericCommands
/// </returns>
Task<object?[]?> Exec(Batch batch, bool raiseOnError, BatchOptions options);

/// <summary>
/// Move key from the currently selected database to the database specified by database.
/// </summary>
/// <seealso href="https://valkey.io/commands/move"/>
/// <param name="key">The key to move.</param>
/// <param name="database">The index of the database to move key to.</param>
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
/// <returns>
/// <see langword="true"/> if key was moved. <see langword="false"/> if the key already exists in the destination
/// database or does not exist in the source database.
/// </returns>
/// <remarks>
/// <example>
/// <code>
/// bool result = await client.KeyMoveAsync(key, 2);
/// </code>
/// </example>
/// </remarks>
Task<bool> KeyMoveAsync(ValkeyKey key, int database, CommandFlags flags = CommandFlags.None);

/// <summary>
/// Copies the value stored at the source to the destination key. When
/// replace is true, removes the destination key first if it already
/// exists, otherwise performs no action.
/// </summary>
/// <seealso href="https://valkey.io/commands/copy"/>
/// <note>Since Valkey 6.2.0 and above.</note>
/// <param name="sourceKey">The key to the source value.</param>
/// <param name="destinationKey">The key where the value should be copied to.</param>
/// <param name="destinationDatabase">The database ID to store destinationKey in.</param>
/// <param name="replace">Whether to overwrite an existing values at destinationKey.</param>
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
/// <returns><see langword="true"/> if souceKey was copied. <see langword="false"/> if sourceKey was not copied.</returns>
/// <remarks>
/// <example>
/// <code>
/// bool result = await client.KeyCopyAsync(sourceKey, destKey, replace: true);
/// </code>
/// </example>
/// </remarks>
Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false, CommandFlags flags = CommandFlags.None);


}
41 changes: 22 additions & 19 deletions sources/Valkey.Glide/ConnectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal StandaloneClientConfiguration() { }
/// <param name="connectionTimeout"><inheritdoc cref="ClientConfigurationBuilder{T}.ConnectionTimeout" path="/summary" /></param>
/// <param name="readFrom"><inheritdoc cref="ClientConfigurationBuilder{T}.ReadFrom" path="/summary" /></param>
/// <param name="retryStrategy"><inheritdoc cref="ClientConfigurationBuilder{T}.ConnectionRetryStrategy" path="/summary" /></param>
/// <param name="databaseId"><inheritdoc cref="StandaloneClientConfigurationBuilder.DataBaseId" path="/summary" /></param>
/// <param name="databaseId"><inheritdoc cref="ClientConfigurationBuilder{T}.DataBaseId" path="/summary" /></param>
/// <param name="protocol"><inheritdoc cref="ClientConfigurationBuilder{T}.ProtocolVersion" path="/summary" /></param>
/// <param name="clientName"><inheritdoc cref="ClientConfigurationBuilder{T}.ClientName" path="/summary" /></param>
public StandaloneClientConfiguration(
Expand Down Expand Up @@ -220,8 +220,7 @@ public StandaloneClientConfiguration(
}

/// <summary>
/// Configuration for a cluster client. Use <see cref="ClusterClientConfigurationBuilder" /> or
/// <see cref="ClusterClientConfiguration(List{ValueTuple{string?, ushort?}}, bool?, TimeSpan?, TimeSpan?, ReadFrom?, RetryStrategy?, string?, string?, Protocol?, string?)" /> to create an instance.
/// Configuration for a cluster client. Use <see cref="ClusterClientConfigurationBuilder" /> to create an instance.
/// </summary>
public sealed class ClusterClientConfiguration : BaseClientConfiguration
{
Expand All @@ -237,6 +236,7 @@ internal ClusterClientConfiguration() { }
/// <param name="connectionTimeout"><inheritdoc cref="ClientConfigurationBuilder{T}.ConnectionTimeout" path="/summary" /></param>
/// <param name="readFrom"><inheritdoc cref="ClientConfigurationBuilder{T}.ReadFrom" path="/summary" /></param>
/// <param name="retryStrategy"><inheritdoc cref="ClientConfigurationBuilder{T}.ConnectionRetryStrategy" path="/summary" /></param>
/// <param name="databaseId"><inheritdoc cref="ClientConfigurationBuilder{T}.DataBaseId" path="/summary" /></param>
/// <param name="protocol"><inheritdoc cref="ClientConfigurationBuilder{T}.ProtocolVersion" path="/summary" /></param>
/// <param name="clientName"><inheritdoc cref="ClientConfigurationBuilder{T}.ClientName" path="/summary" /></param>
public ClusterClientConfiguration(
Expand All @@ -248,6 +248,7 @@ public ClusterClientConfiguration(
RetryStrategy? retryStrategy = null,
string? username = null,
string? password = null,
uint? databaseId = null,
Protocol? protocol = null,
string? clientName = null
)
Expand All @@ -260,6 +261,7 @@ public ClusterClientConfiguration(
_ = readFrom.HasValue ? builder.ReadFrom = readFrom.Value : new();
_ = retryStrategy.HasValue ? builder.ConnectionRetryStrategy = retryStrategy.Value : new();
_ = (username ?? password) is not null ? builder.Authentication = (username, password!) : new();
_ = databaseId.HasValue ? builder.DataBaseId = databaseId.Value : new();
_ = protocol.HasValue ? builder.ProtocolVersion = protocol.Value : new();
_ = clientName is not null ? builder.ClientName = clientName : "";
Request = builder.Build().Request;
Expand Down Expand Up @@ -515,6 +517,23 @@ public T WithConnectionRetryStrategy(RetryStrategy connectionRetryStrategy)
public T WithConnectionRetryStrategy(uint numberOfRetries, uint factor, uint exponentBase, uint? jitterPercent = null)
=> WithConnectionRetryStrategy(new RetryStrategy(numberOfRetries, factor, exponentBase, jitterPercent));
#endregion
#region DataBase ID
/// <summary>
/// Index of the logical database to connect to. Must be non-negative and within the range
/// supported by the server configuration. If not specified, defaults to database 0.
/// For cluster mode, requires Valkey 9.0+ with cluster-databases configuration enabled.
/// </summary>
public uint DataBaseId
{
set => Config.DatabaseId = value;
}
/// <inheritdoc cref="DataBaseId" />
public T WithDataBaseId(uint dataBaseId)
{
DataBaseId = dataBaseId;
return (T)this;
}
#endregion

internal ConnectionConfig Build() => Config;
}
Expand All @@ -530,22 +549,6 @@ public StandaloneClientConfigurationBuilder() : base(false) { }
/// Complete the configuration with given settings.
/// </summary>
public new StandaloneClientConfiguration Build() => new() { Request = base.Build() };

#region DataBase ID
/// <summary>
/// Index of the logical database to connect to.
/// </summary>
public uint DataBaseId
{
set => Config.DatabaseId = value;
}
/// <inheritdoc cref="DataBaseId" />
public StandaloneClientConfigurationBuilder WithDataBaseId(uint dataBaseId)
{
DataBaseId = dataBaseId;
return this;
}
#endregion
}

/// <summary>
Expand Down
12 changes: 2 additions & 10 deletions sources/Valkey.Glide/GlideClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,9 @@ public async Task<TimeSpan> PingAsync(ValkeyValue message, CommandFlags flags =
return await Command(Request.Ping(message));
}

public async Task<bool> KeyMoveAsync(ValkeyKey key, int database, CommandFlags flags = CommandFlags.None)
{
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
return await Command(Request.KeyMoveAsync(key, database));
}

public async Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false, CommandFlags flags = CommandFlags.None)
{
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
return await Command(Request.KeyCopyAsync(sourceKey, destinationKey, destinationDatabase, replace));
}



public async Task<KeyValuePair<string, string>[]> ConfigGetAsync(ValkeyValue pattern = default, CommandFlags flags = CommandFlags.None)
{
Expand Down
7 changes: 7 additions & 0 deletions sources/Valkey.Glide/Pipeline/BaseBatch.GenericCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public abstract partial class BaseBatch<T>
/// <inheritdoc cref="IBatchGenericCommands.KeyCopy(ValkeyKey, ValkeyKey, bool)" />
public T KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, bool replace = false) => AddCmd(KeyCopyAsync(sourceKey, destinationKey, replace));

/// <inheritdoc cref="IBatchGenericCommands.KeyMove(ValkeyKey, int)" />
public T KeyMove(ValkeyKey key, int database) => AddCmd(KeyMoveAsync(key, database));

/// <inheritdoc cref="IBatchGenericCommands.KeyCopy(ValkeyKey, ValkeyKey, int, bool)" />
public T KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false) => AddCmd(KeyCopyAsync(sourceKey, destinationKey, destinationDatabase, replace));
/// <inheritdoc cref="IBatchGenericCommands.KeyRandom()" />
public T KeyRandom() => AddCmd(KeyRandomAsync());

Expand Down Expand Up @@ -125,6 +130,8 @@ public abstract partial class BaseBatch<T>
IBatch IBatchGenericCommands.KeyIdleTime(ValkeyKey key) => KeyIdleTime(key);
IBatch IBatchGenericCommands.KeyRefCount(ValkeyKey key) => KeyRefCount(key);
IBatch IBatchGenericCommands.KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, bool replace) => KeyCopy(sourceKey, destinationKey, replace);
IBatch IBatchGenericCommands.KeyMove(ValkeyKey key, int database) => KeyMove(key, database);
IBatch IBatchGenericCommands.KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace) => KeyCopy(sourceKey, destinationKey, destinationDatabase, replace);
IBatch IBatchGenericCommands.KeyRandom() => KeyRandom();
IBatch IBatchGenericCommands.Sort(ValkeyKey key, long skip, long take, Order order, SortType sortType, ValkeyValue by, ValkeyValue[]? get) => Sort(key, skip, take, order, sortType, by, get);
IBatch IBatchGenericCommands.Wait(long numreplicas, long timeout) => Wait(numreplicas, timeout);
Expand Down
13 changes: 1 addition & 12 deletions sources/Valkey.Glide/Pipeline/Batch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

using Valkey.Glide.Internals;

namespace Valkey.Glide.Pipeline;

/// <summary>
Expand All @@ -25,15 +23,6 @@ namespace Valkey.Glide.Pipeline;
/// </param>
public sealed class Batch(bool isAtomic) : BaseBatch<Batch>(isAtomic), IBatchStandalone
{
// Standalone commands: select, move, copy, scan

/// <inheritdoc cref="IBatchStandalone.KeyCopy(ValkeyKey, ValkeyKey, int, bool)" />
public Batch KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false) => AddCmd(Request.KeyCopyAsync(sourceKey, destinationKey, destinationDatabase, replace));

/// <inheritdoc cref="IBatchStandalone.KeyMove(ValkeyKey, int)" />
public Batch KeyMove(ValkeyKey key, int database) => AddCmd(Request.KeyMoveAsync(key, database));

// Explicit interface implementations for IBatchStandalone
IBatchStandalone IBatchStandalone.KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace) => KeyCopy(sourceKey, destinationKey, destinationDatabase, replace);
IBatchStandalone IBatchStandalone.KeyMove(ValkeyKey key, int database) => KeyMove(key, database);
IBatch IBatchStandalone.SelectAsync(long index) => SelectAsync(index);
}
7 changes: 7 additions & 0 deletions sources/Valkey.Glide/Pipeline/IBatchGenericCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ internal interface IBatchGenericCommands
/// <returns>Command Response - <inheritdoc cref="IGenericBaseCommands.KeyCopyAsync(ValkeyKey, ValkeyKey, bool, CommandFlags)" /></returns>
IBatch KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, bool replace = false);

/// <inheritdoc cref="IGenericBaseCommands.KeyMoveAsync(ValkeyKey, int, CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />
/// <returns>Command Response - <inheritdoc cref="IGenericBaseCommands.KeyMoveAsync(ValkeyKey, int, CommandFlags)" /></returns>
IBatch KeyMove(ValkeyKey key, int database);

/// <inheritdoc cref="IGenericBaseCommands.KeyCopyAsync(ValkeyKey, ValkeyKey, int, bool, CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />
/// <returns>Command Response - <inheritdoc cref="IGenericBaseCommands.KeyCopyAsync(ValkeyKey, ValkeyKey, int, bool, CommandFlags)" /></returns>
IBatch KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false);
/// <inheritdoc cref="IGenericBaseCommands.KeyRandomAsync(CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />
/// <returns>Command Response - <inheritdoc cref="IGenericBaseCommands.KeyRandomAsync(CommandFlags)" /></returns>
IBatch KeyRandom();
Expand Down
12 changes: 3 additions & 9 deletions sources/Valkey.Glide/Pipeline/IBatchStandalone.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

using Valkey.Glide.Commands;

namespace Valkey.Glide.Pipeline;

/// <summary>
/// Interface for standalone-specific batch operations that are not available in cluster mode.
/// </summary>
internal interface IBatchStandalone
{
/// <inheritdoc cref="IGenericCommands.KeyCopyAsync(ValkeyKey, ValkeyKey, int, bool, CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />
/// <returns>Command Response - <inheritdoc cref="IGenericCommands.KeyCopyAsync(ValkeyKey, ValkeyKey, int, bool, CommandFlags)" /></returns>
IBatchStandalone KeyCopy(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false);

/// <inheritdoc cref="IGenericCommands.KeyMoveAsync(ValkeyKey, int, CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />
/// <returns>Command Response - <inheritdoc cref="IGenericCommands.KeyMoveAsync(ValkeyKey, int, CommandFlags)" /></returns>
IBatchStandalone KeyMove(ValkeyKey key, int database);
/// <inheritdoc cref="IServerManagementCommands.SelectAsync(long, CommandFlags)" path="/*[not(self::remarks) and not(self::returns)]" />

Check failure on line 10 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / Analyze

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 10 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / Analyze

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 10 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / lint

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 10 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / lint

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved
/// <returns>Command Response - <inheritdoc cref="IServerManagementCommands.SelectAsync(long, CommandFlags)" /></returns>

Check failure on line 11 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / Analyze

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 11 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / Analyze

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 11 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / lint

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved

Check failure on line 11 in sources/Valkey.Glide/Pipeline/IBatchStandalone.cs

View workflow job for this annotation

GitHub Actions / lint

XML comment has cref attribute 'SelectAsync(long, CommandFlags)' that could not be resolved
IBatch SelectAsync(long index);
}
Loading
Loading