Skip to content

Commit 263193d

Browse files
committed
Implement HyperLogLog commands (PFADD, PFCOUNT, PFMERGE) with corresponding handlers and tests; update README
1 parent 7ed0ae4 commit 263193d

4 files changed

Lines changed: 610 additions & 0 deletions

File tree

Dredis.Abstractions.Storage/IKeyValueStore.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,82 @@ public StreamConsumersInfoResult(StreamInfoResultStatus status, StreamConsumerIn
934934
public StreamConsumerInfo[] Consumers { get; }
935935
}
936936

937+
/// <summary>
938+
/// Describes results of HyperLogLog operations.
939+
/// </summary>
940+
public enum HyperLogLogResultStatus
941+
{
942+
Ok,
943+
WrongType
944+
}
945+
946+
/// <summary>
947+
/// Represents a result for HyperLogLog add operations.
948+
/// </summary>
949+
public sealed class HyperLogLogAddResult
950+
{
951+
/// <summary>
952+
/// Initializes a new instance of the <see cref="HyperLogLogAddResult"/> class.
953+
/// </summary>
954+
public HyperLogLogAddResult(HyperLogLogResultStatus status, bool changed)
955+
{
956+
Status = status;
957+
Changed = changed;
958+
}
959+
960+
/// <summary>
961+
/// Gets the result status.
962+
/// </summary>
963+
public HyperLogLogResultStatus Status { get; }
964+
/// <summary>
965+
/// Gets whether at least one register changed.
966+
/// </summary>
967+
public bool Changed { get; }
968+
}
969+
970+
/// <summary>
971+
/// Represents a result for HyperLogLog count operations.
972+
/// </summary>
973+
public sealed class HyperLogLogCountResult
974+
{
975+
/// <summary>
976+
/// Initializes a new instance of the <see cref="HyperLogLogCountResult"/> class.
977+
/// </summary>
978+
public HyperLogLogCountResult(HyperLogLogResultStatus status, long count)
979+
{
980+
Status = status;
981+
Count = count;
982+
}
983+
984+
/// <summary>
985+
/// Gets the result status.
986+
/// </summary>
987+
public HyperLogLogResultStatus Status { get; }
988+
/// <summary>
989+
/// Gets the approximate cardinality.
990+
/// </summary>
991+
public long Count { get; }
992+
}
993+
994+
/// <summary>
995+
/// Represents a result for HyperLogLog merge operations.
996+
/// </summary>
997+
public sealed class HyperLogLogMergeResult
998+
{
999+
/// <summary>
1000+
/// Initializes a new instance of the <see cref="HyperLogLogMergeResult"/> class.
1001+
/// </summary>
1002+
public HyperLogLogMergeResult(HyperLogLogResultStatus status)
1003+
{
1004+
Status = status;
1005+
}
1006+
1007+
/// <summary>
1008+
/// Gets the result status.
1009+
/// </summary>
1010+
public HyperLogLogResultStatus Status { get; }
1011+
}
1012+
9371013
/// <summary>
9381014
/// Describes results of vector operations.
9391015
/// </summary>
@@ -1999,6 +2075,40 @@ Task<JsonMGetResult> JsonMgetAsync(
19992075
string path,
20002076
CancellationToken token = default);
20012077

2078+
/// <summary>
2079+
/// Adds one or more elements to a HyperLogLog sketch.
2080+
/// </summary>
2081+
/// <param name="key">The HyperLogLog key.</param>
2082+
/// <param name="elements">The elements to add.</param>
2083+
/// <param name="token">A cancellation token that can be used to cancel the operation.</param>
2084+
/// <returns>A task that represents the asynchronous operation. The task result contains status and whether the sketch changed.</returns>
2085+
Task<HyperLogLogAddResult> HyperLogLogAddAsync(
2086+
string key,
2087+
byte[][] elements,
2088+
CancellationToken token = default);
2089+
2090+
/// <summary>
2091+
/// Returns the approximate cardinality for one or more HyperLogLog sketches.
2092+
/// </summary>
2093+
/// <param name="keys">The HyperLogLog keys.</param>
2094+
/// <param name="token">A cancellation token that can be used to cancel the operation.</param>
2095+
/// <returns>A task that represents the asynchronous operation. The task result contains status and approximate cardinality.</returns>
2096+
Task<HyperLogLogCountResult> HyperLogLogCountAsync(
2097+
string[] keys,
2098+
CancellationToken token = default);
2099+
2100+
/// <summary>
2101+
/// Merges one or more HyperLogLog sketches into a destination sketch.
2102+
/// </summary>
2103+
/// <param name="destinationKey">The destination HyperLogLog key.</param>
2104+
/// <param name="sourceKeys">The source HyperLogLog keys.</param>
2105+
/// <param name="token">A cancellation token that can be used to cancel the operation.</param>
2106+
/// <returns>A task that represents the asynchronous operation. The task result contains merge status.</returns>
2107+
Task<HyperLogLogMergeResult> HyperLogLogMergeAsync(
2108+
string destinationKey,
2109+
string[] sourceKeys,
2110+
CancellationToken token = default);
2111+
20022112
/// <summary>
20032113
/// Sets a vector value at the specified key.
20042114
/// </summary>

0 commit comments

Comments
 (0)