Commit b88b5860 authored by Marc Gravell's avatar Marc Gravell

Merge branch 'master' of github.com:StackExchange/StackExchange.Redis

parents 97d16d37 e9df673f
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace StackExchange.Redis.Tests
{
[TestFixture]
public class HyperLogLog : TestBase
{
[Test]
public void SingleKeyLength()
{
using (var conn = Create())
{
var db = conn.GetDatabase();
RedisKey key = "hll1";
db.HyperLogLogAdd(key, "a");
db.HyperLogLogAdd(key, "b");
db.HyperLogLogAdd(key, "c");
Assert.IsTrue(db.HyperLogLogLength(key) > 0);
}
}
[Test]
public void MultiKeyLength()
{
using (var conn = Create(useSharedSocketManager: true))
{
var db = conn.GetDatabase();
RedisKey[] keys = { "hll1", "hll2", "hll3" };
db.HyperLogLogAdd(keys[0], "a");
db.HyperLogLogAdd(keys[1], "b");
db.HyperLogLogAdd(keys[2], "c");
Assert.IsTrue(db.HyperLogLogLength(keys) > 0);
}
}
}
}
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="AsyncTests.cs" /> <Compile Include="AsyncTests.cs" />
<Compile Include="BasicOps.cs" /> <Compile Include="BasicOps.cs" />
<Compile Include="HyperLogLog.cs" />
<Compile Include="WrapperBaseTests.cs" /> <Compile Include="WrapperBaseTests.cs" />
<Compile Include="TransactionWrapperTests.cs" /> <Compile Include="TransactionWrapperTests.cs" />
<Compile Include="Bits.cs" /> <Compile Include="Bits.cs" />
...@@ -128,11 +129,11 @@ ...@@ -128,11 +129,11 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>
\ No newline at end of file
...@@ -189,6 +189,13 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -189,6 +189,13 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>http://redis.io/commands/pfcount</remarks> /// <remarks>http://redis.io/commands/pfcount</remarks>
long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.None); long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Returns the approximated cardinality of the union of the HyperLogLogs passed, by internally merging the HyperLogLogs stored at the provided keys into a temporary hyperLogLog, or 0 if the variable does not exist.
/// </summary>
/// <returns>The approximated number of unique elements observed via HyperLogLogAdd.</returns>
/// <remarks>http://redis.io/commands/pfcount</remarks>
long HyperLogLogLength(RedisKey[] keys, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures. /// Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
/// </summary> /// </summary>
......
...@@ -147,6 +147,13 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -147,6 +147,13 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>http://redis.io/commands/pfcount</remarks> /// <remarks>http://redis.io/commands/pfcount</remarks>
Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None); Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Returns the approximated cardinality of the union of the HyperLogLogs passed, by internally merging the HyperLogLogs stored at the provided keys into a temporary hyperLogLog, or 0 if the variable does not exist.
/// </summary>
/// <returns>The approximated number of unique elements observed via HyperLogLogAdd.</returns>
/// <remarks>http://redis.io/commands/pfcount</remarks>
Task<long> HyperLogLogLengthAsync(RedisKey[] keys, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures. /// Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
/// </summary> /// </summary>
......
...@@ -121,6 +121,11 @@ public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.No ...@@ -121,6 +121,11 @@ public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.No
return this.Inner.HyperLogLogLength(this.ToInner(key), flags); return this.Inner.HyperLogLogLength(this.ToInner(key), flags);
} }
public long HyperLogLogLength(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{
return this.Inner.HyperLogLogLength(this.ToInner(keys), flags);
}
public void HyperLogLogMerge(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None) public void HyperLogLogMerge(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None)
{ {
this.Inner.HyperLogLogMerge(this.ToInner(destination), this.ToInner(sourceKeys), flags); this.Inner.HyperLogLogMerge(this.ToInner(destination), this.ToInner(sourceKeys), flags);
......
...@@ -127,6 +127,11 @@ public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = Comm ...@@ -127,6 +127,11 @@ public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = Comm
return this.Inner.HyperLogLogLengthAsync(this.ToInner(key), flags); return this.Inner.HyperLogLogLengthAsync(this.ToInner(key), flags);
} }
public Task<long> HyperLogLogLengthAsync(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{
return this.Inner.HyperLogLogLengthAsync(this.ToInner(keys), flags);
}
public Task HyperLogLogMergeAsync(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None) public Task HyperLogLogMergeAsync(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None)
{ {
return this.Inner.HyperLogLogMergeAsync(this.ToInner(destination), this.ToInner(sourceKeys), flags); return this.Inner.HyperLogLogMergeAsync(this.ToInner(destination), this.ToInner(sourceKeys), flags);
......
...@@ -287,12 +287,28 @@ public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.No ...@@ -287,12 +287,28 @@ public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.No
return ExecuteSync(cmd, ResultProcessor.Int64); return ExecuteSync(cmd, ResultProcessor.Int64);
} }
public long HyperLogLogLength(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{
if (keys == null) throw new ArgumentNullException("keys");
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys);
return ExecuteSync(cmd, ResultProcessor.Int64);
}
public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None) public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{ {
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key); var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key);
return ExecuteAsync(cmd, ResultProcessor.Int64); return ExecuteAsync(cmd, ResultProcessor.Int64);
} }
public Task<long> HyperLogLogLengthAsync(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{
if (keys == null) throw new ArgumentNullException("keys");
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys);
return ExecuteAsync(cmd, ResultProcessor.Int64);
}
public void HyperLogLogMerge(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None) public void HyperLogLogMerge(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
{ {
var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, first, second); var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, first, second);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment