Commit 6b2a66d4 authored by Marc Gravell's avatar Marc Gravell

HyperLogLog is now a thing

parent 45d7ba62
...@@ -106,6 +106,8 @@ static bool IgnoreMethodConventions(MethodInfo method) ...@@ -106,6 +106,8 @@ static bool IgnoreMethodConventions(MethodInfo method)
case "CreateTransaction": case "CreateTransaction":
case "IsConnected": case "IsConnected":
case "SetScan": case "SetScan":
case "SortedSetScan":
case "HashScan":
case "SubscribedEndpoint": case "SubscribedEndpoint":
return true; return true;
} }
...@@ -185,7 +187,7 @@ void CheckMethod(MethodInfo method, bool isAsync) ...@@ -185,7 +187,7 @@ void CheckMethod(MethodInfo method, bool isAsync)
|| shortName.StartsWith("String") || shortName.StartsWith("List") || shortName.StartsWith("String") || shortName.StartsWith("List")
|| shortName.StartsWith("SortedSet") || shortName.StartsWith("Set") || shortName.StartsWith("SortedSet") || shortName.StartsWith("Set")
|| shortName.StartsWith("Debug") || shortName.StartsWith("Lock") || shortName.StartsWith("Debug") || shortName.StartsWith("Lock")
|| shortName.StartsWith("Script") || shortName.StartsWith("Script") || shortName.StartsWith("HyperLogLog")
, fullName + ":Prefix"); , fullName + ":Prefix");
} }
......
...@@ -153,6 +153,39 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -153,6 +153,39 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>http://redis.io/commands/hvals</remarks> /// <remarks>http://redis.io/commands/hvals</remarks>
RedisValue[] HashValues(RedisKey key, CommandFlags flags = CommandFlags.None); RedisValue[] HashValues(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Adds the element to the HyperLogLog data structure stored at the variable name specified as first argument.
/// </summary>
/// <returns>true if at least 1 HyperLogLog internal register was altered. false otherwise.</returns>
/// <remarks>http://redis.io/commands/pfadd</remarks>
bool HyperLogLogAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.
/// </summary>
/// <returns>true if at least 1 HyperLogLog internal register was altered. false otherwise.</returns>
/// <remarks>http://redis.io/commands/pfadd</remarks>
bool HyperLogLogAdd(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, 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 key, CommandFlags flags = CommandFlags.None);
/// <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.
/// </summary>
/// <remarks>http://redis.io/commands/pfmerge</remarks>
void HyperLogLogMerge(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None);
/// <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.
/// </summary>
/// <remarks>http://redis.io/commands/pfmerge</remarks>
void HyperLogLogMerge(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Inidicate exactly which redis server we are talking to /// Inidicate exactly which redis server we are talking to
/// </summary> /// </summary>
......
...@@ -126,6 +126,39 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -126,6 +126,39 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>http://redis.io/commands/hvals</remarks> /// <remarks>http://redis.io/commands/hvals</remarks>
Task<RedisValue[]> HashValuesAsync(RedisKey key, CommandFlags flags = CommandFlags.None); Task<RedisValue[]> HashValuesAsync(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Adds the element to the HyperLogLog data structure stored at the variable name specified as first argument.
/// </summary>
/// <returns>true if at least 1 HyperLogLog internal register was altered. false otherwise.</returns>
/// <remarks>http://redis.io/commands/pfadd</remarks>
Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.
/// </summary>
/// <returns>true if at least 1 HyperLogLog internal register was altered. false otherwise.</returns>
/// <remarks>http://redis.io/commands/pfadd</remarks>
Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, 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 key, CommandFlags flags = CommandFlags.None);
/// <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.
/// </summary>
/// <remarks>http://redis.io/commands/pfmerge</remarks>
Task HyperLogLogMergeAsync(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None);
/// <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.
/// </summary>
/// <remarks>http://redis.io/commands/pfmerge</remarks>
Task HyperLogLogMergeAsync(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Inidicate exactly which redis server we are talking to /// Inidicate exactly which redis server we are talking to
/// </summary> /// </summary>
......
...@@ -311,6 +311,9 @@ public static bool IsMasterOnly(RedisCommand command) ...@@ -311,6 +311,9 @@ public static bool IsMasterOnly(RedisCommand command)
case RedisCommand.PERSIST: case RedisCommand.PERSIST:
case RedisCommand.PEXPIRE: case RedisCommand.PEXPIRE:
case RedisCommand.PEXPIREAT: case RedisCommand.PEXPIREAT:
case RedisCommand.PFADD:
case RedisCommand.PFCOUNT: // technically a write command
case RedisCommand.PFMERGE:
case RedisCommand.PSETEX: case RedisCommand.PSETEX:
case RedisCommand.RENAME: case RedisCommand.RENAME:
case RedisCommand.RENAMENX: case RedisCommand.RENAMENX:
......
...@@ -90,6 +90,9 @@ enum RedisCommand ...@@ -90,6 +90,9 @@ enum RedisCommand
PERSIST, PERSIST,
PEXPIRE, PEXPIRE,
PEXPIREAT, PEXPIREAT,
PFADD,
PFCOUNT,
PFMERGE,
PING, PING,
PSETEX, PSETEX,
PSUBSCRIBE, PSUBSCRIBE,
......
...@@ -1810,6 +1810,65 @@ private IEnumerable<T> TryScan<T>(RedisKey key, RedisValue pattern, int pageSize ...@@ -1810,6 +1810,65 @@ private IEnumerable<T> TryScan<T>(RedisKey key, RedisValue pattern, int pageSize
if (ScanUtils.IsNil(pattern)) pattern = (byte[])null; if (ScanUtils.IsNil(pattern)) pattern = (byte[])null;
return new ScanIterator<T>(this, server, key, pattern, pageSize, flags, command, processor).Read(); return new ScanIterator<T>(this, server, key, pattern, pageSize, flags, command, processor).Read();
} }
public bool HyperLogLogAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFADD, key, value);
return ExecuteSync(cmd, ResultProcessor.Boolean);
}
public bool HyperLogLogAdd(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFADD, key, values);
return ExecuteSync(cmd, ResultProcessor.Boolean);
}
public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key);
return ExecuteSync(cmd, ResultProcessor.Int64);
}
public void HyperLogLogMerge(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, first, second);
ExecuteSync(cmd, ResultProcessor.DemandOK);
}
public void HyperLogLogMerge(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, sourceKeys);
ExecuteSync(cmd, ResultProcessor.DemandOK);
}
public Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFADD, key, value);
return ExecuteAsync(cmd, ResultProcessor.Boolean);
}
public Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFADD, key, values);
return ExecuteAsync(cmd, ResultProcessor.Boolean);
}
public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key);
return ExecuteAsync(cmd, ResultProcessor.Int64);
}
public Task HyperLogLogMergeAsync(RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, first, second);
return ExecuteAsync(cmd, ResultProcessor.DemandOK);
}
public Task HyperLogLogMergeAsync(RedisKey destination, RedisKey[] sourceKeys, CommandFlags flags = CommandFlags.None)
{
var cmd = Message.Create(Db, flags, RedisCommand.PFMERGE, destination, sourceKeys);
return ExecuteAsync(cmd, ResultProcessor.DemandOK);
}
internal static class ScanUtils internal static class ScanUtils
{ {
public const int DefaultPageSize = 10; public const int DefaultPageSize = 10;
......
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