Commit cc5b084c authored by Jeremy Meng's avatar Jeremy Meng

Merge branch 'UpdateNUnitTo3' of...

Merge branch 'UpdateNUnitTo3' of https://github.com/RogerBestMsft/StackExchange.Redis into netcore-test
parents 910405af 5633bbb2
...@@ -72,26 +72,31 @@ public void PingMany(bool preserveOrder) ...@@ -72,26 +72,31 @@ public void PingMany(bool preserveOrder)
} }
[Test] [Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"A null key is not valid in this context")] // [ExpectedException(typeof(ArgumentException), ExpectedMessage = @"A null key is not valid in this context")]
public void GetWithNullKey() public void GetWithNullKey()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var db = muxer.GetDatabase(); var db = muxer.GetDatabase();
string key = null; string key = null;
db.StringGet(key); //db.StringGet(key);
ArgumentException ex = Assert.Throws(typeof(ArgumentException), delegate { db.StringGet(key); }) as ArgumentException;
Assert.That(ex.Message.Equals( @"A null key is not valid in this context"));
} }
} }
[Test] [Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"A null key is not valid in this context")] // [ExpectedException(typeof(ArgumentException), ExpectedMessage = @"A null key is not valid in this context")]
public void SetWithNullKey() public void SetWithNullKey()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var db = muxer.GetDatabase(); var db = muxer.GetDatabase();
string key = null, value = "abc"; string key = null, value = "abc";
db.StringSet(key, value); // db.StringSet(key, value);
ArgumentException ex = Assert.Throws(typeof(ArgumentException), delegate { db.StringSet(key, value); }) as ArgumentException;
Assert.That(ex.Message.Equals(@"A null key is not valid in this context"));
} }
} }
...@@ -293,7 +298,7 @@ public void GetWithExpiry(bool exists, bool hasExpiry) ...@@ -293,7 +298,7 @@ public void GetWithExpiry(bool exists, bool hasExpiry)
} }
} }
[Test] [Test]
[ExpectedException(typeof(RedisServerException), ExpectedMessage = "WRONGTYPE Operation against a key holding the wrong kind of value")] // [ExpectedException(typeof(RedisServerException), ExpectedMessage = @"A null key is not valid in this context")]
public void GetWithExpiryWrongTypeAsync() public void GetWithExpiryWrongTypeAsync()
{ {
using (var conn = Create()) using (var conn = Create())
...@@ -308,15 +313,19 @@ public void GetWithExpiryWrongTypeAsync() ...@@ -308,15 +313,19 @@ public void GetWithExpiryWrongTypeAsync()
} }
catch(AggregateException ex) catch(AggregateException ex)
{ {
throw ex.InnerExceptions[0]; //throw ex.InnerExceptions[0];
Assert.That(ex.GetType().Equals(typeof(RedisServerException)));
Assert.That(ex.InnerExceptions[0].Equals(@"A null key is not valid in this context"));
} }
Assert.Fail(); Assert.Fail();
} }
} }
[Test] [Test]
[ExpectedException(typeof(RedisServerException), ExpectedMessage = "WRONGTYPE Operation against a key holding the wrong kind of value")] // [ExpectedException(typeof(RedisServerException), ExpectedMessage = "WRONGTYPE Operation against a key holding the wrong kind of value")]
public void GetWithExpiryWrongTypeSync() public void GetWithExpiryWrongTypeSync()
{
Exception ex = Assert.Throws(typeof(RedisServerException), delegate
{ {
using (var conn = Create()) using (var conn = Create())
{ {
...@@ -327,6 +336,8 @@ public void GetWithExpiryWrongTypeSync() ...@@ -327,6 +336,8 @@ public void GetWithExpiryWrongTypeSync()
db.StringGetWithExpiry(key); db.StringGetWithExpiry(key);
Assert.Fail(); Assert.Fail();
} }
});
Assert.That(ex.Message.Equals("WRONGTYPE Operation against a key holding the wrong kind of value"));
} }
[Test] [Test]
......
...@@ -12,7 +12,8 @@ public sealed class BatchWrapperTests ...@@ -12,7 +12,8 @@ public sealed class BatchWrapperTests
private Mock<IBatch> mock; private Mock<IBatch> mock;
private BatchWrapper wrapper; private BatchWrapper wrapper;
[TestFixtureSetUp] //[TestFixtureSetUp]
[OneTimeSetUpAttribute]
public void Initialize() public void Initialize()
{ {
mock = new Mock<IBatch>(); mock = new Mock<IBatch>();
......
...@@ -198,10 +198,11 @@ public void IntentionalWrongServer() ...@@ -198,10 +198,11 @@ public void IntentionalWrongServer()
} }
[Test] [Test]
[ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot")] //[ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot")]
public void TransactionWithMultiServerKeys() public void TransactionWithMultiServerKeys()
{ {
using(var muxer = Create()) Exception ex = Assert.Throws(typeof(RedisCommandException), delegate {
using (var muxer = Create())
{ {
// connect // connect
var cluster = muxer.GetDatabase(); var cluster = muxer.GetDatabase();
...@@ -249,11 +250,15 @@ public void TransactionWithMultiServerKeys() ...@@ -249,11 +250,15 @@ public void TransactionWithMultiServerKeys()
//Assert.IsFalse(cluster.Wait(existsX), "x exists"); //Assert.IsFalse(cluster.Wait(existsX), "x exists");
//Assert.IsFalse(cluster.Wait(existsY), "y exists"); //Assert.IsFalse(cluster.Wait(existsY), "y exists");
} }
});
Assert.That(ex.Message.Equals("Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot"));
} }
[Test] [Test]
[ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot")] //[ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot")]
public void TransactionWithSameServerKeys() public void TransactionWithSameServerKeys()
{
Exception ex = Assert.Throws(typeof(RedisCommandException), delegate
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -302,6 +307,8 @@ public void TransactionWithSameServerKeys() ...@@ -302,6 +307,8 @@ public void TransactionWithSameServerKeys()
//Assert.IsTrue(cluster.Wait(existsX), "x exists"); //Assert.IsTrue(cluster.Wait(existsX), "x exists");
//Assert.IsTrue(cluster.Wait(existsY), "y exists"); //Assert.IsTrue(cluster.Wait(existsY), "y exists");
} }
});
Assert.That(ex.Message.Equals("Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot"));
} }
[Test] [Test]
......
...@@ -125,7 +125,7 @@ public void ClientName() ...@@ -125,7 +125,7 @@ public void ClientName()
} }
[Test] [Test]
[ExpectedException(typeof(RedisCommandException), ExpectedMessage = "This operation has been disabled in the command-map and cannot be used: CONFIG")] // [ExpectedException(typeof(RedisCommandException), ExpectedMessage = "This operation has been disabled in the command-map and cannot be used: CONFIG")]
public void ReadConfigWithConfigDisabled() public void ReadConfigWithConfigDisabled()
{ {
using (var muxer = Create(allowAdmin: true, disabledCommands: new[] { "config", "info" })) using (var muxer = Create(allowAdmin: true, disabledCommands: new[] { "config", "info" }))
......
...@@ -15,7 +15,8 @@ public sealed class DatabaseWrapperTests ...@@ -15,7 +15,8 @@ public sealed class DatabaseWrapperTests
private Mock<IDatabase> mock; private Mock<IDatabase> mock;
private DatabaseWrapper wrapper; private DatabaseWrapper wrapper;
[TestFixtureSetUp] //[TestFixtureSetUp]
[OneTimeSetUp]
public void Initialize() public void Initialize()
{ {
mock = new Mock<IDatabase>(); mock = new Mock<IDatabase>();
...@@ -289,10 +290,10 @@ public void KeyPersist() ...@@ -289,10 +290,10 @@ public void KeyPersist()
} }
[Test] [Test]
[ExpectedException(typeof(NotSupportedException))] //[ExpectedException(typeof(NotSupportedException))]
public void KeyRandom() public void KeyRandom()
{ {
wrapper.KeyRandom(); Assert.Throws(typeof(NotSupportedException), delegate { wrapper.KeyRandom(); });
} }
[Test] [Test]
......
...@@ -23,15 +23,23 @@ public void UnkonwnKeywordHandling_Ignore() ...@@ -23,15 +23,23 @@ public void UnkonwnKeywordHandling_Ignore()
{ {
var options = ConfigurationOptions.Parse("ssl2=true", true); var options = ConfigurationOptions.Parse("ssl2=true", true);
} }
[Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Keyword 'ssl2' is not supported")] [Test]
//, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Keyword 'ssl2' is not supported")]
public void UnkonwnKeywordHandling_ExplicitFail() public void UnkonwnKeywordHandling_ExplicitFail()
{ {
Exception ex = Assert.Throws(typeof(ArgumentException), delegate {
var options = ConfigurationOptions.Parse("ssl2=true", false); var options = ConfigurationOptions.Parse("ssl2=true", false);
});
Assert.That(ex.Message.Equals("Keyword 'ssl2' is not supported"));
} }
[Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Keyword 'ssl2' is not supported")] [Test]
//, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Keyword 'ssl2' is not supported")]
public void UnkonwnKeywordHandling_ImplicitFail() public void UnkonwnKeywordHandling_ImplicitFail()
{ {
Exception ex = Assert.Throws(typeof(ArgumentException), delegate {
var options = ConfigurationOptions.Parse("ssl2=true"); var options = ConfigurationOptions.Parse("ssl2=true");
});
Assert.That(ex.Message.Equals("Keyword 'ssl2' is not supported"));
} }
} }
} }
...@@ -14,9 +14,11 @@ protected override string GetConfiguration() ...@@ -14,9 +14,11 @@ protected override string GetConfiguration()
return PrimaryServer + ":" + SecurePort + "," + PrimaryServer + ":" + PrimaryPort + ",password=" + SecurePassword; return PrimaryServer + ":" + SecurePort + "," + PrimaryServer + ":" + PrimaryPort + ",password=" + SecurePassword;
} }
[Test, ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Command cannot be issued to a slave: FLUSHDB")] [Test]
//, ExpectedException(typeof(RedisCommandException), ExpectedMessage = "Command cannot be issued to a slave: FLUSHDB")]
public void CannotFlushSlave() public void CannotFlushSlave()
{ {
Exception ex = Assert.Throws(typeof(RedisCommandException), delegate {
ConfigurationOptions config = GetMasterSlaveConfig(); ConfigurationOptions config = GetMasterSlaveConfig();
using (var conn = ConnectionMultiplexer.Connect(config)) using (var conn = ConnectionMultiplexer.Connect(config))
{ {
...@@ -24,6 +26,9 @@ public void CannotFlushSlave() ...@@ -24,6 +26,9 @@ public void CannotFlushSlave()
var slave = servers.First(x => x.IsSlave); var slave = servers.First(x => x.IsSlave);
slave.FlushDatabase(); slave.FlushDatabase();
} }
});
Assert.That(ex.Message.Equals("Command cannot be issued to a slave: FLUSHDB"));
} }
[Test] [Test]
......
...@@ -68,14 +68,17 @@ public void Connect() ...@@ -68,14 +68,17 @@ public void Connect()
[Test] [Test]
[TestCase("wrong")] [TestCase("wrong")]
[TestCase("")] [TestCase("")]
[ExpectedException(typeof(RedisConnectionException), ExpectedMessage = "No connection is available to service this operation: PING")] //[ExpectedException(typeof(RedisConnectionException), ExpectedMessage = "No connection is available to service this operation: PING")]
public void ConnectWithWrongPassword(string password) public void ConnectWithWrongPassword(string password)
{ {
Exception ex = Assert.Throws(typeof(RedisConnectionException), delegate {
SetExpectedAmbientFailureCount(-1); SetExpectedAmbientFailureCount(-1);
using (var server = Create(password: password, checkConnect: false)) using (var server = Create(password: password, checkConnect: false))
{ {
server.GetDatabase().Ping(); server.GetDatabase().Ping();
} }
});
Assert.That(ex.Message.Equals("No connection is available to service this operation: PING"));
} }
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace StackExchange.Redis.Tests namespace StackExchange.Redis.Tests
{ {
[TestFixture, Ignore] [TestFixture, Ignore("reason?")]
public class Sentinel public class Sentinel
{ {
// TODO fill in these constants before running tests // TODO fill in these constants before running tests
...@@ -100,7 +100,7 @@ public void SentinelSlavesTest() ...@@ -100,7 +100,7 @@ public void SentinelSlavesTest()
} }
} }
[Test, Ignore] [Test, Ignore("reason?")]
public void SentinelFailoverTest() public void SentinelFailoverTest()
{ {
Server.SentinelFailover(ServiceName); Server.SentinelFailover(ServiceName);
......
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
<HintPath>..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath> <HintPath>..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=3.0.5715.30856, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <HintPath>..\packages\NUnit.3.0.0-beta-5\lib\net45\nunit.framework.dll</HintPath>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
......
...@@ -11,7 +11,8 @@ public sealed class TransactionWrapperTests ...@@ -11,7 +11,8 @@ public sealed class TransactionWrapperTests
private Mock<ITransaction> mock; private Mock<ITransaction> mock;
private TransactionWrapper wrapper; private TransactionWrapper wrapper;
[TestFixtureSetUp] //[TestFixtureSetUp]
[OneTimeSetUp]
public void Initialize() public void Initialize()
{ {
mock = new Mock<ITransaction>(); mock = new Mock<ITransaction>();
......
...@@ -28,33 +28,42 @@ public void BlankPrefixYieldsSame_String() ...@@ -28,33 +28,42 @@ public void BlankPrefixYieldsSame_String()
Assert.AreSame(raw, prefixed); Assert.AreSame(raw, prefixed);
} }
} }
[Test, ExpectedException(typeof(ArgumentNullException))] [Test]
//, ExpectedException(typeof(ArgumentNullException))]
public void NullPrefixIsError_Bytes() public void NullPrefixIsError_Bytes()
{ {
Assert.Throws(typeof(ArgumentNullException), delegate {
using (var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(1); var raw = conn.GetDatabase(1);
var prefixed = raw.WithKeyPrefix((byte[])null); var prefixed = raw.WithKeyPrefix((byte[])null);
} }
});
} }
[Test, ExpectedException(typeof(ArgumentNullException))] [Test]
//, ExpectedException(typeof(ArgumentNullException))]
public void NullPrefixIsError_String() public void NullPrefixIsError_String()
{ {
Assert.Throws(typeof(ArgumentNullException), delegate {
using (var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(1); var raw = conn.GetDatabase(1);
var prefixed = raw.WithKeyPrefix((string)null); var prefixed = raw.WithKeyPrefix((string)null);
} }
});
} }
[Test, ExpectedException(typeof(ArgumentNullException))] [Test]
//, ExpectedException(typeof(ArgumentNullException))]
[TestCase("abc")] [TestCase("abc")]
[TestCase("")] [TestCase("")]
[TestCase(null)] [TestCase(null)]
public void NullDatabaseIsError(string prefix) public void NullDatabaseIsError(string prefix)
{ {
Assert.Throws(typeof(ArgumentNullException), delegate {
IDatabase raw = null; IDatabase raw = null;
var prefixed = raw.WithKeyPrefix(prefix); var prefixed = raw.WithKeyPrefix(prefix);
});
} }
[Test] [Test]
public void BasicSmokeTest() public void BasicSmokeTest()
......
...@@ -15,7 +15,8 @@ public sealed class WrapperBaseTests ...@@ -15,7 +15,8 @@ public sealed class WrapperBaseTests
private Mock<IDatabaseAsync> mock; private Mock<IDatabaseAsync> mock;
private WrapperBase<IDatabaseAsync> wrapper; private WrapperBase<IDatabaseAsync> wrapper;
[TestFixtureSetUp] //[TestFixtureSetUp]
[OneTimeSetUp]
public void Initialize() public void Initialize()
{ {
mock = new Mock<IDatabaseAsync>(); mock = new Mock<IDatabaseAsync>();
...@@ -258,10 +259,12 @@ public void KeyPersistAsync() ...@@ -258,10 +259,12 @@ public void KeyPersistAsync()
} }
[Test] [Test]
[ExpectedException(typeof(NotSupportedException))] //[ExpectedException(typeof(NotSupportedException))]
public void KeyRandomAsync() public void KeyRandomAsync()
{ {
Assert.Throws(typeof(NotSupportedException), delegate {
wrapper.KeyRandomAsync(); wrapper.KeyRandomAsync();
});
} }
[Test] [Test]
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
<packages> <packages>
<package id="BookSleeve" version="1.3.41" targetFramework="net45" /> <package id="BookSleeve" version="1.3.41" targetFramework="net45" />
<package id="Moq" version="4.2.1502.0911" targetFramework="net45" /> <package id="Moq" version="4.2.1502.0911" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" /> <package id="NUnit" version="3.0.0-beta-5" targetFramework="net45" />
</packages> </packages>
\ No newline at end of file
...@@ -144,7 +144,7 @@ internal static bool TryParseDouble(string s, out double value) ...@@ -144,7 +144,7 @@ internal static bool TryParseDouble(string s, out double value)
return true; return true;
} }
// need to handle these // need to handle these
if(string.Equals("+inf", s, StringComparison.OrdinalIgnoreCase)) if(string.Equals("+inf", s, StringComparison.OrdinalIgnoreCase) || string.Equals("inf", s, StringComparison.OrdinalIgnoreCase))
{ {
value = double.PositiveInfinity; value = double.PositiveInfinity;
return true; return true;
......
...@@ -189,29 +189,32 @@ protected Message(int db, CommandFlags flags, RedisCommand command) ...@@ -189,29 +189,32 @@ protected Message(int db, CommandFlags flags, RedisCommand command)
} }
} }
if (IsMasterOnly(command)) bool masterOnly = IsMasterOnly(command);
this.Db = db;
this.command = command;
this.flags = flags & UserSelectableFlags;
if (masterOnly) SetMasterOnly();
createdDateTime = DateTime.UtcNow;
createdTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();
}
internal void SetMasterOnly()
{ {
switch (GetMasterSlaveFlags(flags)) switch (GetMasterSlaveFlags(this.flags))
{ {
case CommandFlags.DemandSlave: case CommandFlags.DemandSlave:
throw ExceptionFactory.MasterOnly(false, command, null, null); throw ExceptionFactory.MasterOnly(false, this.command, null, null);
case CommandFlags.DemandMaster: case CommandFlags.DemandMaster:
// already fine as-is // already fine as-is
break; break;
case CommandFlags.PreferMaster: case CommandFlags.PreferMaster:
case CommandFlags.PreferSlave: case CommandFlags.PreferSlave:
default: // we will run this on the master, then default: // we will run this on the master, then
flags = SetMasterSlaveFlags(flags, CommandFlags.DemandMaster); this.flags = SetMasterSlaveFlags(this.flags, CommandFlags.DemandMaster);
break; break;
} }
} }
this.Db = db;
this.command = command;
this.flags = flags & UserSelectableFlags;
createdDateTime = DateTime.UtcNow;
createdTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();
}
internal void SetProfileStorage(ProfileStorage storage) internal void SetProfileStorage(ProfileStorage storage)
{ {
...@@ -436,7 +439,6 @@ public static bool IsMasterOnly(RedisCommand command) ...@@ -436,7 +439,6 @@ public static bool IsMasterOnly(RedisCommand command)
case RedisCommand.PEXPIRE: case RedisCommand.PEXPIRE:
case RedisCommand.PEXPIREAT: case RedisCommand.PEXPIREAT:
case RedisCommand.PFADD: case RedisCommand.PFADD:
case RedisCommand.PFCOUNT: // technically a write command
case RedisCommand.PFMERGE: case RedisCommand.PFMERGE:
case RedisCommand.PSETEX: case RedisCommand.PSETEX:
case RedisCommand.RENAME: case RedisCommand.RENAME:
......
...@@ -294,30 +294,50 @@ public Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue[] values, Command ...@@ -294,30 +294,50 @@ public Task<bool> HyperLogLogAddAsync(RedisKey key, RedisValue[] values, Command
public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.None) public long HyperLogLogLength(RedisKey key, CommandFlags flags = CommandFlags.None)
{ {
ServerEndPoint server;
var features = GetFeatures(Db, key, flags, out server);
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key); var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key);
return ExecuteSync(cmd, ResultProcessor.Int64); // technically a write / master-only command until 2.8.18
if (server != null && !features.HyperLogLogCountSlaveSafe) cmd.SetMasterOnly();
return ExecuteSync(cmd, ResultProcessor.Int64, server);
} }
public long HyperLogLogLength(RedisKey[] keys, CommandFlags flags = CommandFlags.None) public long HyperLogLogLength(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{ {
if (keys == null) throw new ArgumentNullException("keys"); if (keys == null) throw new ArgumentNullException("keys");
ServerEndPoint server = null;
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys); var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys);
return ExecuteSync(cmd, ResultProcessor.Int64); if (keys.Length != 0)
{
var features = GetFeatures(Db, keys[0], flags, out server);
// technically a write / master-only command until 2.8.18
if (server != null && !features.HyperLogLogCountSlaveSafe) cmd.SetMasterOnly();
}
return ExecuteSync(cmd, ResultProcessor.Int64, server);
} }
public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None) public Task<long> HyperLogLogLengthAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{ {
ServerEndPoint server;
var features = GetFeatures(Db, key, flags, out server);
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key); var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, key);
return ExecuteAsync(cmd, ResultProcessor.Int64); // technically a write / master-only command until 2.8.18
if (server != null && !features.HyperLogLogCountSlaveSafe) cmd.SetMasterOnly();
return ExecuteAsync(cmd, ResultProcessor.Int64, server);
} }
public Task<long> HyperLogLogLengthAsync(RedisKey[] keys, CommandFlags flags = CommandFlags.None) public Task<long> HyperLogLogLengthAsync(RedisKey[] keys, CommandFlags flags = CommandFlags.None)
{ {
if (keys == null) throw new ArgumentNullException("keys"); if (keys == null) throw new ArgumentNullException("keys");
ServerEndPoint server = null;
var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys); var cmd = Message.Create(Db, flags, RedisCommand.PFCOUNT, keys);
return ExecuteAsync(cmd, ResultProcessor.Int64); if (keys.Length != 0)
{
var features = GetFeatures(Db, keys[0], flags, out server);
// technically a write / master-only command until 2.8.18
if (server != null && !features.HyperLogLogCountSlaveSafe) cmd.SetMasterOnly();
}
return ExecuteAsync(cmd, ResultProcessor.Int64, server);
} }
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)
...@@ -561,7 +581,7 @@ public Task KeyRestoreAsync(RedisKey key, byte[] value, TimeSpan? expiry = null, ...@@ -561,7 +581,7 @@ public Task KeyRestoreAsync(RedisKey key, byte[] value, TimeSpan? expiry = null,
if (server != null && features.MillisecondExpiry && multiplexer.CommandMap.IsAvailable(RedisCommand.PTTL)) if (server != null && features.MillisecondExpiry && multiplexer.CommandMap.IsAvailable(RedisCommand.PTTL))
{ {
msg = Message.Create(Db, flags, RedisCommand.PTTL, key); msg = Message.Create(Db, flags, RedisCommand.PTTL, key);
return ExecuteSync(msg, ResultProcessor.TimeSpanFromMilliseconds); return ExecuteSync(msg, ResultProcessor.TimeSpanFromMilliseconds, server);
} }
msg = Message.Create(Db, flags, RedisCommand.TTL, key); msg = Message.Create(Db, flags, RedisCommand.TTL, key);
return ExecuteSync(msg, ResultProcessor.TimeSpanFromSeconds); return ExecuteSync(msg, ResultProcessor.TimeSpanFromSeconds);
...@@ -575,7 +595,7 @@ public Task KeyRestoreAsync(RedisKey key, byte[] value, TimeSpan? expiry = null, ...@@ -575,7 +595,7 @@ public Task KeyRestoreAsync(RedisKey key, byte[] value, TimeSpan? expiry = null,
if (server != null && features.MillisecondExpiry && multiplexer.CommandMap.IsAvailable(RedisCommand.PTTL)) if (server != null && features.MillisecondExpiry && multiplexer.CommandMap.IsAvailable(RedisCommand.PTTL))
{ {
msg = Message.Create(Db, flags, RedisCommand.PTTL, key); msg = Message.Create(Db, flags, RedisCommand.PTTL, key);
return ExecuteAsync(msg, ResultProcessor.TimeSpanFromMilliseconds); return ExecuteAsync(msg, ResultProcessor.TimeSpanFromMilliseconds, server);
} }
msg = Message.Create(Db, flags, RedisCommand.TTL, key); msg = Message.Create(Db, flags, RedisCommand.TTL, key);
return ExecuteAsync(msg, ResultProcessor.TimeSpanFromSeconds); return ExecuteAsync(msg, ResultProcessor.TimeSpanFromSeconds);
......
...@@ -25,6 +25,7 @@ public struct RedisFeatures ...@@ -25,6 +25,7 @@ public struct RedisFeatures
v2_6_12 = new Version(2, 6, 12), v2_6_12 = new Version(2, 6, 12),
v2_8_0 = new Version(2, 8, 0), v2_8_0 = new Version(2, 8, 0),
v2_8_12 = new Version(2, 8, 12), v2_8_12 = new Version(2, 8, 12),
v2_8_18 = new Version(2, 8, 18),
v2_9_5 = new Version(2, 9, 5); v2_9_5 = new Version(2, 9, 5);
private readonly Version version; private readonly Version version;
...@@ -137,6 +138,11 @@ public RedisFeatures(Version version) ...@@ -137,6 +138,11 @@ public RedisFeatures(Version version)
/// </summary> /// </summary>
public bool ScriptingDatabaseSafe { get { return Version >= v2_8_12; } } public bool ScriptingDatabaseSafe { get { return Version >= v2_8_12; } }
/// <summary>
/// Is PFCOUNT supported on slaves?
/// </summary>
public bool HyperLogLogCountSlaveSafe { get { return Version >= v2_8_18; } }
/// <summary> /// <summary>
/// The Redis version of the server /// The Redis version of the server
/// </summary> /// </summary>
......
Copyright © 2002-2014 Charlie Poole
Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
Copyright © 2000-2002 Philip A. Craig
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required.
Portions Copyright © 2002-2014 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
This diff is collapsed.
Copyright (c) 2015 Charlie Poole
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
NUnit 3.0 is based on earlier versions of NUnit, with Portions
Copyright (c) 2002-2014 Charlie Poole or
Copyright (c) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or
Copyright (c) 2000-2002 Philip A. Craig
<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" /><Default Extension="nuspec" ContentType="application/octet" /><Default Extension="txt" ContentType="application/octet" /><Default Extension="dll" ContentType="application/octet" /><Default Extension="xml" ContentType="application/octet" /><Default Extension="psmdcp" ContentType="application/vnd.openxmlformats-package.core-properties+xml" /></Types>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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