Skip to content

Commit 6719de3

Browse files
authored
Merge branch 'main' into currantw/password_update_api
2 parents 74faeff + 3c80ce8 commit 6719de3

File tree

12 files changed

+1267
-8
lines changed

12 files changed

+1267
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ Valkey General Language Independent Driver for the Enterprise (GLIDE) is the off
2929

3030
Valkey GLIDE for C# is API-compatible with the following engine versions:
3131

32-
| Engine Type | 6.2 | 7.0 | 7.1 | 7.2 | 8.0 | 8.1 |
33-
|-----------------------|-------|-------|--------|-------|-------|-------|
34-
| Valkey | - | - | - | V | V | V |
35-
| Redis | V | V | V | V | - | - |
32+
| Engine Type | 6.2 | 7.0 | 7.1 | 7.2 | 8.0 | 8.1 | 9.0 |
33+
|-----------------------|-------|-------|--------|-------|-------|-------|-------|
34+
| Valkey | - | - | - | V | V | V | V |
35+
| Redis | V | V | V | V | - | - | - |
3636

3737
## Installation
3838

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2+
3+
using Valkey.Glide.Commands;
4+
using Valkey.Glide.Commands.Options;
5+
using Valkey.Glide.Internals;
6+
7+
namespace Valkey.Glide;
8+
9+
public abstract partial class BaseClient : IBitmapCommands
10+
{
11+
/// <inheritdoc/>
12+
public async Task<bool> StringGetBitAsync(ValkeyKey key, long offset, CommandFlags flags = CommandFlags.None)
13+
{
14+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
15+
return await Command(Request.GetBitAsync(key, offset));
16+
}
17+
18+
/// <inheritdoc/>
19+
public async Task<bool> StringSetBitAsync(ValkeyKey key, long offset, bool value, CommandFlags flags = CommandFlags.None)
20+
{
21+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
22+
return await Command(Request.SetBitAsync(key, offset, value));
23+
}
24+
25+
/// <inheritdoc/>
26+
public async Task<long> StringBitCountAsync(ValkeyKey key, long start = 0, long end = -1, StringIndexType indexType = StringIndexType.Byte, CommandFlags flags = CommandFlags.None)
27+
{
28+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
29+
return await Command(Request.BitCountAsync(key, start, end, indexType));
30+
}
31+
32+
/// <inheritdoc/>
33+
public async Task<long> StringBitPositionAsync(ValkeyKey key, bool bit, long start = 0, long end = -1, StringIndexType indexType = StringIndexType.Byte, CommandFlags flags = CommandFlags.None)
34+
{
35+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
36+
return await Command(Request.BitPositionAsync(key, bit, start, end, indexType));
37+
}
38+
39+
/// <inheritdoc/>
40+
public async Task<long> StringBitOperationAsync(Bitwise operation, ValkeyKey destination, ValkeyKey first, ValkeyKey second, CommandFlags flags = CommandFlags.None)
41+
{
42+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
43+
return await Command(Request.BitOperationAsync(operation, destination, first, second));
44+
}
45+
46+
/// <inheritdoc/>
47+
public async Task<long> StringBitOperationAsync(Bitwise operation, ValkeyKey destination, ValkeyKey[] keys, CommandFlags flags = CommandFlags.None)
48+
{
49+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
50+
return await Command(Request.BitOperationAsync(operation, destination, keys));
51+
}
52+
53+
/// <inheritdoc/>
54+
public async Task<long[]> StringBitFieldAsync(ValkeyKey key, BitFieldOptions.IBitFieldSubCommand[] subCommands, CommandFlags flags = CommandFlags.None)
55+
{
56+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
57+
58+
// Check if all subcommands are read-only (GET operations)
59+
bool allReadOnly = subCommands.All(cmd => cmd is BitFieldOptions.IBitFieldReadOnlySubCommand);
60+
61+
if (allReadOnly)
62+
{
63+
// Convert to read-only subcommands and use BITFIELD_RO
64+
var readOnlyCommands = subCommands.Cast<BitFieldOptions.IBitFieldReadOnlySubCommand>().ToArray();
65+
return await Command(Request.BitFieldReadOnlyAsync(key, readOnlyCommands));
66+
}
67+
68+
return await Command(Request.BitFieldAsync(key, subCommands));
69+
}
70+
71+
/// <inheritdoc/>
72+
public async Task<long[]> StringBitFieldReadOnlyAsync(ValkeyKey key, BitFieldOptions.IBitFieldReadOnlySubCommand[] subCommands, CommandFlags flags = CommandFlags.None)
73+
{
74+
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
75+
return await Command(Request.BitFieldReadOnlyAsync(key, subCommands));
76+
}
77+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2+
3+
namespace Valkey.Glide.Commands;
4+
5+
/// <summary>
6+
/// Supports bitmap commands for standalone and cluster clients.
7+
/// <br/>
8+
/// See more on <see href="https://valkey.io/commands#bitmap">valkey.io</see>.
9+
/// </summary>
10+
public interface IBitmapCommands
11+
{
12+
/// <summary>
13+
/// Returns the bit value at offset in the string value stored at key.
14+
/// </summary>
15+
/// <seealso href="https://valkey.io/commands/getbit"/>
16+
/// <param name="key">The key of the string.</param>
17+
/// <param name="offset">The offset in the string to get the bit at.</param>
18+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
19+
/// <returns>The bit value stored at offset. Returns 0 if the key does not exist or if the offset is beyond the string length.</returns>
20+
/// <remarks>
21+
/// <example>
22+
/// <code>
23+
/// await client.StringSetAsync("mykey", "A"); // ASCII 'A' is 01000001
24+
/// bool bit = await client.StringGetBitAsync("mykey", 1);
25+
/// Console.WriteLine(bit); // Output: true (bit 1 is set)
26+
/// </code>
27+
/// </example>
28+
/// </remarks>
29+
Task<bool> StringGetBitAsync(ValkeyKey key, long offset, CommandFlags flags = CommandFlags.None);
30+
31+
/// <summary>
32+
/// Sets or clears the bit at offset in the string value stored at key.
33+
/// </summary>
34+
/// <seealso href="https://valkey.io/commands/setbit"/>
35+
/// <param name="key">The key of the string.</param>
36+
/// <param name="offset">The offset in the string to set the bit at.</param>
37+
/// <param name="value">The bit value to set (true for 1, false for 0).</param>
38+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
39+
/// <returns>The original bit value stored at offset. Returns false if the key does not exist or if the offset is beyond the string length.</returns>
40+
/// <remarks>
41+
/// <example>
42+
/// <code>
43+
/// bool oldBit = await client.StringSetBitAsync("mykey", 1, true);
44+
/// Console.WriteLine(oldBit); // Output: false (original bit value)
45+
/// </code>
46+
/// </example>
47+
/// </remarks>
48+
Task<bool> StringSetBitAsync(ValkeyKey key, long offset, bool value, CommandFlags flags = CommandFlags.None);
49+
50+
/// <summary>
51+
/// Count the number of set bits in a string.
52+
/// </summary>
53+
/// <seealso href="https://valkey.io/commands/bitcount"/>
54+
/// <param name="key">The key of the string.</param>
55+
/// <param name="start">The start offset.</param>
56+
/// <param name="end">The end offset.</param>
57+
/// <param name="indexType">The index type (bit or byte).</param>
58+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
59+
/// <returns>The number of bits set to 1.</returns>
60+
/// <remarks>
61+
/// <example>
62+
/// <code>
63+
/// await client.StringSetAsync("mykey", "A"); // ASCII 'A' is 01000001
64+
/// long count = await client.StringBitCountAsync("mykey");
65+
/// Console.WriteLine(count); // Output: 2 (two bits set)
66+
/// </code>
67+
/// </example>
68+
/// </remarks>
69+
Task<long> StringBitCountAsync(ValkeyKey key, long start = 0, long end = -1, StringIndexType indexType = StringIndexType.Byte, CommandFlags flags = CommandFlags.None);
70+
71+
/// <summary>
72+
/// Return the position of the first bit set to 1 or 0 in a string.
73+
/// </summary>
74+
/// <seealso href="https://valkey.io/commands/bitpos"/>
75+
/// <param name="key">The key of the string.</param>
76+
/// <param name="bit">The bit value to search for (true for 1, false for 0).</param>
77+
/// <param name="start">The start offset.</param>
78+
/// <param name="end">The end offset.</param>
79+
/// <param name="indexType">The index type (bit or byte).</param>
80+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
81+
/// <returns>The position of the first bit with the specified value, or -1 if not found.</returns>
82+
/// <remarks>
83+
/// <example>
84+
/// <code>
85+
/// await client.StringSetAsync("mykey", "A"); // ASCII 'A' is 01000001
86+
/// long pos = await client.StringBitPositionAsync("mykey", true);
87+
/// Console.WriteLine(pos); // Output: 1 (first set bit at position 1)
88+
/// </code>
89+
/// </example>
90+
/// </remarks>
91+
Task<long> StringBitPositionAsync(ValkeyKey key, bool bit, long start = 0, long end = -1, StringIndexType indexType = StringIndexType.Byte, CommandFlags flags = CommandFlags.None);
92+
93+
/// <summary>
94+
/// Perform a bitwise operation between multiple keys and store the result in the destination key.
95+
/// </summary>
96+
/// <seealso href="https://valkey.io/commands/bitop"/>
97+
/// <param name="operation">The bitwise operation to perform.</param>
98+
/// <param name="destination">The key to store the result.</param>
99+
/// <param name="first">The first source key.</param>
100+
/// <param name="second">The second source key.</param>
101+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
102+
/// <returns>The size of the string stored in the destination key.</returns>
103+
/// <remarks>
104+
/// <example>
105+
/// <code>
106+
/// await client.StringSetAsync("key1", "A");
107+
/// await client.StringSetAsync("key2", "B");
108+
/// long size = await client.StringBitOperationAsync(Bitwise.And, "result", "key1", "key2");
109+
/// Console.WriteLine(size); // Output: 1 (size of result)
110+
/// </code>
111+
/// </example>
112+
/// </remarks>
113+
Task<long> StringBitOperationAsync(Bitwise operation, ValkeyKey destination, ValkeyKey first, ValkeyKey second, CommandFlags flags = CommandFlags.None);
114+
115+
/// <summary>
116+
/// Perform a bitwise operation between multiple keys and store the result in the destination key.
117+
/// </summary>
118+
/// <seealso href="https://valkey.io/commands/bitop"/>
119+
/// <param name="operation">The bitwise operation to perform.</param>
120+
/// <param name="destination">The key to store the result.</param>
121+
/// <param name="keys">The source keys.</param>
122+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
123+
/// <returns>The size of the string stored in the destination key.</returns>
124+
/// <remarks>
125+
/// <example>
126+
/// <code>
127+
/// await client.StringSetAsync("key1", "A");
128+
/// await client.StringSetAsync("key2", "B");
129+
/// await client.StringSetAsync("key3", "C");
130+
/// long size = await client.StringBitOperationAsync(Bitwise.Or, "result", new ValkeyKey[] { "key1", "key2", "key3" });
131+
/// Console.WriteLine(size); // Output: 1 (size of result)
132+
/// </code>
133+
/// </example>
134+
/// </remarks>
135+
Task<long> StringBitOperationAsync(Bitwise operation, ValkeyKey destination, ValkeyKey[] keys, CommandFlags flags = CommandFlags.None);
136+
137+
/// <summary>
138+
/// Reads or modifies the array of bits representing the string stored at key based on the specified subcommands.
139+
/// </summary>
140+
/// <seealso href="https://valkey.io/commands/bitfield"/>
141+
/// <param name="key">The key of the string.</param>
142+
/// <param name="subCommands">The subcommands to execute (GET, SET, INCRBY).</param>
143+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
144+
/// <returns>An array of results from the executed subcommands. Null responses from the server are converted to 0.</returns>
145+
/// <remarks>
146+
/// <example>
147+
/// <code>
148+
/// await client.StringSetAsync("mykey", "A"); // ASCII 'A' is 01000001
149+
/// var subCommands = new IBitFieldSubCommand[] {
150+
/// new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(8), 0),
151+
/// new BitFieldOptions.BitFieldSet(BitFieldOptions.Encoding.Unsigned(8), 0, 66) // ASCII 'B'
152+
/// };
153+
/// long[] results = await client.StringBitFieldAsync("mykey", subCommands);
154+
/// Console.WriteLine(results[0]); // Output: 65 (ASCII 'A')
155+
/// Console.WriteLine(results[1]); // Output: 65 (old value)
156+
/// </code>
157+
/// </example>
158+
/// </remarks>
159+
Task<long[]> StringBitFieldAsync(ValkeyKey key, Commands.Options.BitFieldOptions.IBitFieldSubCommand[] subCommands, CommandFlags flags = CommandFlags.None);
160+
161+
/// <summary>
162+
/// Reads the array of bits representing the string stored at key based on the specified GET subcommands.
163+
/// This is a read-only variant of BITFIELD.
164+
/// </summary>
165+
/// <seealso href="https://valkey.io/commands/bitfield_ro"/>
166+
/// <param name="key">The key of the string.</param>
167+
/// <param name="subCommands">The GET subcommands to execute.</param>
168+
/// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param>
169+
/// <returns>An array of results from the executed GET subcommands. Null responses from the server are converted to 0.</returns>
170+
/// <remarks>
171+
/// <example>
172+
/// <code>
173+
/// await client.StringSetAsync("mykey", "A"); // ASCII 'A' is 01000001
174+
/// var subCommands = new IBitFieldReadOnlySubCommand[] {
175+
/// new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(8), 0)
176+
/// };
177+
/// long[] results = await client.StringBitFieldReadOnlyAsync("mykey", subCommands);
178+
/// Console.WriteLine(results[0]); // Output: 65 (ASCII 'A')
179+
/// </code>
180+
/// </example>
181+
/// </remarks>
182+
Task<long[]> StringBitFieldReadOnlyAsync(ValkeyKey key, Commands.Options.BitFieldOptions.IBitFieldReadOnlySubCommand[] subCommands, CommandFlags flags = CommandFlags.None);
183+
}

0 commit comments

Comments
 (0)