|
| 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