Commit 9e878625 authored by Marc Gravell's avatar Marc Gravell

Merge branch 'pipelines' into async-timeout

parents 5183f1d4 76326ba6
...@@ -8,7 +8,7 @@ public class QueryTest ...@@ -8,7 +8,7 @@ public class QueryTest
public static Query GetQuery() => new Query("hello world"); public static Query GetQuery() => new Query("hello world");
[Fact] [Fact]
public void getNoContent() public void GetNoContent()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query.NoContent); Assert.False(query.NoContent);
...@@ -17,7 +17,7 @@ public void getNoContent() ...@@ -17,7 +17,7 @@ public void getNoContent()
} }
[Fact] [Fact]
public void getWithScores() public void GetWithScores()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query.WithScores); Assert.False(query.WithScores);
...@@ -26,7 +26,7 @@ public void getWithScores() ...@@ -26,7 +26,7 @@ public void getWithScores()
} }
[Fact] [Fact]
public void serializeRedisArgs() public void SerializeRedisArgs()
{ {
var query = new Query("hello world") var query = new Query("hello world")
{ {
...@@ -38,7 +38,6 @@ public void serializeRedisArgs() ...@@ -38,7 +38,6 @@ public void serializeRedisArgs()
WithScores = true WithScores = true
}; };
var args = new List<object>(); var args = new List<object>();
query.SerializeRedisArgs(args); query.SerializeRedisArgs(args);
...@@ -57,7 +56,7 @@ public void serializeRedisArgs() ...@@ -57,7 +56,7 @@ public void serializeRedisArgs()
} }
[Fact] [Fact]
public void limit() public void Limit()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.Equal(0, query._paging.Offset); Assert.Equal(0, query._paging.Offset);
...@@ -65,11 +64,10 @@ public void limit() ...@@ -65,11 +64,10 @@ public void limit()
Assert.Same(query, query.Limit(1, 30)); Assert.Same(query, query.Limit(1, 30));
Assert.Equal(1, query._paging.Offset); Assert.Equal(1, query._paging.Offset);
Assert.Equal(30, query._paging.Count); Assert.Equal(30, query._paging.Count);
} }
[Fact] [Fact]
public void addFilter() public void AddFilter()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.Empty(query._filters); Assert.Empty(query._filters);
...@@ -79,7 +77,7 @@ public void addFilter() ...@@ -79,7 +77,7 @@ public void addFilter()
} }
[Fact] [Fact]
public void setVerbatim() public void SetVerbatim()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query.Verbatim); Assert.False(query.Verbatim);
...@@ -87,20 +85,17 @@ public void setVerbatim() ...@@ -87,20 +85,17 @@ public void setVerbatim()
Assert.True(query.Verbatim); Assert.True(query.Verbatim);
} }
[Fact] [Fact]
public void setNoStopwords() public void SetNoStopwords()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query.NoStopwords); Assert.False(query.NoStopwords);
Assert.Same(query, query.SetNoStopwords()); Assert.Same(query, query.SetNoStopwords());
Assert.True(query.NoStopwords); Assert.True(query.NoStopwords);
} }
[Fact] [Fact]
public void setLanguage() public void SetLanguage()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.Null(query.Language); Assert.Null(query.Language);
...@@ -109,17 +104,16 @@ public void setLanguage() ...@@ -109,17 +104,16 @@ public void setLanguage()
} }
[Fact] [Fact]
public void limitFields() public void LimitFields()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.Null(query._fields); Assert.Null(query._fields);
Assert.Same(query, query.LimitFields("foo", "bar")); Assert.Same(query, query.LimitFields("foo", "bar"));
Assert.Equal(2, query._fields.Length); Assert.Equal(2, query._fields.Length);
} }
[Fact] [Fact]
public void highlightFields() public void HighlightFields()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query._wantsHighlight); Assert.False(query._wantsHighlight);
...@@ -144,7 +138,7 @@ public void highlightFields() ...@@ -144,7 +138,7 @@ public void highlightFields()
} }
[Fact] [Fact]
public void summarizeFields() public void SummarizeFields()
{ {
var query = GetQuery(); var query = GetQuery();
Assert.False(query._wantsSummarize); Assert.False(query._wantsSummarize);
......
...@@ -17,7 +17,7 @@ public void TestAdhocCommandsAPI() ...@@ -17,7 +17,7 @@ public void TestAdhocCommandsAPI()
// needs explicit RedisKey type for key-based // needs explicit RedisKey type for key-based
// sharding to work; will still work with strings, // sharding to work; will still work with strings,
// but no key-based sharding support // but no key-based sharding support
RedisKey key = "some_key"; RedisKey key = Me();
// note: if command renames are configured in // note: if command renames are configured in
// the API, they will still work automatically // the API, they will still work automatically
......
...@@ -13,14 +13,13 @@ public class BasicOpsTests : TestBase ...@@ -13,14 +13,13 @@ public class BasicOpsTests : TestBase
public BasicOpsTests(ITestOutputHelper output) : base (output) { } public BasicOpsTests(ITestOutputHelper output) : base (output) { }
[Fact] [Fact]
public void PingOnce() public async Task PingOnce()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var task = conn.PingAsync(); var duration = await conn.PingAsync().ForAwait();
var duration = muxer.Wait(task);
Log("Ping took: " + duration); Log("Ping took: " + duration);
Assert.True(duration.TotalMilliseconds > 0); Assert.True(duration.TotalMilliseconds > 0);
} }
...@@ -33,7 +32,7 @@ public void RapidDispose() ...@@ -33,7 +32,7 @@ public void RapidDispose()
using (var primary = Create()) using (var primary = Create())
{ {
var conn = primary.GetDatabase(); var conn = primary.GetDatabase();
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
...@@ -47,18 +46,17 @@ public void RapidDispose() ...@@ -47,18 +46,17 @@ public void RapidDispose()
} }
[Fact] [Fact]
public void PingMany() public async Task PingMany()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var tasks = new Task<TimeSpan>[100]; var tasks = new Task<TimeSpan>[100];
for (int i = 0; i < tasks.Length; i++) for (int i = 0; i < tasks.Length; i++)
{ {
tasks[i] = conn.PingAsync(); tasks[i] = conn.PingAsync();
} }
muxer.WaitAll(tasks); await Task.WhenAll(tasks).ForAwait();
Assert.True(tasks[0].Result.TotalMilliseconds > 0); Assert.True(tasks[0].Result.TotalMilliseconds > 0);
Assert.True(tasks[tasks.Length - 1].Result.TotalMilliseconds > 0); Assert.True(tasks[tasks.Length - 1].Result.TotalMilliseconds > 0);
} }
...@@ -99,7 +97,7 @@ public void SetWithNullValue() ...@@ -99,7 +97,7 @@ public void SetWithNullValue()
db.StringSet(key, "abc", flags: CommandFlags.FireAndForget); db.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
Assert.True(db.KeyExists(key)); Assert.True(db.KeyExists(key));
db.StringSet(key, value); db.StringSet(key, value, flags: CommandFlags.FireAndForget);
var actual = (string)db.StringGet(key); var actual = (string)db.StringGet(key);
Assert.Null(actual); Assert.Null(actual);
...@@ -119,7 +117,7 @@ public void SetWithDefaultValue() ...@@ -119,7 +117,7 @@ public void SetWithDefaultValue()
db.StringSet(key, "abc", flags: CommandFlags.FireAndForget); db.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
Assert.True(db.KeyExists(key)); Assert.True(db.KeyExists(key));
db.StringSet(key, value); db.StringSet(key, value, flags: CommandFlags.FireAndForget);
var actual = (string)db.StringGet(key); var actual = (string)db.StringGet(key);
Assert.Null(actual); Assert.Null(actual);
...@@ -139,7 +137,7 @@ public void SetWithZeroValue() ...@@ -139,7 +137,7 @@ public void SetWithZeroValue()
db.StringSet(key, "abc", flags: CommandFlags.FireAndForget); db.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
Assert.True(db.KeyExists(key)); Assert.True(db.KeyExists(key));
db.StringSet(key, value); db.StringSet(key, value, flags: CommandFlags.FireAndForget);
var actual = (string)db.StringGet(key); var actual = (string)db.StringGet(key);
Assert.Equal("0", actual); Assert.Equal("0", actual);
...@@ -182,10 +180,10 @@ public void GetSetSync() ...@@ -182,10 +180,10 @@ public void GetSetSync()
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
var d1 = conn.KeyDelete(key); var d1 = conn.KeyDelete(key);
var g1 = conn.StringGet(key); var g1 = conn.StringGet(key);
conn.StringSet(key, "123"); conn.StringSet(key, "123", flags: CommandFlags.FireAndForget);
var g2 = conn.StringGet(key); var g2 = conn.StringGet(key);
var d2 = conn.KeyDelete(key); var d2 = conn.KeyDelete(key);
...@@ -204,23 +202,23 @@ public void GetSetSync() ...@@ -204,23 +202,23 @@ public void GetSetSync()
[InlineData(false, false)] [InlineData(false, false)]
[InlineData(true, true)] [InlineData(true, true)]
[InlineData(true, false)] [InlineData(true, false)]
public void GetWithExpiry(bool exists, bool hasExpiry) public async Task GetWithExpiry(bool exists, bool hasExpiry)
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
if (exists) if (exists)
{ {
if (hasExpiry) if (hasExpiry)
db.StringSet(key, "val", TimeSpan.FromMinutes(5)); db.StringSet(key, "val", TimeSpan.FromMinutes(5), flags: CommandFlags.FireAndForget);
else else
db.StringSet(key, "val"); db.StringSet(key, "val", flags: CommandFlags.FireAndForget);
} }
var async = db.StringGetWithExpiryAsync(key); var async = db.StringGetWithExpiryAsync(key);
var syncResult = db.StringGetWithExpiry(key); var syncResult = db.StringGetWithExpiry(key);
var asyncResult = db.Wait(async); var asyncResult = await async;
if (exists) if (exists)
{ {
...@@ -248,8 +246,8 @@ public async Task GetWithExpiryWrongTypeAsync() ...@@ -248,8 +246,8 @@ public async Task GetWithExpiryWrongTypeAsync()
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); var del = db.KeyDeleteAsync(key);
db.SetAdd(key, "abc"); var add = db.SetAddAsync(key, "abc");
var ex = await Assert.ThrowsAsync<RedisServerException>(async () => var ex = await Assert.ThrowsAsync<RedisServerException>(async () =>
{ {
try try
...@@ -269,14 +267,14 @@ public async Task GetWithExpiryWrongTypeAsync() ...@@ -269,14 +267,14 @@ public async Task GetWithExpiryWrongTypeAsync()
[Fact] [Fact]
public void GetWithExpiryWrongTypeSync() public void GetWithExpiryWrongTypeSync()
{ {
RedisKey key = Me();
var ex = Assert.Throws<RedisServerException>(() => var ex = Assert.Throws<RedisServerException>(() =>
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); db.KeyDelete(key, CommandFlags.FireAndForget);
db.KeyDelete(key); db.SetAdd(key, "abc", CommandFlags.FireAndForget);
db.SetAdd(key, "abc");
db.StringGetWithExpiry(key); db.StringGetWithExpiry(key);
} }
}); });
...@@ -431,15 +429,16 @@ private void Incr(IDatabase database, RedisKey key, int delta, ref int total) ...@@ -431,15 +429,16 @@ private void Incr(IDatabase database, RedisKey key, int delta, ref int total)
[Fact] [Fact]
public void WrappedDatabasePrefixIntegration() public void WrappedDatabasePrefixIntegration()
{ {
var key = Me();
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase().WithKeyPrefix("abc"); var db = conn.GetDatabase().WithKeyPrefix("abc");
db.KeyDelete("count"); db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringIncrement("count"); db.StringIncrement(key, flags: CommandFlags.FireAndForget);
db.StringIncrement("count"); db.StringIncrement(key, flags: CommandFlags.FireAndForget);
db.StringIncrement("count"); db.StringIncrement(key, flags: CommandFlags.FireAndForget);
int count = (int)conn.GetDatabase().StringGet("abccount"); int count = (int)conn.GetDatabase().StringGet("abc" + key);
Assert.Equal(3, count); Assert.Equal(3, count);
} }
} }
......
...@@ -22,4 +22,4 @@ public void BasicOps() ...@@ -22,4 +22,4 @@ public void BasicOps()
} }
} }
} }
} }
\ No newline at end of file
...@@ -36,7 +36,7 @@ public void ExportConfiguration() ...@@ -36,7 +36,7 @@ public void ExportConfiguration()
} }
[Fact] [Fact]
public async Task ConnectUsesSingleSocket() public void ConnectUsesSingleSocket()
{ {
using (var sw = new StringWriter()) using (var sw = new StringWriter())
{ {
...@@ -46,7 +46,6 @@ public async Task ConnectUsesSingleSocket() ...@@ -46,7 +46,6 @@ public async Task ConnectUsesSingleSocket()
{ {
using (var muxer = Create(failMessage: i + ": ", log: sw)) using (var muxer = Create(failMessage: i + ": ", log: sw))
{ {
await Task.Delay(500).ForAwait();
foreach (var ep in muxer.GetEndPoints()) foreach (var ep in muxer.GetEndPoints())
{ {
var srv = muxer.GetServer(ep); var srv = muxer.GetServer(ep);
...@@ -174,8 +173,8 @@ string StringGet(IServer server, RedisKey key, CommandFlags flags = CommandFlags ...@@ -174,8 +173,8 @@ string StringGet(IServer server, RedisKey key, CommandFlags flags = CommandFlags
var key = Me(); var key = Me();
const string value = "abc"; const string value = "abc";
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringSet(key, value); db.StringSet(key, value, flags: CommandFlags.FireAndForget);
servers.First().Ping(); servers.First().Ping();
var config = servers.First().ClusterConfiguration; var config = servers.First().ClusterConfiguration;
Assert.NotNull(config); Assert.NotNull(config);
...@@ -445,12 +444,12 @@ public void SScan() ...@@ -445,12 +444,12 @@ public void SScan()
{ {
RedisKey key = "a"; RedisKey key = "a";
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
int totalUnfiltered = 0, totalFiltered = 0; int totalUnfiltered = 0, totalFiltered = 0;
for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
totalUnfiltered += i; totalUnfiltered += i;
if (i.ToString().Contains("3")) totalFiltered += i; if (i.ToString().Contains("3")) totalFiltered += i;
} }
...@@ -502,7 +501,6 @@ public void AccessRandomKeys() ...@@ -502,7 +501,6 @@ public void AccessRandomKeys()
}; };
var pairs = new Dictionary<string, string>(); var pairs = new Dictionary<string, string>();
const int COUNT = 500; const int COUNT = 500;
Task[] send = new Task[COUNT];
int index = 0; int index = 0;
var servers = conn.GetEndPoints().Select(x => conn.GetServer(x)); var servers = conn.GetEndPoints().Select(x => conn.GetServer(x));
...@@ -520,9 +518,8 @@ public void AccessRandomKeys() ...@@ -520,9 +518,8 @@ public void AccessRandomKeys()
var key = Guid.NewGuid().ToString(); var key = Guid.NewGuid().ToString();
var value = Guid.NewGuid().ToString(); var value = Guid.NewGuid().ToString();
pairs.Add(key, value); pairs.Add(key, value);
send[index++] = cluster.StringSetAsync(key, value); cluster.StringSet(key, value, flags: CommandFlags.FireAndForget);
} }
conn.WaitAll(send);
var expected = new string[COUNT]; var expected = new string[COUNT];
var actual = new Task<RedisValue>[COUNT]; var actual = new Task<RedisValue>[COUNT];
...@@ -597,7 +594,7 @@ public void SimpleProfiling() ...@@ -597,7 +594,7 @@ public void SimpleProfiling()
var profiler = new TestProfiler(); var profiler = new TestProfiler();
var key = Me(); var key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
conn.RegisterProfiler(profiler); conn.RegisterProfiler(profiler);
conn.BeginProfiling(profiler.MyContext); conn.BeginProfiling(profiler.MyContext);
......
...@@ -17,32 +17,30 @@ public void ValueEquals() ...@@ -17,32 +17,30 @@ public void ValueEquals()
} }
[Fact] [Fact]
public void TestManualIncr() public async Task TestManualIncr()
{ {
using (var muxer = Create(syncTimeout: 120000)) // big timeout while debugging using (var muxer = Create(syncTimeout: 120000)) // big timeout while debugging
{ {
var key = Me(); var key = Me();
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
for (int i = 0; i < 200; i++) for (int i = 0; i < 10; i++)
{ {
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
Assert.Equal(1, conn.Wait(ManualIncr(conn, key))); Assert.Equal(1, await ManualIncrAsync(conn, key));
Assert.Equal(2, conn.Wait(ManualIncr(conn, key))); Assert.Equal(2, await ManualIncrAsync(conn, key));
Assert.Equal(2, (long)conn.StringGet(key)); Assert.Equal(2, (long)conn.StringGet(key));
} }
} }
} }
public async Task<long?> ManualIncr(IDatabase connection, RedisKey key) public async Task<long?> ManualIncrAsync(IDatabase connection, RedisKey key)
{ {
var oldVal = (long?)await connection.StringGetAsync(key).ForAwait(); var oldVal = (long?)await connection.StringGetAsync(key).ForAwait();
var newVal = (oldVal ?? 0) + 1; var newVal = (oldVal ?? 0) + 1;
var tran = connection.CreateTransaction(); var tran = connection.CreateTransaction();
{ // check hasn't changed { // check hasn't changed
#pragma warning disable 4014
tran.AddCondition(Condition.StringEqual(key, oldVal)); tran.AddCondition(Condition.StringEqual(key, oldVal));
tran.StringSetAsync(key, newVal); var t = tran.StringSetAsync(key, newVal);
#pragma warning restore 4014
if (!await tran.ExecuteAsync().ForAwait()) return null; // aborted if (!await tran.ExecuteAsync().ForAwait()) return null; // aborted
return newVal; return newVal;
} }
......
...@@ -26,11 +26,11 @@ public async Task CountKeys() ...@@ -26,11 +26,11 @@ public async Task CountKeys()
Skip.IfMissingDatabase(muxer, db1Id); Skip.IfMissingDatabase(muxer, db1Id);
Skip.IfMissingDatabase(muxer, db2Id); Skip.IfMissingDatabase(muxer, db2Id);
RedisKey key = Me(); RedisKey key = Me();
var db61 = muxer.GetDatabase(db1Id); var dba = muxer.GetDatabase(db1Id);
var db62 = muxer.GetDatabase(db2Id); var dbb = muxer.GetDatabase(db2Id);
db61.StringSet("abc", "def", flags: CommandFlags.FireAndForget); dba.StringSet("abc", "def", flags: CommandFlags.FireAndForget);
db61.StringIncrement(key, flags: CommandFlags.FireAndForget); dba.StringIncrement(key, flags: CommandFlags.FireAndForget);
db62.StringIncrement(key, flags: CommandFlags.FireAndForget); dbb.StringIncrement(key, flags: CommandFlags.FireAndForget);
var server = GetAnyMaster(muxer); var server = GetAnyMaster(muxer);
var c0 = server.DatabaseSizeAsync(db1Id); var c0 = server.DatabaseSizeAsync(db1Id);
...@@ -56,7 +56,7 @@ public void DatabaseCount() ...@@ -56,7 +56,7 @@ public void DatabaseCount()
} }
[Fact] [Fact]
public void MultiDatabases() public async Task MultiDatabases()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -64,26 +64,22 @@ public void MultiDatabases() ...@@ -64,26 +64,22 @@ public void MultiDatabases()
var db0 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer)); var db0 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer));
var db1 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer)); var db1 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer));
var db2 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer)); var db2 = muxer.GetDatabase(TestConfig.GetDedicatedDB(muxer));
db0.Ping();
db0.KeyDelete(key, CommandFlags.FireAndForget); db0.KeyDelete(key, CommandFlags.FireAndForget);
db1.KeyDelete(key, CommandFlags.FireAndForget); db1.KeyDelete(key, CommandFlags.FireAndForget);
db2.KeyDelete(key, CommandFlags.FireAndForget); db2.KeyDelete(key, CommandFlags.FireAndForget);
muxer.WaitAll( db0.StringSet(key, "a", flags: CommandFlags.FireAndForget);
db0.StringSetAsync(key, "a"), db1.StringSet(key, "b", flags: CommandFlags.FireAndForget);
db1.StringSetAsync(key, "b"), db2.StringSet(key, "c", flags: CommandFlags.FireAndForget);
db2.StringSetAsync(key, "c")
);
var a = db0.StringGetAsync(key); var a = db0.StringGetAsync(key);
var b = db1.StringGetAsync(key); var b = db1.StringGetAsync(key);
var c = db2.StringGetAsync(key); var c = db2.StringGetAsync(key);
muxer.WaitAll(a, b, c);
Assert.Equal("a", muxer.Wait(a)); // db:0 Assert.Equal("a", await a); // db:0
Assert.Equal("b", muxer.Wait(b)); // db:1 Assert.Equal("b", await b); // db:1
Assert.Equal("c", muxer.Wait(c)); // db:2 Assert.Equal("c", await c); // db:2
} }
} }
} }
......
using System; using System;
using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -13,7 +14,7 @@ public class Expiry : TestBase ...@@ -13,7 +14,7 @@ public class Expiry : TestBase
[Theory] [Theory]
[InlineData(true)] [InlineData(true)]
[InlineData(false)] [InlineData(false)]
public void TestBasicExpiryTimeSpan(bool disablePTimes) public async Task TestBasicExpiryTimeSpan(bool disablePTimes)
{ {
using (var muxer = Create(disabledCommands: GetMap(disablePTimes))) using (var muxer = Create(disabledCommands: GetMap(disablePTimes)))
{ {
...@@ -32,15 +33,15 @@ public void TestBasicExpiryTimeSpan(bool disablePTimes) ...@@ -32,15 +33,15 @@ public void TestBasicExpiryTimeSpan(bool disablePTimes)
conn.KeyExpire(key, TimeSpan.MaxValue, CommandFlags.FireAndForget); conn.KeyExpire(key, TimeSpan.MaxValue, CommandFlags.FireAndForget);
var e = conn.KeyTimeToLiveAsync(key); var e = conn.KeyTimeToLiveAsync(key);
Assert.Null(muxer.Wait(a)); Assert.Null(await a);
var time = muxer.Wait(b); var time = await b;
Assert.NotNull(time); Assert.NotNull(time);
Assert.True(time > TimeSpan.FromMinutes(59.9) && time <= TimeSpan.FromMinutes(60)); Assert.True(time > TimeSpan.FromMinutes(59.9) && time <= TimeSpan.FromMinutes(60));
Assert.Null(muxer.Wait(c)); Assert.Null(await c);
time = muxer.Wait(d); time = await d;
Assert.NotNull(time); Assert.NotNull(time);
Assert.True(time > TimeSpan.FromMinutes(89.9) && time <= TimeSpan.FromMinutes(90)); Assert.True(time > TimeSpan.FromMinutes(89.9) && time <= TimeSpan.FromMinutes(90));
Assert.Null(muxer.Wait(e)); Assert.Null(await e);
} }
} }
...@@ -49,7 +50,7 @@ public void TestBasicExpiryTimeSpan(bool disablePTimes) ...@@ -49,7 +50,7 @@ public void TestBasicExpiryTimeSpan(bool disablePTimes)
[InlineData(false, true)] [InlineData(false, true)]
[InlineData(true, false)] [InlineData(true, false)]
[InlineData(false, false)] [InlineData(false, false)]
public void TestBasicExpiryDateTime(bool disablePTimes, bool utc) public async Task TestBasicExpiryDateTime(bool disablePTimes, bool utc)
{ {
using (var muxer = Create(disabledCommands: GetMap(disablePTimes))) using (var muxer = Create(disabledCommands: GetMap(disablePTimes)))
{ {
...@@ -70,18 +71,18 @@ public void TestBasicExpiryDateTime(bool disablePTimes, bool utc) ...@@ -70,18 +71,18 @@ public void TestBasicExpiryDateTime(bool disablePTimes, bool utc)
conn.KeyExpire(key, DateTime.MaxValue, CommandFlags.FireAndForget); conn.KeyExpire(key, DateTime.MaxValue, CommandFlags.FireAndForget);
var e = conn.KeyTimeToLiveAsync(key); var e = conn.KeyTimeToLiveAsync(key);
Assert.Null(muxer.Wait(a)); Assert.Null(await a);
var time = muxer.Wait(b); var time = await b;
Assert.NotNull(time); Assert.NotNull(time);
Log("Time: {0}, Expected: {1}-{2}", time, TimeSpan.FromMinutes(59), TimeSpan.FromMinutes(60)); Log("Time: {0}, Expected: {1}-{2}", time, TimeSpan.FromMinutes(59), TimeSpan.FromMinutes(60));
Assert.True(time >= TimeSpan.FromMinutes(59)); Assert.True(time >= TimeSpan.FromMinutes(59));
Assert.True(time <= TimeSpan.FromMinutes(60)); Assert.True(time <= TimeSpan.FromMinutes(60));
Assert.Null(muxer.Wait(c)); Assert.Null(await c);
time = muxer.Wait(d); time = await d;
Assert.NotNull(time); Assert.NotNull(time);
Assert.True(time >= TimeSpan.FromMinutes(89)); Assert.True(time >= TimeSpan.FromMinutes(89));
Assert.True(time <= TimeSpan.FromMinutes(90)); Assert.True(time <= TimeSpan.FromMinutes(90));
Assert.Null(muxer.Wait(e)); Assert.Null(await e);
} }
} }
} }
......
...@@ -236,8 +236,10 @@ public async Task SubscriptionsSurviveMasterSwitchAsync() ...@@ -236,8 +236,10 @@ public async Task SubscriptionsSurviveMasterSwitchAsync()
Log("B: " + EndPointCollection.ToString(epB)); Log("B: " + EndPointCollection.ToString(epB));
subA.Publish(channel, "A1"); subA.Publish(channel, "A1");
subB.Publish(channel, "B1"); subB.Publish(channel, "B1");
subA.Ping(); Log("SubA ping: " + subA.Ping());
subB.Ping(); Log("SubB ping: " + subB.Ping());
// If redis is under load due to this suite, it may take a moment to send across.
await Task.Delay(250).ForAwait();
Assert.Equal(2, Interlocked.Read(ref aCount)); Assert.Equal(2, Interlocked.Read(ref aCount));
Assert.Equal(2, Interlocked.Read(ref bCount)); Assert.Equal(2, Interlocked.Read(ref bCount));
......
...@@ -150,12 +150,12 @@ public async Task HashIncrDecrFloatingPointAsync() ...@@ -150,12 +150,12 @@ public async Task HashIncrDecrFloatingPointAsync()
double sum = 0; double sum = 0;
foreach (var value in incr) foreach (var value in incr)
{ {
await db.HashIncrementAsync(key, field, value).ForAwait(); var t = db.HashIncrementAsync(key, field, value);
sum += value; sum += value;
} }
foreach (var value in decr) foreach (var value in decr)
{ {
await db.HashDecrementAsync(key, field, value).ForAwait(); var t = db.HashDecrementAsync(key, field, value);
sum -= value; sum -= value;
} }
var val = (double)await db.HashGetAsync(key, field).ForAwait(); var val = (double)await db.HashGetAsync(key, field).ForAwait();
......
...@@ -23,7 +23,7 @@ public void GeoAdd() ...@@ -23,7 +23,7 @@ public void GeoAdd()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
// add while not there // add while not there
Assert.True(db.GeoAdd(key, cefalù.Longitude, cefalù.Latitude, cefalù.Member)); Assert.True(db.GeoAdd(key, cefalù.Longitude, cefalù.Latitude, cefalù.Member));
...@@ -51,8 +51,8 @@ public void GetDistance() ...@@ -51,8 +51,8 @@ public void GetDistance()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.GeoAdd(key, all); db.GeoAdd(key, all, CommandFlags.FireAndForget);
var val = db.GeoDistance(key, "Palermo", "Catania", GeoUnit.Meters); var val = db.GeoDistance(key, "Palermo", "Catania", GeoUnit.Meters);
Assert.True(val.HasValue); Assert.True(val.HasValue);
var rounded = Math.Round(val.Value, 10); var rounded = Math.Round(val.Value, 10);
...@@ -71,8 +71,8 @@ public void GeoHash() ...@@ -71,8 +71,8 @@ public void GeoHash()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.GeoAdd(key, all); db.GeoAdd(key, all, CommandFlags.FireAndForget);
var hashes = db.GeoHash(key, new RedisValue[] { palermo.Member, "Nowhere", agrigento.Member }); var hashes = db.GeoHash(key, new RedisValue[] { palermo.Member, "Nowhere", agrigento.Member });
Assert.Equal(3, hashes.Length); Assert.Equal(3, hashes.Length);
...@@ -96,8 +96,8 @@ public void GeoGetPosition() ...@@ -96,8 +96,8 @@ public void GeoGetPosition()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.GeoAdd(key, all); db.GeoAdd(key, all, CommandFlags.FireAndForget);
var pos = db.GeoPosition(key, palermo.Member); var pos = db.GeoPosition(key, palermo.Member);
Assert.True(pos.HasValue); Assert.True(pos.HasValue);
...@@ -117,8 +117,8 @@ public void GeoRemove() ...@@ -117,8 +117,8 @@ public void GeoRemove()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.GeoAdd(key, all); db.GeoAdd(key, all, CommandFlags.FireAndForget);
var pos = db.GeoPosition(key, "Palermo"); var pos = db.GeoPosition(key, "Palermo");
Assert.True(pos.HasValue); Assert.True(pos.HasValue);
...@@ -140,8 +140,8 @@ public void GeoRadius() ...@@ -140,8 +140,8 @@ public void GeoRadius()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.GeoAdd(key, all); db.GeoAdd(key, all, CommandFlags.FireAndForget);
var results = db.GeoRadius(key, cefalù.Member, 60, GeoUnit.Miles, 2, Order.Ascending); var results = db.GeoRadius(key, cefalù.Member, 60, GeoUnit.Miles, 2, Order.Ascending);
Assert.Equal(2, results.Length); Assert.Equal(2, results.Length);
...@@ -180,7 +180,7 @@ public void GeoRadiusOverloads() ...@@ -180,7 +180,7 @@ public void GeoRadiusOverloads()
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
Assert.True(db.GeoAdd(key, -1.759925, 52.19493, "steve")); Assert.True(db.GeoAdd(key, -1.759925, 52.19493, "steve"));
Assert.True(db.GeoAdd(key, -3.360655, 54.66395, "dave")); Assert.True(db.GeoAdd(key, -3.360655, 54.66395, "dave"));
......
...@@ -20,13 +20,20 @@ public async Task TestIncrBy() ...@@ -20,13 +20,20 @@ public async Task TestIncrBy()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
await conn.KeyDeleteAsync(key).ForAwait(); var t = conn.KeyDeleteAsync(key).ForAwait();
for (int i = 1; i < 1000; i++)
var aTasks = new Task<long>[1000];
var bTasks = new Task<long>[1000];
for (int i = 1; i < 1001; i++)
{
aTasks[i - 1] = conn.HashIncrementAsync(key, "a", 1);
bTasks[i - 1] = conn.HashIncrementAsync(key, "b", -1);
}
await Task.WhenAll(bTasks).ForAwait();
for (int i = 1; i < 1001; i++)
{ {
Assert.Equal(i, await conn.HashIncrementAsync(key, "a", 1).ForAwait()); Assert.Equal(i, aTasks[i - 1].Result);
Assert.Equal(-i, await conn.HashIncrementAsync(key, "b", -1).ForAwait()); Assert.Equal(-i, bTasks[i - 1].Result);
//Assert.Equal(i, conn.Wait(conn.Hashes.Increment(5, key, "a", 1)));
//Assert.Equal(-i, conn.Wait(conn.Hashes.Increment(5, key, "b", -1)));
} }
} }
} }
...@@ -93,11 +100,19 @@ public async Task TestIncrByFloat() ...@@ -93,11 +100,19 @@ public async Task TestIncrByFloat()
Skip.IfMissingFeature(muxer, nameof(RedisFeatures.IncrementFloat), r => r.IncrementFloat); Skip.IfMissingFeature(muxer, nameof(RedisFeatures.IncrementFloat), r => r.IncrementFloat);
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
await conn.KeyDeleteAsync(key).ForAwait(); var del = conn.KeyDeleteAsync(key).ForAwait();
for (int i = 1; i < 1000; i++) var aTasks = new Task<double>[1000];
var bTasks = new Task<double>[1000];
for (int i = 1; i < 1001; i++)
{ {
Assert.Equal(i, await conn.HashIncrementAsync(key, "a", 1.0).ForAwait()); aTasks[i-1] = conn.HashIncrementAsync(key, "a", 1.0);
Assert.Equal(-i, await conn.HashIncrementAsync(key, "b", -1.0).ForAwait()); bTasks[i-1] = conn.HashIncrementAsync(key, "b", -1.0);
}
await Task.WhenAll(bTasks).ForAwait();
for (int i = 1; i < 1001; i++)
{
Assert.Equal(i, aTasks[i-1].Result);
Assert.Equal(-i, bTasks[i-1].Result);
} }
} }
} }
...@@ -113,15 +128,16 @@ public async Task TestGetAll() ...@@ -113,15 +128,16 @@ public async Task TestGetAll()
var shouldMatch = new Dictionary<Guid, int>(); var shouldMatch = new Dictionary<Guid, int>();
var random = new Random(); var random = new Random();
for (int i = 1; i < 1000; i++) for (int i = 0; i < 1000; i++)
{ {
var guid = Guid.NewGuid(); var guid = Guid.NewGuid();
var value = random.Next(int.MaxValue); var value = random.Next(int.MaxValue);
shouldMatch[guid] = value; shouldMatch[guid] = value;
var x = await conn.HashIncrementAsync(key, guid.ToString(), value).ForAwait(); var t = conn.HashIncrementAsync(key, guid.ToString(), value);
} }
var inRedis = (await conn.HashGetAllAsync(key).ForAwait()).ToDictionary( var inRedis = (await conn.HashGetAllAsync(key).ForAwait()).ToDictionary(
x => Guid.Parse(x.Name), x => int.Parse(x.Value)); x => Guid.Parse(x.Name), x => int.Parse(x.Value));
...@@ -151,7 +167,7 @@ public async Task TestGet() ...@@ -151,7 +167,7 @@ public async Task TestGet()
shouldMatch[guid] = value; shouldMatch[guid] = value;
var x = await conn.HashIncrementAsync(key, guid.ToString(), value).ForAwait(); var t = conn.HashIncrementAsync(key, guid.ToString(), value);
} }
foreach (var k in shouldMatch.Keys) foreach (var k in shouldMatch.Keys)
...@@ -171,7 +187,7 @@ public async Task TestGet() ...@@ -171,7 +187,7 @@ public async Task TestGet()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); var del = conn.KeyDeleteAsync(hashkey).ForAwait();
var val0 = conn.HashGetAsync(hashkey, "field").ForAwait(); var val0 = conn.HashGetAsync(hashkey, "field").ForAwait();
var set0 = conn.HashSetAsync(hashkey, "field", "value1").ForAwait(); var set0 = conn.HashSetAsync(hashkey, "field", "value1").ForAwait();
...@@ -187,6 +203,7 @@ public async Task TestGet() ...@@ -187,6 +203,7 @@ public async Task TestGet()
var set4 = conn.HashSetAsync(hashkey, "empty_type2", RedisValue.EmptyString).ForAwait(); var set4 = conn.HashSetAsync(hashkey, "empty_type2", RedisValue.EmptyString).ForAwait();
var val5 = conn.HashGetAsync(hashkey, "empty_type2").ForAwait(); var val5 = conn.HashGetAsync(hashkey, "empty_type2").ForAwait();
await del;
Assert.Null((string)(await val0)); Assert.Null((string)(await val0));
Assert.True(await set0); Assert.True(await set0);
Assert.Equal("value1", await val1); Assert.Equal("value1", await val1);
...@@ -210,7 +227,7 @@ public async Task TestGet() ...@@ -210,7 +227,7 @@ public async Task TestGet()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); var del = conn.KeyDeleteAsync(hashkey).ForAwait();
var val0 = conn.HashGetAsync(hashkey, "field").ForAwait(); var val0 = conn.HashGetAsync(hashkey, "field").ForAwait();
var set0 = conn.HashSetAsync(hashkey, "field", "value1", When.NotExists).ForAwait(); var set0 = conn.HashSetAsync(hashkey, "field", "value1", When.NotExists).ForAwait();
...@@ -222,6 +239,7 @@ public async Task TestGet() ...@@ -222,6 +239,7 @@ public async Task TestGet()
var val3 = conn.HashGetAsync(hashkey, "field-blob").ForAwait(); var val3 = conn.HashGetAsync(hashkey, "field-blob").ForAwait();
var set3 = conn.HashSetAsync(hashkey, "field-blob", Encoding.UTF8.GetBytes("value3"), When.NotExists).ForAwait(); var set3 = conn.HashSetAsync(hashkey, "field-blob", Encoding.UTF8.GetBytes("value3"), When.NotExists).ForAwait();
await del;
Assert.Null((string)(await val0)); Assert.Null((string)(await val0));
Assert.True(await set0); Assert.True(await set0);
Assert.Equal("value1", await val1); Assert.Equal("value1", await val1);
...@@ -256,15 +274,15 @@ public async Task TestGet() ...@@ -256,15 +274,15 @@ public async Task TestGet()
} }
[Fact] [Fact]
public void TestDelMulti() // https://redis.io/commands/hdel public async Task TestDelMulti() // https://redis.io/commands/hdel
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
conn.HashSetAsync(hashkey, "key1", "val1"); conn.HashSet(hashkey, "key1", "val1", flags: CommandFlags.FireAndForget);
conn.HashSetAsync(hashkey, "key2", "val2"); conn.HashSet(hashkey, "key2", "val2", flags: CommandFlags.FireAndForget);
conn.HashSetAsync(hashkey, "key3", "val3"); conn.HashSet(hashkey, "key3", "val3", flags: CommandFlags.FireAndForget);
var s1 = conn.HashExistsAsync(hashkey, "key1"); var s1 = conn.HashExistsAsync(hashkey, "key1");
var s2 = conn.HashExistsAsync(hashkey, "key2"); var s2 = conn.HashExistsAsync(hashkey, "key2");
...@@ -276,34 +294,34 @@ public async Task TestGet() ...@@ -276,34 +294,34 @@ public async Task TestGet()
var d2 = conn.HashExistsAsync(hashkey, "key2"); var d2 = conn.HashExistsAsync(hashkey, "key2");
var d3 = conn.HashExistsAsync(hashkey, "key3"); var d3 = conn.HashExistsAsync(hashkey, "key3");
Assert.True(conn.Wait(s1)); Assert.True(await s1);
Assert.True(conn.Wait(s2)); Assert.True(await s2);
Assert.True(conn.Wait(s3)); Assert.True(await s3);
Assert.Equal(2, conn.Wait(removed)); Assert.Equal(2, await removed);
Assert.False(conn.Wait(d1)); Assert.False(await d1);
Assert.True(conn.Wait(d2)); Assert.True(await d2);
Assert.False(conn.Wait(d3)); Assert.False(await d3);
var removeFinal = conn.HashDeleteAsync(hashkey, new RedisValue[] { "key2" }); var removeFinal = conn.HashDeleteAsync(hashkey, new RedisValue[] { "key2" });
Assert.Equal(0, conn.Wait(conn.HashLengthAsync(hashkey))); Assert.Equal(0, await conn.HashLengthAsync(hashkey).ForAwait());
Assert.Equal(1, conn.Wait(removeFinal)); Assert.Equal(1, await removeFinal);
} }
} }
[Fact] [Fact]
public void TestDelMultiInsideTransaction() // https://redis.io/commands/hdel public async Task TestDelMultiInsideTransaction() // https://redis.io/commands/hdel
{ {
using (var outer = Create()) using (var outer = Create())
{ {
var conn = outer.GetDatabase().CreateTransaction(); var conn = outer.GetDatabase().CreateTransaction();
{ {
var hashkey = Me(); var hashkey = Me();
conn.HashSetAsync(hashkey, "key1", "val1"); var t = conn.HashSetAsync(hashkey, "key1", "val1");
conn.HashSetAsync(hashkey, "key2", "val2"); var t2 = conn.HashSetAsync(hashkey, "key2", "val2");
conn.HashSetAsync(hashkey, "key3", "val3"); var t3 = conn.HashSetAsync(hashkey, "key3", "val3");
var s1 = conn.HashExistsAsync(hashkey, "key1"); var s1 = conn.HashExistsAsync(hashkey, "key1");
var s2 = conn.HashExistsAsync(hashkey, "key2"); var s2 = conn.HashExistsAsync(hashkey, "key2");
...@@ -317,15 +335,15 @@ public async Task TestGet() ...@@ -317,15 +335,15 @@ public async Task TestGet()
conn.Execute(); conn.Execute();
Assert.True(conn.Wait(s1)); Assert.True(await s1);
Assert.True(conn.Wait(s2)); Assert.True(await s2);
Assert.True(conn.Wait(s3)); Assert.True(await s3);
Assert.Equal(2, conn.Wait(removed)); Assert.Equal(2, await removed);
Assert.False(conn.Wait(d1)); Assert.False(await d1);
Assert.True(conn.Wait(d2)); Assert.True(await d2);
Assert.False(conn.Wait(d3)); Assert.False(await d3);
} }
} }
} }
...@@ -337,11 +355,11 @@ public async Task TestGet() ...@@ -337,11 +355,11 @@ public async Task TestGet()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); var del = conn.KeyDeleteAsync(hashkey).ForAwait();
var ex0 = conn.HashExistsAsync(hashkey, "field").ForAwait(); var ex0 = conn.HashExistsAsync(hashkey, "field").ForAwait();
await conn.HashSetAsync(hashkey, "field", "value").ForAwait(); var set = conn.HashSetAsync(hashkey, "field", "value").ForAwait();
var ex1 = conn.HashExistsAsync(hashkey, "field").ForAwait(); var ex1 = conn.HashExistsAsync(hashkey, "field").ForAwait();
await conn.HashDeleteAsync(hashkey, "field").ForAwait(); var del2= conn.HashDeleteAsync(hashkey, "field").ForAwait();
var ex2 = conn.HashExistsAsync(hashkey, "field").ForAwait(); var ex2 = conn.HashExistsAsync(hashkey, "field").ForAwait();
Assert.False(await ex0); Assert.False(await ex0);
...@@ -360,14 +378,13 @@ public async Task TestGet() ...@@ -360,14 +378,13 @@ public async Task TestGet()
await conn.KeyDeleteAsync(hashKey).ForAwait(); await conn.KeyDeleteAsync(hashKey).ForAwait();
var keys0 = await conn.HashKeysAsync(hashKey).ForAwait(); var keys0 = await conn.HashKeysAsync(hashKey).ForAwait();
Assert.Empty(keys0);
await conn.HashSetAsync(hashKey, "foo", "abc").ForAwait(); await conn.HashSetAsync(hashKey, "foo", "abc").ForAwait();
await conn.HashSetAsync(hashKey, "bar", "def").ForAwait(); await conn.HashSetAsync(hashKey, "bar", "def").ForAwait();
var keys1 = conn.HashKeysAsync(hashKey); var keys1 = conn.HashKeysAsync(hashKey);
Assert.Empty(keys0);
var arr = await keys1; var arr = await keys1;
Assert.Equal(2, arr.Length); Assert.Equal(2, arr.Length);
Assert.Equal("foo", arr[0]); Assert.Equal("foo", arr[0]);
...@@ -407,17 +424,17 @@ public async Task TestGet() ...@@ -407,17 +424,17 @@ public async Task TestGet()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); conn.KeyDelete(hashkey, CommandFlags.FireAndForget);
var len0 = await conn.HashLengthAsync(hashkey).ForAwait(); var len0 = conn.HashLengthAsync(hashkey);
await conn.HashSetAsync(hashkey, "foo", "abc").ForAwait(); conn.HashSet(hashkey, "foo", "abc", flags: CommandFlags.FireAndForget);
await conn.HashSetAsync(hashkey, "bar", "def").ForAwait(); conn.HashSet(hashkey, "bar", "def", flags: CommandFlags.FireAndForget);
var len1 = await conn.HashLengthAsync(hashkey).ForAwait(); var len1 = conn.HashLengthAsync(hashkey);
Assert.Equal(0, len0); Assert.Equal(0, await len0);
Assert.Equal(2, len1); Assert.Equal(2, await len1);
} }
} }
...@@ -428,13 +445,13 @@ public async Task TestGet() ...@@ -428,13 +445,13 @@ public async Task TestGet()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); conn.KeyDelete(hashkey, CommandFlags.FireAndForget);
RedisValue[] fields = { "foo", "bar", "blop" }; RedisValue[] fields = { "foo", "bar", "blop" };
var arr0 = await conn.HashGetAsync(hashkey, fields).ForAwait(); var arr0 = await conn.HashGetAsync(hashkey, fields).ForAwait();
await conn.HashSetAsync(hashkey, "foo", "abc").ForAwait(); conn.HashSet(hashkey, "foo", "abc", flags: CommandFlags.FireAndForget);
await conn.HashSetAsync(hashkey, "bar", "def").ForAwait(); conn.HashSet(hashkey, "bar", "def", flags: CommandFlags.FireAndForget);
var arr1 = await conn.HashGetAsync(hashkey, fields).ForAwait(); var arr1 = await conn.HashGetAsync(hashkey, fields).ForAwait();
var arr2 = await conn.HashGetAsync(hashkey, fields).ForAwait(); var arr2 = await conn.HashGetAsync(hashkey, fields).ForAwait();
...@@ -457,23 +474,23 @@ public async Task TestGet() ...@@ -457,23 +474,23 @@ public async Task TestGet()
} }
[Fact] [Fact]
public async Task TestGetPairs() // https://redis.io/commands/hgetall public void TestGetPairs() // https://redis.io/commands/hgetall
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); conn.KeyDeleteAsync(hashkey);
var result0 = await conn.HashGetAllAsync(hashkey).ForAwait(); var result0 = conn.HashGetAllAsync(hashkey);
await conn.HashSetAsync(hashkey, "foo", "abc").ForAwait(); conn.HashSetAsync(hashkey, "foo", "abc");
await conn.HashSetAsync(hashkey, "bar", "def").ForAwait(); conn.HashSetAsync(hashkey, "bar", "def");
var result1 = await conn.HashGetAllAsync(hashkey).ForAwait(); var result1 = conn.HashGetAllAsync(hashkey);
Assert.Empty(result0); Assert.Empty(muxer.Wait(result0));
var result = result1.ToStringDictionary(); var result = muxer.Wait(result1).ToStringDictionary();
Assert.Equal(2, result.Count); Assert.Equal(2, result.Count);
Assert.Equal("abc", result["foo"]); Assert.Equal("abc", result["foo"]);
Assert.Equal("def", result["bar"]); Assert.Equal("def", result["bar"]);
...@@ -481,25 +498,25 @@ public async Task TestGet() ...@@ -481,25 +498,25 @@ public async Task TestGet()
} }
[Fact] [Fact]
public async Task TestSetPairs() // https://redis.io/commands/hmset public void TestSetPairs() // https://redis.io/commands/hmset
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var hashkey = Me(); var hashkey = Me();
await conn.KeyDeleteAsync(hashkey).ForAwait(); conn.KeyDeleteAsync(hashkey).ForAwait();
var result0 = await conn.HashGetAllAsync(hashkey).ForAwait(); var result0 = conn.HashGetAllAsync(hashkey);
var data = new HashEntry[] { var data = new HashEntry[] {
new HashEntry("foo", Encoding.UTF8.GetBytes("abc")), new HashEntry("foo", Encoding.UTF8.GetBytes("abc")),
new HashEntry("bar", Encoding.UTF8.GetBytes("def")) new HashEntry("bar", Encoding.UTF8.GetBytes("def"))
}; };
await conn.HashSetAsync(hashkey, data).ForAwait(); conn.HashSetAsync(hashkey, data).ForAwait();
var result1 = await conn.HashGetAllAsync(hashkey).ForAwait(); var result1 = conn.Wait(conn.HashGetAllAsync(hashkey));
Assert.Empty(result0); Assert.Empty(result0.Result);
var result = result1.ToStringDictionary(); var result = result1.ToStringDictionary();
Assert.Equal(2, result.Count); Assert.Equal(2, result.Count);
Assert.Equal("abc", result["foo"]); Assert.Equal("abc", result["foo"]);
......
...@@ -242,11 +242,11 @@ private bool SendDataCommand(byte[] data, string cmd, params object[] args) ...@@ -242,11 +242,11 @@ private bool SendDataCommand(byte[] data, string cmd, params object[] args)
if (socket == null) if (socket == null)
return false; return false;
var s = args.Length > 0 ? String.Format(cmd, args) : cmd; var s = args.Length > 0 ? string.Format(cmd, args) : cmd;
byte[] r = Encoding.UTF8.GetBytes(s); byte[] r = Encoding.UTF8.GetBytes(s);
try try
{ {
Log("S: " + String.Format(cmd, args)); Log("S: " + string.Format(cmd, args));
socket.Send(r); socket.Send(r);
if (data != null) if (data != null)
{ {
...@@ -272,11 +272,11 @@ private bool SendCommand(string cmd, params object[] args) ...@@ -272,11 +272,11 @@ private bool SendCommand(string cmd, params object[] args)
if (socket == null) if (socket == null)
return false; return false;
var s = args?.Length > 0 ? String.Format(cmd, args) : cmd; var s = args?.Length > 0 ? string.Format(cmd, args) : cmd;
byte[] r = Encoding.UTF8.GetBytes(s); byte[] r = Encoding.UTF8.GetBytes(s);
try try
{ {
Log("S: " + String.Format(cmd, args)); Log("S: " + string.Format(cmd, args));
socket.Send(r); socket.Send(r);
} }
catch (SocketException) catch (SocketException)
...@@ -293,7 +293,7 @@ private bool SendCommand(string cmd, params object[] args) ...@@ -293,7 +293,7 @@ private bool SendCommand(string cmd, params object[] args)
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void Log(string fmt, params object[] args) private void Log(string fmt, params object[] args)
{ {
Console.WriteLine("{0}", String.Format(fmt, args).Trim()); Console.WriteLine("{0}", string.Format(fmt, args).Trim());
} }
private void ExpectSuccess() private void ExpectSuccess()
...@@ -416,7 +416,7 @@ private byte[] ReadData() ...@@ -416,7 +416,7 @@ private byte[] ReadData()
if (r == "$-1") if (r == "$-1")
return null; return null;
if (Int32.TryParse(r.Substring(1), out int n)) if (int.TryParse(r.Substring(1), out int n))
{ {
var retbuf = new byte[n]; var retbuf = new byte[n];
...@@ -439,7 +439,7 @@ private byte[] ReadData() ...@@ -439,7 +439,7 @@ private byte[] ReadData()
//returns the number of matches //returns the number of matches
if (c == '*') if (c == '*')
{ {
if (Int32.TryParse(r.Substring(1), out int n)) if (int.TryParse(r.Substring(1), out int n))
return n <= 0 ? new byte[0] : ReadData(); return n <= 0 ? new byte[0] : ReadData();
throw new ResponseException("Unexpected length parameter" + r); throw new ResponseException("Unexpected length parameter" + r);
...@@ -759,16 +759,16 @@ public byte[][] GetUnionOfSets(params string[] keys) ...@@ -759,16 +759,16 @@ public byte[][] GetUnionOfSets(params string[] keys)
private void StoreSetCommands(string cmd, string destKey, params string[] keys) private void StoreSetCommands(string cmd, string destKey, params string[] keys)
{ {
if (String.IsNullOrEmpty(cmd)) if (string.IsNullOrEmpty(cmd))
throw new ArgumentNullException(nameof(cmd)); throw new ArgumentNullException(nameof(cmd));
if (String.IsNullOrEmpty(destKey)) if (string.IsNullOrEmpty(destKey))
throw new ArgumentNullException(nameof(destKey)); throw new ArgumentNullException(nameof(destKey));
if (keys == null) if (keys == null)
throw new ArgumentNullException(nameof(keys)); throw new ArgumentNullException(nameof(keys));
SendExpectSuccess("{0} {1} {2}\r\n", cmd, destKey, String.Join(" ", keys)); SendExpectSuccess("{0} {1} {2}\r\n", cmd, destKey, string.Join(" ", keys));
} }
public void StoreUnionOfSets(string destKey, params string[] keys) public void StoreUnionOfSets(string destKey, params string[] keys)
...@@ -835,15 +835,15 @@ public class SortOptions ...@@ -835,15 +835,15 @@ public class SortOptions
public string Key { get; set; } public string Key { get; set; }
public bool Descending { get; set; } public bool Descending { get; set; }
public bool Lexographically { get; set; } public bool Lexographically { get; set; }
public Int32 LowerLimit { get; set; } public int LowerLimit { get; set; }
public Int32 UpperLimit { get; set; } public int UpperLimit { get; set; }
public string By { get; set; } public string By { get; set; }
public string StoreInKey { get; set; } public string StoreInKey { get; set; }
public string Get { get; set; } public string Get { get; set; }
public string ToCommand() public string ToCommand()
{ {
var command = "SORT " + this.Key; var command = "SORT " + Key;
if (LowerLimit != 0 || UpperLimit != 0) if (LowerLimit != 0 || UpperLimit != 0)
command += " LIMIT " + LowerLimit + " " + UpperLimit; command += " LIMIT " + LowerLimit + " " + UpperLimit;
if (Lexographically) if (Lexographically)
...@@ -857,4 +857,4 @@ public string ToCommand() ...@@ -857,4 +857,4 @@ public string ToCommand()
return command; return command;
} }
} }
} }
\ No newline at end of file
...@@ -12,11 +12,12 @@ public class SO10504853 : TestBase ...@@ -12,11 +12,12 @@ public class SO10504853 : TestBase
[Fact] [Fact]
public void LoopLotsOfTrivialStuff() public void LoopLotsOfTrivialStuff()
{ {
var key = Me();
Trace.WriteLine("### init"); Trace.WriteLine("### init");
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
conn.KeyDelete("lots-trivial"); conn.KeyDelete(key, CommandFlags.FireAndForget);
} }
const int COUNT = 2; const int COUNT = 2;
for (int i = 0; i < COUNT; i++) for (int i = 0; i < COUNT; i++)
...@@ -25,14 +26,14 @@ public void LoopLotsOfTrivialStuff() ...@@ -25,14 +26,14 @@ public void LoopLotsOfTrivialStuff()
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
Assert.Equal(i + 1, conn.StringIncrement("lots-trivial")); Assert.Equal(i + 1, conn.StringIncrement(key));
} }
} }
Trace.WriteLine("### close"); Trace.WriteLine("### close");
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
Assert.Equal(COUNT, (long)conn.StringGet("lots-trivial")); Assert.Equal(COUNT, (long)conn.StringGet(key));
} }
} }
...@@ -42,12 +43,13 @@ public void ExecuteWithEmptyStartingPoint() ...@@ -42,12 +43,13 @@ public void ExecuteWithEmptyStartingPoint()
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me();
var task = new { priority = 3 }; var task = new { priority = 3 };
conn.KeyDeleteAsync("item:1"); conn.KeyDeleteAsync(key);
conn.HashSetAsync("item:1", "something else", "abc"); conn.HashSetAsync(key, "something else", "abc");
conn.HashSetAsync("item:1", "priority", task.priority.ToString()); conn.HashSetAsync(key, "priority", task.priority.ToString());
var taskResult = conn.HashGetAsync("item:1", "priority"); var taskResult = conn.HashGetAsync(key, "priority");
conn.Wait(taskResult); conn.Wait(taskResult);
...@@ -60,17 +62,18 @@ public void ExecuteWithEmptyStartingPoint() ...@@ -60,17 +62,18 @@ public void ExecuteWithEmptyStartingPoint()
[Fact] [Fact]
public void ExecuteWithNonHashStartingPoint() public void ExecuteWithNonHashStartingPoint()
{ {
var key = Me();
Assert.Throws<RedisServerException>(() => Assert.Throws<RedisServerException>(() =>
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var task = new { priority = 3 }; var task = new { priority = 3 };
conn.KeyDeleteAsync("item:1"); conn.KeyDeleteAsync(key);
conn.StringSetAsync("item:1", "not a hash"); conn.StringSetAsync(key, "not a hash");
conn.HashSetAsync("item:1", "priority", task.priority.ToString()); conn.HashSetAsync(key, "priority", task.priority.ToString());
var taskResult = conn.HashGetAsync("item:1", "priority"); var taskResult = conn.HashGetAsync(key, "priority");
try try
{ {
......
using System; using System;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -10,7 +11,7 @@ public class SO10825542 : TestBase ...@@ -10,7 +11,7 @@ public class SO10825542 : TestBase
public SO10825542(ITestOutputHelper output) : base(output) { } public SO10825542(ITestOutputHelper output) : base(output) { }
[Fact] [Fact]
public void Execute() public async Task Execute()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -18,14 +19,13 @@ public void Execute() ...@@ -18,14 +19,13 @@ public void Execute()
var con = muxer.GetDatabase(); var con = muxer.GetDatabase();
// set the field value and expiration // set the field value and expiration
con.HashSetAsync(key, "field1", Encoding.UTF8.GetBytes("hello world")); var hsa = con.HashSetAsync(key, "field1", Encoding.UTF8.GetBytes("hello world"));
con.KeyExpireAsync(key, TimeSpan.FromSeconds(7200)); var kea = con.KeyExpireAsync(key, TimeSpan.FromSeconds(7200));
con.HashSetAsync(key, "field2", "fooobar"); var hsa2 = con.HashSetAsync(key, "field2", "fooobar");
var task = con.HashGetAllAsync(key); var result = await con.HashGetAllAsync(key).ForAwait();
con.Wait(task);
Assert.Equal(2, task.Result.Length); Assert.Equal(2, result.Length);
var dict = task.Result.ToStringDictionary(); var dict = result.ToStringDictionary();
Assert.Equal("hello world", dict["field1"]); Assert.Equal("hello world", dict["field1"]);
Assert.Equal("fooobar", dict["field2"]); Assert.Equal("fooobar", dict["field2"]);
} }
......
...@@ -19,9 +19,9 @@ public async Task Exec() ...@@ -19,9 +19,9 @@ public async Task Exec()
var cache = conn.GetDatabase(); var cache = conn.GetDatabase();
// setup some data // setup some data
cache.KeyDelete(key); cache.KeyDelete(key, CommandFlags.FireAndForget);
cache.HashSet(key, "full", "some value"); cache.HashSet(key, "full", "some value", flags: CommandFlags.FireAndForget);
cache.KeyExpire(key, TimeSpan.FromSeconds(3)); cache.KeyExpire(key, TimeSpan.FromSeconds(3), CommandFlags.FireAndForget);
// test while exists // test while exists
var keyExists = cache.KeyExists(key); var keyExists = cache.KeyExists(key);
...@@ -41,7 +41,7 @@ public async Task Exec() ...@@ -41,7 +41,7 @@ public async Task Exec()
Assert.False(keyExists); Assert.False(keyExists);
Assert.Null(ttl); Assert.Null(ttl);
var r = fullWait.Result; var r = await fullWait;
Assert.True(r.IsNull); Assert.True(r.IsNull);
Assert.Null((string)r); Assert.Null((string)r);
} }
......
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -18,7 +17,7 @@ public async Task SetExpirationToPassed() ...@@ -18,7 +17,7 @@ public async Task SetExpirationToPassed()
{ {
// Given // Given
var cache = conn.GetDatabase(); var cache = conn.GetDatabase();
cache.KeyDelete(key); cache.KeyDelete(key, CommandFlags.FireAndForget);
cache.HashSet(key, "full", "test", When.NotExists, CommandFlags.PreferMaster); cache.HashSet(key, "full", "test", When.NotExists, CommandFlags.PreferMaster);
await Task.Delay(2000).ForAwait(); await Task.Delay(2000).ForAwait();
......
...@@ -38,7 +38,7 @@ public void FlushFetchRandomKey() ...@@ -38,7 +38,7 @@ public void FlushFetchRandomKey()
Skip.IfMissingDatabase(conn, dbId); Skip.IfMissingDatabase(conn, dbId);
var db = conn.GetDatabase(dbId); var db = conn.GetDatabase(dbId);
var prefix = Me(); var prefix = Me();
conn.GetServer(TestConfig.Current.MasterServerAndPort).FlushDatabase(dbId); conn.GetServer(TestConfig.Current.MasterServerAndPort).FlushDatabase(dbId, CommandFlags.FireAndForget);
string anyKey = db.KeyRandom(); string anyKey = db.KeyRandom();
Assert.Null(anyKey); Assert.Null(anyKey);
...@@ -56,12 +56,12 @@ public void Zeros() ...@@ -56,12 +56,12 @@ public void Zeros()
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringSet(key, 123); db.StringSet(key, 123, flags: CommandFlags.FireAndForget);
int k = (int)db.StringGet(key); int k = (int)db.StringGet(key);
Assert.Equal(123, k); Assert.Equal(123, k);
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
int i = (int)db.StringGet(key); int i = (int)db.StringGet(key);
Assert.Equal(0, i); Assert.Equal(0, i);
......
...@@ -14,7 +14,7 @@ public void QueryRangeAndLengthByLex() ...@@ -14,7 +14,7 @@ public void QueryRangeAndLengthByLex()
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SortedSetAdd(key, db.SortedSetAdd(key,
new SortedSetEntry[] new SortedSetEntry[]
...@@ -26,7 +26,7 @@ public void QueryRangeAndLengthByLex() ...@@ -26,7 +26,7 @@ public void QueryRangeAndLengthByLex()
new SortedSetEntry("e", 0), new SortedSetEntry("e", 0),
new SortedSetEntry("f", 0), new SortedSetEntry("f", 0),
new SortedSetEntry("g", 0), new SortedSetEntry("g", 0),
}); }, CommandFlags.FireAndForget);
var set = db.SortedSetRangeByValue(key, default(RedisValue), "c"); var set = db.SortedSetRangeByValue(key, default(RedisValue), "c");
var count = db.SortedSetLengthByValue(key, default(RedisValue), "c"); var count = db.SortedSetLengthByValue(key, default(RedisValue), "c");
...@@ -43,7 +43,6 @@ public void QueryRangeAndLengthByLex() ...@@ -43,7 +43,6 @@ public void QueryRangeAndLengthByLex()
set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, 1, 3); set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, 1, 3);
Equate(set, set.Length, "c", "d", "e"); Equate(set, set.Length, "c", "d", "e");
set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, Order.Descending, 1, 3); set = db.SortedSetRangeByValue(key, "aaa", "g", Exclude.Stop, Order.Descending, 1, 3);
Equate(set, set.Length, "e", "d", "c"); Equate(set, set.Length, "e", "d", "c");
...@@ -59,7 +58,7 @@ public void RemoveRangeByLex() ...@@ -59,7 +58,7 @@ public void RemoveRangeByLex()
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SortedSetAdd(key, db.SortedSetAdd(key,
new SortedSetEntry[] new SortedSetEntry[]
...@@ -69,7 +68,7 @@ public void RemoveRangeByLex() ...@@ -69,7 +68,7 @@ public void RemoveRangeByLex()
new SortedSetEntry("c", 0), new SortedSetEntry("c", 0),
new SortedSetEntry("d", 0), new SortedSetEntry("d", 0),
new SortedSetEntry("e", 0), new SortedSetEntry("e", 0),
}); }, CommandFlags.FireAndForget);
db.SortedSetAdd(key, db.SortedSetAdd(key,
new SortedSetEntry[] new SortedSetEntry[]
{ {
...@@ -78,7 +77,7 @@ public void RemoveRangeByLex() ...@@ -78,7 +77,7 @@ public void RemoveRangeByLex()
new SortedSetEntry("zip", 0), new SortedSetEntry("zip", 0),
new SortedSetEntry("ALPHA", 0), new SortedSetEntry("ALPHA", 0),
new SortedSetEntry("alpha", 0), new SortedSetEntry("alpha", 0),
}); }, CommandFlags.FireAndForget);
var set = db.SortedSetRangeByRank(key); var set = db.SortedSetRangeByRank(key);
Equate(set, set.Length, "ALPHA", "aaaa", "alpha", "b", "c", "d", "e", "foo", "zap", "zip"); Equate(set, set.Length, "ALPHA", "aaaa", "alpha", "b", "c", "d", "e", "foo", "zap", "zip");
......
...@@ -17,18 +17,18 @@ public void Ranges() ...@@ -17,18 +17,18 @@ public void Ranges()
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key, CommandFlags.FireAndForget); db.KeyDelete(key, CommandFlags.FireAndForget);
db.ListRightPush(key, "abcdefghijklmnopqrstuvwxyz".Select(x => (RedisValue)x.ToString()).ToArray()); db.ListRightPush(key, "abcdefghijklmnopqrstuvwxyz".Select(x => (RedisValue)x.ToString()).ToArray(), CommandFlags.FireAndForget);
Assert.Equal(26, db.ListLength(key)); Assert.Equal(26, db.ListLength(key));
Assert.Equal("abcdefghijklmnopqrstuvwxyz", string.Concat(db.ListRange(key))); Assert.Equal("abcdefghijklmnopqrstuvwxyz", string.Concat(db.ListRange(key)));
var last10 = db.ListRange(key, -10, -1); var last10 = db.ListRange(key, -10, -1);
Assert.Equal("qrstuvwxyz", string.Concat(last10)); Assert.Equal("qrstuvwxyz", string.Concat(last10));
db.ListTrim(key, 0, -11); db.ListTrim(key, 0, -11, CommandFlags.FireAndForget);
Assert.Equal(16, db.ListLength(key)); Assert.Equal(16, db.ListLength(key));
Assert.Equal("abcdefghijklmnop", string.Concat(db.ListRange(key))); Assert.Equal("abcdefghijklmnop", string.Concat(db.ListRange(key)));
} }
} }
} }
} }
\ No newline at end of file
...@@ -72,35 +72,8 @@ public void TestOpCountByVersionLocal_UpLevel() ...@@ -72,35 +72,8 @@ public void TestOpCountByVersionLocal_UpLevel()
{ {
TestLockOpCountByVersion(conn, 1, false); TestLockOpCountByVersion(conn, 1, false);
TestLockOpCountByVersion(conn, 1, true); TestLockOpCountByVersion(conn, 1, true);
//TestManualLockOpCountByVersion(conn, 5, false);
//TestManualLockOpCountByVersion(conn, 3, true);
} }
} }
//[Test]
//public void TestOpCountByVersionLocal_DownLevel()
//{
// using (var conn = GetUnsecuredConnection(open: false))
// {
// conn.SetServerVersion(new Version(2, 6, 0), ServerType.Master);
// TestLockOpCountByVersion(conn, 5, false);
// TestLockOpCountByVersion(conn, 3, true);
// //TestManualLockOpCountByVersion(conn, 5, false);
// //TestManualLockOpCountByVersion(conn, 3, true);
// }
//}
//[Test]
//public void TestOpCountByVersionRemote()
//{
// using (var conn = GetRemoteConnection(open: false))
// {
// TestLockOpCountByVersion(conn, 1, false);
// TestLockOpCountByVersion(conn, 1, true);
// //TestManualLockOpCountByVersion(conn, 1, false);
// //TestManualLockOpCountByVersion(conn, 1, true);
// }
//}
private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expectedOps, bool existFirst) private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expectedOps, bool existFirst)
{ {
...@@ -108,13 +81,13 @@ private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expectedOp ...@@ -108,13 +81,13 @@ private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expectedOp
RedisKey Key = Me(); RedisKey Key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(Key); db.KeyDelete(Key, CommandFlags.FireAndForget);
RedisValue newVal = "us:" + Guid.NewGuid().ToString(); RedisValue newVal = "us:" + Guid.NewGuid().ToString();
RedisValue expectedVal = newVal; RedisValue expectedVal = newVal;
if (existFirst) if (existFirst)
{ {
expectedVal = "other:" + Guid.NewGuid().ToString(); expectedVal = "other:" + Guid.NewGuid().ToString();
db.StringSet(Key, expectedVal, TimeSpan.FromSeconds(LockDuration)); db.StringSet(Key, expectedVal, TimeSpan.FromSeconds(LockDuration), flags: CommandFlags.FireAndForget);
} }
long countBefore = GetServer(conn).GetCounters().Interactive.OperationCount; long countBefore = GetServer(conn).GetCounters().Interactive.OperationCount;
...@@ -145,7 +118,7 @@ private ConnectionMultiplexer Create(TestMode mode) ...@@ -145,7 +118,7 @@ private ConnectionMultiplexer Create(TestMode mode)
} }
[Theory, MemberData(nameof(TestModes))] [Theory, MemberData(nameof(TestModes))]
public void TakeLockAndExtend(TestMode mode) public async Task TakeLockAndExtend(TestMode mode)
{ {
bool withTran = mode == TestMode.MultiExec; bool withTran = mode == TestMode.MultiExec;
using (var conn = Create(mode)) using (var conn = Create(mode))
...@@ -158,7 +131,7 @@ public void TakeLockAndExtend(TestMode mode) ...@@ -158,7 +131,7 @@ public void TakeLockAndExtend(TestMode mode)
var db = conn.GetDatabase(DB); var db = conn.GetDatabase(DB);
db.KeyDelete(Key); db.KeyDelete(Key, CommandFlags.FireAndForget);
var t1 = db.LockTakeAsync(Key, right, TimeSpan.FromSeconds(20)); var t1 = db.LockTakeAsync(Key, right, TimeSpan.FromSeconds(20));
var t1b = db.LockTakeAsync(Key, wrong, TimeSpan.FromSeconds(10)); var t1b = db.LockTakeAsync(Key, wrong, TimeSpan.FromSeconds(10));
...@@ -178,22 +151,22 @@ public void TakeLockAndExtend(TestMode mode) ...@@ -178,22 +151,22 @@ public void TakeLockAndExtend(TestMode mode)
Assert.NotEqual(default(RedisValue), right); Assert.NotEqual(default(RedisValue), right);
Assert.NotEqual(default(RedisValue), wrong); Assert.NotEqual(default(RedisValue), wrong);
Assert.NotEqual(right, wrong); Assert.NotEqual(right, wrong);
Assert.True(conn.Wait(t1), "1"); Assert.True(await t1, "1");
Assert.False(conn.Wait(t1b), "1b"); Assert.False(await t1b, "1b");
Assert.Equal(right, conn.Wait(t2)); Assert.Equal(right, await t2);
if (withTran) Assert.False(conn.Wait(t3), "3"); if (withTran) Assert.False(await t3, "3");
Assert.Equal(right, conn.Wait(t4)); Assert.Equal(right, await t4);
if (withTran) Assert.False(conn.Wait(t5), "5"); if (withTran) Assert.False(await t5, "5");
Assert.Equal(right, conn.Wait(t6)); Assert.Equal(right, await t6);
var ttl = conn.Wait(t7).Value.TotalSeconds; var ttl = (await t7).Value.TotalSeconds;
Assert.True(ttl > 0 && ttl <= 20, "7"); Assert.True(ttl > 0 && ttl <= 20, "7");
Assert.True(conn.Wait(t8), "8"); Assert.True(await t8, "8");
Assert.Equal(right, conn.Wait(t9)); Assert.Equal(right, await t9);
ttl = conn.Wait(t10).Value.TotalSeconds; ttl = (await t10).Value.TotalSeconds;
Assert.True(ttl > 50 && ttl <= 60, "10"); Assert.True(ttl > 50 && ttl <= 60, "10");
Assert.True(conn.Wait(t11), "11"); Assert.True(await t11, "11");
Assert.Null((string)conn.Wait(t12)); Assert.Null((string)await t12);
Assert.True(conn.Wait(t13), "13"); Assert.True(await t13, "13");
} }
} }
...@@ -226,7 +199,7 @@ public void TakeLockAndExtend(TestMode mode) ...@@ -226,7 +199,7 @@ public void TakeLockAndExtend(TestMode mode)
//} //}
[Theory, MemberData(nameof(TestModes))] [Theory, MemberData(nameof(TestModes))]
public void TestBasicLockNotTaken(TestMode testMode) public async Task TestBasicLockNotTaken(TestMode testMode)
{ {
using (var conn = Create(testMode)) using (var conn = Create(testMode))
{ {
...@@ -241,14 +214,14 @@ public void TestBasicLockNotTaken(TestMode testMode) ...@@ -241,14 +214,14 @@ public void TestBasicLockNotTaken(TestMode testMode)
var key = Me(); var key = Me();
for (int i = 0; i < LOOP; i++) for (int i = 0; i < LOOP; i++)
{ {
db.KeyDeleteAsync(key); var d = db.KeyDeleteAsync(key);
taken = db.LockTakeAsync(key, "new-value", TimeSpan.FromSeconds(10)); taken = db.LockTakeAsync(key, "new-value", TimeSpan.FromSeconds(10));
newValue = db.StringGetAsync(key); newValue = db.StringGetAsync(key);
ttl = db.KeyTimeToLiveAsync(key); ttl = db.KeyTimeToLiveAsync(key);
} }
Assert.True(conn.Wait(taken), "taken"); Assert.True(await taken, "taken");
Assert.Equal("new-value", (string)conn.Wait(newValue)); Assert.Equal("new-value", (string)await newValue);
var ttlValue = conn.Wait(ttl).Value.TotalSeconds; var ttlValue = (await ttl).Value.TotalSeconds;
Assert.True(ttlValue >= 8 && ttlValue <= 10, "ttl"); Assert.True(ttlValue >= 8 && ttlValue <= 10, "ttl");
Assert.Equal(0, errorCount); Assert.Equal(0, errorCount);
...@@ -256,21 +229,21 @@ public void TestBasicLockNotTaken(TestMode testMode) ...@@ -256,21 +229,21 @@ public void TestBasicLockNotTaken(TestMode testMode)
} }
[Theory, MemberData(nameof(TestModes))] [Theory, MemberData(nameof(TestModes))]
public void TestBasicLockTaken(TestMode testMode) public async Task TestBasicLockTaken(TestMode testMode)
{ {
using (var conn = Create(testMode)) using (var conn = Create(testMode))
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringSet(key, "old-value", TimeSpan.FromSeconds(20)); db.StringSet(key, "old-value", TimeSpan.FromSeconds(20), flags: CommandFlags.FireAndForget);
var taken = db.LockTakeAsync(key, "new-value", TimeSpan.FromSeconds(10)); var taken = db.LockTakeAsync(key, "new-value", TimeSpan.FromSeconds(10));
var newValue = db.StringGetAsync(key); var newValue = db.StringGetAsync(key);
var ttl = db.KeyTimeToLiveAsync(key); var ttl = db.KeyTimeToLiveAsync(key);
Assert.False(conn.Wait(taken), "taken"); Assert.False(await taken, "taken");
Assert.Equal("old-value", (string)conn.Wait(newValue)); Assert.Equal("old-value", (string)await newValue);
var ttlValue = conn.Wait(ttl).Value.TotalSeconds; var ttlValue = (await ttl).Value.TotalSeconds;
Assert.True(ttlValue >= 18 && ttlValue <= 20, "ttl"); Assert.True(ttlValue >= 18 && ttlValue <= 20, "ttl");
} }
} }
......
...@@ -22,10 +22,10 @@ public async Task MassiveBulkOpsAsync(bool withContinuation) ...@@ -22,10 +22,10 @@ public async Task MassiveBulkOpsAsync(bool withContinuation)
RedisKey key = "MBOA"; RedisKey key = "MBOA";
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
await conn.PingAsync().ForAwait(); await conn.PingAsync().ForAwait();
Action<Task> nonTrivial = delegate void nonTrivial(Task _)
{ {
Thread.SpinWait(5); Thread.SpinWait(5);
}; }
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
for (int i = 0; i <= AsyncOpsQty; i++) for (int i = 0; i <= AsyncOpsQty; i++)
{ {
...@@ -53,7 +53,7 @@ public void MassiveBulkOpsSync(int threads) ...@@ -53,7 +53,7 @@ public void MassiveBulkOpsSync(int threads)
{ {
RedisKey key = "MBOS"; RedisKey key = "MBOS";
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
#if DEBUG #if DEBUG
long oldAlloc = ConnectionMultiplexer.GetResultBoxAllocationCount(); long oldAlloc = ConnectionMultiplexer.GetResultBoxAllocationCount();
#endif #endif
...@@ -61,7 +61,7 @@ public void MassiveBulkOpsSync(int threads) ...@@ -61,7 +61,7 @@ public void MassiveBulkOpsSync(int threads)
{ {
for (int i = 0; i < workPerThread; i++) for (int i = 0; i < workPerThread; i++)
{ {
conn.StringIncrement(key); conn.StringIncrement(key, flags: CommandFlags.FireAndForget);
} }
}, threads); }, threads);
......
...@@ -8,9 +8,10 @@ public class Migrate : TestBase ...@@ -8,9 +8,10 @@ public class Migrate : TestBase
{ {
public Migrate(ITestOutputHelper output) : base (output) { } public Migrate(ITestOutputHelper output) : base (output) { }
[Fact]
public void Basic() public void Basic()
{ {
var fromConfig = new ConfigurationOptions { EndPoints = { { TestConfig.Current.MasterServer, TestConfig.Current.SecurePort } }, Password = TestConfig.Current.SecurePassword }; var fromConfig = new ConfigurationOptions { EndPoints = { { TestConfig.Current.SecureServer, TestConfig.Current.SecurePort } }, Password = TestConfig.Current.SecurePassword };
var toConfig = new ConfigurationOptions { EndPoints = { { TestConfig.Current.MasterServer, TestConfig.Current.MasterPort } } }; var toConfig = new ConfigurationOptions { EndPoints = { { TestConfig.Current.MasterServer, TestConfig.Current.MasterPort } } };
using (var from = ConnectionMultiplexer.Connect(fromConfig)) using (var from = ConnectionMultiplexer.Connect(fromConfig))
using (var to = ConnectionMultiplexer.Connect(toConfig)) using (var to = ConnectionMultiplexer.Connect(toConfig))
...@@ -18,11 +19,11 @@ public void Basic() ...@@ -18,11 +19,11 @@ public void Basic()
RedisKey key = Me(); RedisKey key = Me();
var fromDb = from.GetDatabase(); var fromDb = from.GetDatabase();
var toDb = to.GetDatabase(); var toDb = to.GetDatabase();
fromDb.KeyDelete(key); fromDb.KeyDelete(key, CommandFlags.FireAndForget);
toDb.KeyDelete(key); toDb.KeyDelete(key, CommandFlags.FireAndForget);
fromDb.StringSet(key, "foo"); fromDb.StringSet(key, "foo", flags: CommandFlags.FireAndForget);
var dest = to.GetEndPoints(true).Single(); var dest = to.GetEndPoints(true).Single();
fromDb.KeyMigrate(key, dest); fromDb.KeyMigrate(key, dest, flags: CommandFlags.FireAndForget);
Assert.False(fromDb.KeyExists(key)); Assert.False(fromDb.KeyExists(key));
Assert.True(toDb.KeyExists(key)); Assert.True(toDb.KeyExists(key));
string s = toDb.StringGet(key); string s = toDb.StringGet(key);
......
...@@ -16,22 +16,22 @@ public void AddSortedSetEveryWay() ...@@ -16,22 +16,22 @@ public void AddSortedSetEveryWay()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SortedSetAdd(key, "a", 1); db.SortedSetAdd(key, "a", 1, CommandFlags.FireAndForget);
db.SortedSetAdd(key, new[] { db.SortedSetAdd(key, new[] {
new SortedSetEntry("b", 2) }); new SortedSetEntry("b", 2) }, CommandFlags.FireAndForget);
db.SortedSetAdd(key, new[] { db.SortedSetAdd(key, new[] {
new SortedSetEntry("c", 3), new SortedSetEntry("c", 3),
new SortedSetEntry("d", 4)}); new SortedSetEntry("d", 4)}, CommandFlags.FireAndForget);
db.SortedSetAdd(key, new[] { db.SortedSetAdd(key, new[] {
new SortedSetEntry("e", 5), new SortedSetEntry("e", 5),
new SortedSetEntry("f", 6), new SortedSetEntry("f", 6),
new SortedSetEntry("g", 7)}); new SortedSetEntry("g", 7)}, CommandFlags.FireAndForget);
db.SortedSetAdd(key, new[] { db.SortedSetAdd(key, new[] {
new SortedSetEntry("h", 8), new SortedSetEntry("h", 8),
new SortedSetEntry("i", 9), new SortedSetEntry("i", 9),
new SortedSetEntry("j", 10), new SortedSetEntry("j", 10),
new SortedSetEntry("k", 11)}); new SortedSetEntry("k", 11)}, CommandFlags.FireAndForget);
var vals = db.SortedSetRangeByScoreWithScores(key); var vals = db.SortedSetRangeByScoreWithScores(key);
string s = string.Join(",", vals.OrderByDescending(x => x.Score).Select(x => x.Element)); string s = string.Join(",", vals.OrderByDescending(x => x.Score).Select(x => x.Element));
Assert.Equal("k,j,i,h,g,f,e,d,c,b,a", s); Assert.Equal("k,j,i,h,g,f,e,d,c,b,a", s);
...@@ -48,22 +48,22 @@ public void AddHashEveryWay() ...@@ -48,22 +48,22 @@ public void AddHashEveryWay()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.HashSet(key, "a", 1); db.HashSet(key, "a", 1, flags: CommandFlags.FireAndForget);
db.HashSet(key, new[] { db.HashSet(key, new[] {
new HashEntry("b", 2) }); new HashEntry("b", 2) }, CommandFlags.FireAndForget);
db.HashSet(key, new[] { db.HashSet(key, new[] {
new HashEntry("c", 3), new HashEntry("c", 3),
new HashEntry("d", 4)}); new HashEntry("d", 4)}, CommandFlags.FireAndForget);
db.HashSet(key, new[] { db.HashSet(key, new[] {
new HashEntry("e", 5), new HashEntry("e", 5),
new HashEntry("f", 6), new HashEntry("f", 6),
new HashEntry("g", 7)}); new HashEntry("g", 7)}, CommandFlags.FireAndForget);
db.HashSet(key, new[] { db.HashSet(key, new[] {
new HashEntry("h", 8), new HashEntry("h", 8),
new HashEntry("i", 9), new HashEntry("i", 9),
new HashEntry("j", 10), new HashEntry("j", 10),
new HashEntry("k", 11)}); new HashEntry("k", 11)}, CommandFlags.FireAndForget);
var vals = db.HashGetAll(key); var vals = db.HashGetAll(key);
string s = string.Join(",", vals.OrderByDescending(x => (double)x.Value).Select(x => x.Name)); string s = string.Join(",", vals.OrderByDescending(x => (double)x.Value).Select(x => x.Name));
Assert.Equal("k,j,i,h,g,f,e,d,c,b,a", s); Assert.Equal("k,j,i,h,g,f,e,d,c,b,a", s);
...@@ -80,12 +80,12 @@ public void AddSetEveryWay() ...@@ -80,12 +80,12 @@ public void AddSetEveryWay()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SetAdd(key, "a"); db.SetAdd(key, "a", CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "b" }); db.SetAdd(key, new RedisValue[] { "b" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "c", "d" }); db.SetAdd(key, new RedisValue[] { "c", "d" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "e", "f", "g" }); db.SetAdd(key, new RedisValue[] { "e", "f", "g" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "h", "i", "j", "k" }); db.SetAdd(key, new RedisValue[] { "h", "i", "j", "k" }, CommandFlags.FireAndForget);
var vals = db.SetMembers(key); var vals = db.SetMembers(key);
string s = string.Join(",", vals.OrderByDescending(x => x)); string s = string.Join(",", vals.OrderByDescending(x => x));
...@@ -101,12 +101,12 @@ public void AddSetEveryWayNumbers() ...@@ -101,12 +101,12 @@ public void AddSetEveryWayNumbers()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SetAdd(key, "a"); db.SetAdd(key, "a", CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "1" }); db.SetAdd(key, new RedisValue[] { "1" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "11", "2" }); db.SetAdd(key, new RedisValue[] { "11", "2" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "10", "3", "1.5" }); db.SetAdd(key, new RedisValue[] { "10", "3", "1.5" }, CommandFlags.FireAndForget);
db.SetAdd(key, new RedisValue[] { "2.2", "-1", "s", "t" }); db.SetAdd(key, new RedisValue[] { "2.2", "-1", "s", "t" }, CommandFlags.FireAndForget);
var vals = db.SetMembers(key); var vals = db.SetMembers(key);
string s = string.Join(",", vals.OrderByDescending(x => x)); string s = string.Join(",", vals.OrderByDescending(x => x));
......
...@@ -124,7 +124,7 @@ public async Task BasicStringGetPerf() ...@@ -124,7 +124,7 @@ public async Task BasicStringGetPerf()
Assert.Equal("some value", asyncVal); Assert.Equal("some value", asyncVal);
// let's allow 20% async overhead // let's allow 20% async overhead
// But with a floor, since the base can often be zero // But with a floor, since the base can often be zero
Assert.True(asyncTimer.ElapsedMilliseconds <= System.Math.Max(syncTimer.ElapsedMilliseconds * 1.2M, 20)); Assert.True(asyncTimer.ElapsedMilliseconds <= System.Math.Max(syncTimer.ElapsedMilliseconds * 1.2M, 50));
} }
} }
} }
......
...@@ -20,7 +20,7 @@ public void Execute() ...@@ -20,7 +20,7 @@ public void Execute()
var received = new List<int>(); var received = new List<int>();
Log("Subscribing..."); Log("Subscribing...");
const int COUNT = 1000; const int COUNT = 1000;
sub.Subscribe("foo", (channel, message) => sub.Subscribe("foo", (_, message) =>
{ {
lock (received) lock (received)
{ {
......
...@@ -32,28 +32,32 @@ public void Simple() ...@@ -32,28 +32,32 @@ public void Simple()
var dbId = TestConfig.GetDedicatedDB(); var dbId = TestConfig.GetDedicatedDB();
var db = conn.GetDatabase(dbId); var db = conn.GetDatabase(dbId);
db.StringSet(key, "world"); db.StringSet(key, "world");
var val = db.StringGet(key);
Assert.Equal("world", (string)val);
var result = db.ScriptEvaluate(LuaScript.Prepare("return redis.call('get', @key)"), new { key = (RedisKey)key }); var result = db.ScriptEvaluate(LuaScript.Prepare("return redis.call('get', @key)"), new { key = (RedisKey)key });
Assert.Equal("world", result.AsString()); Assert.Equal("world", result.AsString());
var val = db.StringGet(key);
Assert.Equal("world", (string)val);
var cmds = conn.FinishProfiling(profiler.MyContext); var cmds = conn.FinishProfiling(profiler.MyContext);
var i = 0; var i = 0;
foreach (var cmd in cmds) foreach (var cmd in cmds)
{ {
Log("Command {0}: {1}", i++, cmd.ToString().Replace("\n", ", ")); Log("Command {0} (DB: {1}): {2}", i++, cmd.Db, cmd.ToString().Replace("\n", ", "));
} }
Assert.Equal(3, cmds.Count());
Log("Checking for SET");
var set = cmds.SingleOrDefault(cmd => cmd.Command == "SET"); var set = cmds.SingleOrDefault(cmd => cmd.Command == "SET");
Assert.NotNull(set); Assert.NotNull(set);
Log("Checking for GET");
var get = cmds.SingleOrDefault(cmd => cmd.Command == "GET"); var get = cmds.SingleOrDefault(cmd => cmd.Command == "GET");
Assert.NotNull(get); Assert.NotNull(get);
Log("Checking for EVAL");
var eval = cmds.SingleOrDefault(cmd => cmd.Command == "EVAL"); var eval = cmds.SingleOrDefault(cmd => cmd.Command == "EVAL");
Assert.NotNull(eval); Assert.NotNull(eval);
Assert.True(set.CommandCreated <= get.CommandCreated); Assert.Equal(3, cmds.Count());
Assert.True(get.CommandCreated <= eval.CommandCreated);
Assert.True(set.CommandCreated <= eval.CommandCreated);
Assert.True(eval.CommandCreated <= get.CommandCreated);
AssertProfiledCommandValues(set, conn, dbId); AssertProfiledCommandValues(set, conn, dbId);
...@@ -67,14 +71,14 @@ private static void AssertProfiledCommandValues(IProfiledCommand command, Connec ...@@ -67,14 +71,14 @@ private static void AssertProfiledCommandValues(IProfiledCommand command, Connec
{ {
Assert.Equal(dbId, command.Db); Assert.Equal(dbId, command.Db);
Assert.Equal(conn.GetEndPoints()[0], command.EndPoint); Assert.Equal(conn.GetEndPoints()[0], command.EndPoint);
Assert.True(command.CreationToEnqueued > TimeSpan.Zero); Assert.True(command.CreationToEnqueued > TimeSpan.Zero, nameof(command.CreationToEnqueued));
Assert.True(command.EnqueuedToSending > TimeSpan.Zero); Assert.True(command.EnqueuedToSending > TimeSpan.Zero, nameof(command.EnqueuedToSending));
Assert.True(command.SentToResponse > TimeSpan.Zero); Assert.True(command.SentToResponse > TimeSpan.Zero, nameof(command.SentToResponse));
Assert.True(command.ResponseToCompletion > TimeSpan.Zero); Assert.True(command.ResponseToCompletion > TimeSpan.Zero, nameof(command.ResponseToCompletion));
Assert.True(command.ElapsedTime > TimeSpan.Zero); Assert.True(command.ElapsedTime > TimeSpan.Zero, nameof(command.ElapsedTime));
Assert.True(command.ElapsedTime > command.CreationToEnqueued && command.ElapsedTime > command.EnqueuedToSending && command.ElapsedTime > command.SentToResponse); Assert.True(command.ElapsedTime > command.CreationToEnqueued && command.ElapsedTime > command.EnqueuedToSending && command.ElapsedTime > command.SentToResponse, "Comparisons");
Assert.True(command.RetransmissionOf == null); Assert.True(command.RetransmissionOf == null, nameof(command.RetransmissionOf));
Assert.True(command.RetransmissionReason == null); Assert.True(command.RetransmissionReason == null, nameof(command.RetransmissionReason));
} }
[Fact] [Fact]
...@@ -89,8 +93,8 @@ public void ManyThreads() ...@@ -89,8 +93,8 @@ public void ManyThreads()
conn.BeginProfiling(profiler.MyContext); conn.BeginProfiling(profiler.MyContext);
var threads = new List<Thread>(); var threads = new List<Thread>();
const int CountPer = 100;
for (var i = 0; i < 16; i++) for (var i = 1; i <= 16; i++)
{ {
var db = conn.GetDatabase(i); var db = conn.GetDatabase(i);
...@@ -98,7 +102,7 @@ public void ManyThreads() ...@@ -98,7 +102,7 @@ public void ManyThreads()
{ {
var threadTasks = new List<Task>(); var threadTasks = new List<Task>();
for (var j = 0; j < 1000; j++) for (var j = 0; j < CountPer; j++)
{ {
var task = db.StringSetAsync(prefix + j, "" + j); var task = db.StringSetAsync(prefix + j, "" + j);
threadTasks.Add(task); threadTasks.Add(task);
...@@ -112,22 +116,27 @@ public void ManyThreads() ...@@ -112,22 +116,27 @@ public void ManyThreads()
threads.ForEach(thread => thread.Join()); threads.ForEach(thread => thread.Join());
var allVals = conn.FinishProfiling(profiler.MyContext); var allVals = conn.FinishProfiling(profiler.MyContext);
var relevant = allVals.Where(cmd => cmd.Db > 0).ToList();
var kinds = allVals.Select(cmd => cmd.Command).Distinct().ToList(); var kinds = relevant.Select(cmd => cmd.Command).Distinct().ToList();
foreach (var k in kinds)
{
Log("Kind Seen: " + k);
}
Assert.True(kinds.Count <= 2); Assert.True(kinds.Count <= 2);
Assert.Contains("SET", kinds); Assert.Contains("SET", kinds);
if (kinds.Count == 2 && !kinds.Contains("SELECT")) if (kinds.Count == 2 && !kinds.Contains("SELECT") && !kinds.Contains("GET"))
{ {
Assert.True(false, "Non-SET, Non-SELECT command seen"); Assert.True(false, "Non-SET, Non-SELECT, Non-GET command seen");
} }
Assert.Equal(16 * 1000, allVals.Count()); Assert.Equal(16 * CountPer, relevant.Count);
Assert.Equal(16, allVals.Select(cmd => cmd.Db).Distinct().Count()); Assert.Equal(16, allVals.Select(cmd => cmd.Db).Distinct().Count());
for (var i = 0; i < 16; i++) for (var i = 1; i <= 16; i++)
{ {
var setsInDb = allVals.Count(cmd => cmd.Db == i && cmd.Command == "SET"); var setsInDb = relevant.Count(cmd => cmd.Db == i);
Assert.Equal(1000, setsInDb); Assert.Equal(CountPer, setsInDb);
} }
} }
} }
...@@ -294,7 +303,7 @@ public async Task LeaksCollectedAndRePooled() ...@@ -294,7 +303,7 @@ public async Task LeaksCollectedAndRePooled()
var anyContext = LeaksCollectedAndRePooled_Initialize(conn, ThreadCount); var anyContext = LeaksCollectedAndRePooled_Initialize(conn, ThreadCount);
// force collection of everything but `anyContext` // force collection of everything but `anyContext`
GC.Collect(3, GCCollectionMode.Forced, blocking: true); GC.Collect(3, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
await Task.Delay(TimeSpan.FromMinutes(1.01)).ForAwait(); await Task.Delay(TimeSpan.FromMinutes(1.01)).ForAwait();
...@@ -419,7 +428,7 @@ public void LowAllocationEnumerable() ...@@ -419,7 +428,7 @@ public void LowAllocationEnumerable()
conn.BeginProfiling(profiler.MyContext); conn.BeginProfiling(profiler.MyContext);
var prefix = Me(); var prefix = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase(1);
var allTasks = new List<Task<string>>(); var allTasks = new List<Task<string>>();
...@@ -453,10 +462,10 @@ public void LowAllocationEnumerable() ...@@ -453,10 +462,10 @@ public void LowAllocationEnumerable()
Assert.True(object.ReferenceEquals(i, j)); Assert.True(object.ReferenceEquals(i, j));
} }
Assert.Equal(OuterLoop, res.Count(r => r.Command == "GET")); Assert.Equal(OuterLoop, res.Count(r => r.Command == "GET" && r.Db > 0));
Assert.Equal(OuterLoop, res.Count(r => r.Command == "SET")); Assert.Equal(OuterLoop, res.Count(r => r.Command == "SET" && r.Db > 0));
Assert.Equal(OuterLoop * 2, res.Count()); Assert.Equal(OuterLoop * 2, res.Count(r => r.Db > 0));
} }
} }
......
...@@ -270,9 +270,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption ...@@ -270,9 +270,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
{ {
const int loop = 10000; const int loop = 10000;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var tasks = new Task[loop]; var tasks = new Task[loop];
var withFAF = Stopwatch.StartNew(); var withFAF = Stopwatch.StartNew();
...@@ -282,9 +279,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption ...@@ -282,9 +279,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
} }
withFAF.Stop(); withFAF.Stop();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var withAsync = Stopwatch.StartNew(); var withAsync = Stopwatch.StartNew();
for (int i = 0; i < loop; i++) for (int i = 0; i < loop; i++)
{ {
...@@ -530,7 +524,7 @@ public async Task PubSubGetAllCorrectOrder_OnMessage_Async() ...@@ -530,7 +524,7 @@ public async Task PubSubGetAllCorrectOrder_OnMessage_Async()
} }
[Fact] [Fact]
public void TestPublishWithSubscribers() public async Task TestPublishWithSubscribers()
{ {
var channel = Me(); var channel = Me();
using (var muxerA = Create()) using (var muxerA = Create())
...@@ -542,11 +536,10 @@ public void TestPublishWithSubscribers() ...@@ -542,11 +536,10 @@ public void TestPublishWithSubscribers()
var t1 = listenA.SubscribeAsync(channel, delegate { }); var t1 = listenA.SubscribeAsync(channel, delegate { });
var t2 = listenB.SubscribeAsync(channel, delegate { }); var t2 = listenB.SubscribeAsync(channel, delegate { });
listenA.Wait(t1); await Task.WhenAll(t1, t2).ForAwait();
listenB.Wait(t2);
var pub = conn.GetSubscriber().PublishAsync(channel, "message"); var pub = conn.GetSubscriber().PublishAsync(channel, "message");
Assert.Equal(2, conn.Wait(pub)); // delivery count Assert.Equal(2, await pub); // delivery count
} }
} }
...@@ -563,10 +556,9 @@ public async Task TestMultipleSubscribersGetMessage() ...@@ -563,10 +556,9 @@ public async Task TestMultipleSubscribersGetMessage()
conn.GetDatabase().Ping(); conn.GetDatabase().Ping();
var pub = conn.GetSubscriber(); var pub = conn.GetSubscriber();
int gotA = 0, gotB = 0; int gotA = 0, gotB = 0;
var tA = listenA.SubscribeAsync(channel, (s, msg) => { if (msg == "message") Interlocked.Increment(ref gotA); }); var tA = listenA.SubscribeAsync(channel, (_, msg) => { if (msg == "message") Interlocked.Increment(ref gotA); });
var tB = listenB.SubscribeAsync(channel, (s, msg) => { if (msg == "message") Interlocked.Increment(ref gotB); }); var tB = listenB.SubscribeAsync(channel, (_, msg) => { if (msg == "message") Interlocked.Increment(ref gotB); });
listenA.Wait(tA); await Task.WhenAll(tA, tB).ForAwait();
listenB.Wait(tB);
Assert.Equal(2, pub.Publish(channel, "message")); Assert.Equal(2, pub.Publish(channel, "message"));
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0)); Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0));
...@@ -574,7 +566,7 @@ public async Task TestMultipleSubscribersGetMessage() ...@@ -574,7 +566,7 @@ public async Task TestMultipleSubscribersGetMessage()
// and unsubscibe... // and unsubscibe...
tA = listenA.UnsubscribeAsync(channel); tA = listenA.UnsubscribeAsync(channel);
listenA.Wait(tA); await tA;
Assert.Equal(1, pub.Publish(channel, "message")); Assert.Equal(1, pub.Publish(channel, "message"));
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0)); Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0));
...@@ -596,14 +588,14 @@ public async Task Issue38() ...@@ -596,14 +588,14 @@ public async Task Issue38()
var a1 = sub.SubscribeAsync(prefix + "bar", handler); var a1 = sub.SubscribeAsync(prefix + "bar", handler);
var b0 = sub.SubscribeAsync(prefix + "f*o", handler); var b0 = sub.SubscribeAsync(prefix + "f*o", handler);
var b1 = sub.SubscribeAsync(prefix + "b*r", handler); var b1 = sub.SubscribeAsync(prefix + "b*r", handler);
sub.WaitAll(a0, a1, b0, b1); await Task.WhenAll(a0, a1, b0, b1).ForAwait();
var c = sub.PublishAsync(prefix + "foo", "foo"); var c = sub.PublishAsync(prefix + "foo", "foo");
var d = sub.PublishAsync(prefix + "f@o", "f@o"); var d = sub.PublishAsync(prefix + "f@o", "f@o");
var e = sub.PublishAsync(prefix + "bar", "bar"); var e = sub.PublishAsync(prefix + "bar", "bar");
var f = sub.PublishAsync(prefix + "b@r", "b@r"); var f = sub.PublishAsync(prefix + "b@r", "b@r");
await Task.WhenAll(c, d, e, f).ForAwait();
pub.WaitAll(c, d, e, f);
long total = c.Result + d.Result + e.Result + f.Result; long total = c.Result + d.Result + e.Result + f.Result;
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
...@@ -629,8 +621,7 @@ public async Task TestPartialSubscriberGetMessage() ...@@ -629,8 +621,7 @@ public async Task TestPartialSubscriberGetMessage()
var prefix = Me(); var prefix = Me();
var tA = listenA.SubscribeAsync(prefix + "channel", (s, msg) => { if (s == prefix + "channel" && msg == "message") Interlocked.Increment(ref gotA); }); var tA = listenA.SubscribeAsync(prefix + "channel", (s, msg) => { if (s == prefix + "channel" && msg == "message") Interlocked.Increment(ref gotA); });
var tB = listenB.SubscribeAsync(prefix + "chann*", (s, msg) => { if (s == prefix + "channel" && msg == "message") Interlocked.Increment(ref gotB); }); var tB = listenB.SubscribeAsync(prefix + "chann*", (s, msg) => { if (s == prefix + "channel" && msg == "message") Interlocked.Increment(ref gotB); });
listenA.Wait(tA); await Task.WhenAll(tA, tB).ForAwait();
listenB.Wait(tB);
Assert.Equal(2, pub.Publish(prefix + "channel", "message")); Assert.Equal(2, pub.Publish(prefix + "channel", "message"));
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0)); Assert.Equal(1, Interlocked.CompareExchange(ref gotA, 0, 0));
...@@ -638,7 +629,7 @@ public async Task TestPartialSubscriberGetMessage() ...@@ -638,7 +629,7 @@ public async Task TestPartialSubscriberGetMessage()
// and unsubscibe... // and unsubscibe...
tB = listenB.UnsubscribeAsync(prefix + "chann*", null); tB = listenB.UnsubscribeAsync(prefix + "chann*", null);
listenB.Wait(tB); await tB;
Assert.Equal(1, pub.Publish(prefix + "channel", "message")); Assert.Equal(1, pub.Publish(prefix + "channel", "message"));
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(2, Interlocked.CompareExchange(ref gotA, 0, 0)); Assert.Equal(2, Interlocked.CompareExchange(ref gotA, 0, 0));
...@@ -658,20 +649,20 @@ public async Task TestSubscribeUnsubscribeAndSubscribeAgain() ...@@ -658,20 +649,20 @@ public async Task TestSubscribeUnsubscribeAndSubscribeAgain()
int x = 0, y = 0; int x = 0, y = 0;
var t1 = sub.SubscribeAsync(prefix + "abc", delegate { Interlocked.Increment(ref x); }); var t1 = sub.SubscribeAsync(prefix + "abc", delegate { Interlocked.Increment(ref x); });
var t2 = sub.SubscribeAsync(prefix + "ab*", delegate { Interlocked.Increment(ref y); }); var t2 = sub.SubscribeAsync(prefix + "ab*", delegate { Interlocked.Increment(ref y); });
sub.WaitAll(t1, t2); await Task.WhenAll(t1, t2).ForAwait();
pub.Publish(prefix + "abc", ""); pub.Publish(prefix + "abc", "");
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(1, Volatile.Read(ref x)); Assert.Equal(1, Volatile.Read(ref x));
Assert.Equal(1, Volatile.Read(ref y)); Assert.Equal(1, Volatile.Read(ref y));
t1 = sub.UnsubscribeAsync(prefix + "abc", null); t1 = sub.UnsubscribeAsync(prefix + "abc", null);
t2 = sub.UnsubscribeAsync(prefix + "ab*", null); t2 = sub.UnsubscribeAsync(prefix + "ab*", null);
sub.WaitAll(t1, t2); await Task.WhenAll(t1, t2).ForAwait();
pub.Publish(prefix + "abc", ""); pub.Publish(prefix + "abc", "");
Assert.Equal(1, Volatile.Read(ref x)); Assert.Equal(1, Volatile.Read(ref x));
Assert.Equal(1, Volatile.Read(ref y)); Assert.Equal(1, Volatile.Read(ref y));
t1 = sub.SubscribeAsync(prefix + "abc", delegate { Interlocked.Increment(ref x); }); t1 = sub.SubscribeAsync(prefix + "abc", delegate { Interlocked.Increment(ref x); });
t2 = sub.SubscribeAsync(prefix + "ab*", delegate { Interlocked.Increment(ref y); }); t2 = sub.SubscribeAsync(prefix + "ab*", delegate { Interlocked.Increment(ref y); });
sub.WaitAll(t1, t2); await Task.WhenAll(t1, t2).ForAwait();
pub.Publish(prefix + "abc", ""); pub.Publish(prefix + "abc", "");
await AllowReasonableTimeToPublishAndProcess().ForAwait(); await AllowReasonableTimeToPublishAndProcess().ForAwait();
Assert.Equal(2, Volatile.Read(ref x)); Assert.Equal(2, Volatile.Read(ref x));
......
...@@ -21,9 +21,9 @@ public void ConnectToSSDB() ...@@ -21,9 +21,9 @@ public void ConnectToSSDB()
using (var conn = ConnectionMultiplexer.Connect(config)) using (var conn = ConnectionMultiplexer.Connect(config))
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
Assert.True(db.StringGet(key).IsNull); Assert.True(db.StringGet(key).IsNull);
db.StringSet(key, "abc"); db.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
Assert.Equal("abc", db.StringGet(key)); Assert.Equal("abc", db.StringGet(key));
} }
} }
......
...@@ -105,7 +105,7 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost) ...@@ -105,7 +105,7 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost)
muxer.ConnectionFailed += OnConnectionFailed; muxer.ConnectionFailed += OnConnectionFailed;
muxer.InternalError += OnInternalError; muxer.InternalError += OnInternalError;
var db = muxer.GetDatabase(); var db = muxer.GetDatabase();
await db.PingAsync(); await db.PingAsync().ForAwait();
using (var file = File.Create("ssl-" + useSsl + "-" + specifyHost + ".zip")) using (var file = File.Create("ssl-" + useSsl + "-" + specifyHost + ".zip"))
{ {
muxer.ExportConfiguration(file); muxer.ExportConfiguration(file);
...@@ -114,13 +114,13 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost) ...@@ -114,13 +114,13 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost)
const int AsyncLoop = 2000; const int AsyncLoop = 2000;
// perf; async // perf; async
await db.KeyDeleteAsync(key); await db.KeyDeleteAsync(key).ForAwait();
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
for (int i = 0; i < AsyncLoop; i++) for (int i = 0; i < AsyncLoop; i++)
{ {
try try
{ {
await db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget); await db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget).ForAwait();
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -129,7 +129,7 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost) ...@@ -129,7 +129,7 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost)
} }
} }
// need to do this inside the timer to measure the TTLB // need to do this inside the timer to measure the TTLB
long value = (long)await db.StringGetAsync(key); long value = (long)await db.StringGetAsync(key).ForAwait();
watch.Stop(); watch.Stop();
Assert.Equal(AsyncLoop, value); Assert.Equal(AsyncLoop, value);
Log("F&F: {0} INCR, {1:###,##0}ms, {2} ops/s; final value: {3}", Log("F&F: {0} INCR, {1:###,##0}ms, {2} ops/s; final value: {3}",
...@@ -173,7 +173,6 @@ public void RedisLabsSSL() ...@@ -173,7 +173,6 @@ public void RedisLabsSSL()
Skip.IfNoConfig(nameof(TestConfig.Config.RedisLabsSslServer), TestConfig.Current.RedisLabsSslServer); Skip.IfNoConfig(nameof(TestConfig.Config.RedisLabsSslServer), TestConfig.Current.RedisLabsSslServer);
Skip.IfNoConfig(nameof(TestConfig.Config.RedisLabsPfxPath), TestConfig.Current.RedisLabsPfxPath); Skip.IfNoConfig(nameof(TestConfig.Config.RedisLabsPfxPath), TestConfig.Current.RedisLabsPfxPath);
var cert = new X509Certificate2(TestConfig.Current.RedisLabsPfxPath, ""); var cert = new X509Certificate2(TestConfig.Current.RedisLabsPfxPath, "");
Assert.NotNull(cert); Assert.NotNull(cert);
Writer.WriteLine("Thumbprint: " + cert.Thumbprint); Writer.WriteLine("Thumbprint: " + cert.Thumbprint);
...@@ -189,10 +188,8 @@ public void RedisLabsSSL() ...@@ -189,10 +188,8 @@ public void RedisLabsSSL()
"subscribe", "unsubscribe", "cluster" "subscribe", "unsubscribe", "cluster"
}, false) }, false)
}; };
options.TrustIssuer("redislabs_ca.pem");
options.TrustIssuer("redislabs_ca.pem");
if (!Directory.Exists(Me())) Directory.CreateDirectory(Me()); if (!Directory.Exists(Me())) Directory.CreateDirectory(Me());
#if LOGOUTPUT #if LOGOUTPUT
...@@ -207,10 +204,10 @@ public void RedisLabsSSL() ...@@ -207,10 +204,10 @@ public void RedisLabsSSL()
using (var conn = ConnectionMultiplexer.Connect(options)) using (var conn = ConnectionMultiplexer.Connect(options))
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
string s = db.StringGet(key); string s = db.StringGet(key);
Assert.Null(s); Assert.Null(s);
db.StringSet(key, "abc"); db.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
s = db.StringGet(key); s = db.StringGet(key);
Assert.Equal("abc", s); Assert.Equal("abc", s);
...@@ -253,7 +250,7 @@ public void RedisLabsEnvironmentVariableClientCertificate(bool setEnv) ...@@ -253,7 +250,7 @@ public void RedisLabsEnvironmentVariableClientCertificate(bool setEnv)
"subscribe", "unsubscribe", "cluster" "subscribe", "unsubscribe", "cluster"
}, false) }, false)
}; };
if (!Directory.Exists(Me())) Directory.CreateDirectory(Me()); if (!Directory.Exists(Me())) Directory.CreateDirectory(Me());
#if LOGOUTPUT #if LOGOUTPUT
ConnectionMultiplexer.EchoPath = Me(); ConnectionMultiplexer.EchoPath = Me();
...@@ -265,7 +262,7 @@ public void RedisLabsEnvironmentVariableClientCertificate(bool setEnv) ...@@ -265,7 +262,7 @@ public void RedisLabsEnvironmentVariableClientCertificate(bool setEnv)
if (!setEnv) Assert.True(false, "Could not set environment"); if (!setEnv) Assert.True(false, "Could not set environment");
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
string s = db.StringGet(key); string s = db.StringGet(key);
Assert.Null(s); Assert.Null(s);
db.StringSet(key, "abc"); db.StringSet(key, "abc");
......
...@@ -183,11 +183,11 @@ public void SetScan(bool supported) ...@@ -183,11 +183,11 @@ public void SetScan(bool supported)
{ {
RedisKey key = Me(); RedisKey key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SetAdd(key, "a"); db.SetAdd(key, "a", CommandFlags.FireAndForget);
db.SetAdd(key, "b"); db.SetAdd(key, "b", CommandFlags.FireAndForget);
db.SetAdd(key, "c"); db.SetAdd(key, "c", CommandFlags.FireAndForget);
var arr = db.SetScan(key).ToArray(); var arr = db.SetScan(key).ToArray();
Assert.Equal(3, arr.Length); Assert.Equal(3, arr.Length);
Assert.True(arr.Contains("a"), "a"); Assert.True(arr.Contains("a"), "a");
...@@ -206,11 +206,11 @@ public void SortedSetScan(bool supported) ...@@ -206,11 +206,11 @@ public void SortedSetScan(bool supported)
{ {
RedisKey key = Me() + supported; RedisKey key = Me() + supported;
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.SortedSetAdd(key, "a", 1); db.SortedSetAdd(key, "a", 1, CommandFlags.FireAndForget);
db.SortedSetAdd(key, "b", 2); db.SortedSetAdd(key, "b", 2, CommandFlags.FireAndForget);
db.SortedSetAdd(key, "c", 3); db.SortedSetAdd(key, "c", 3, CommandFlags.FireAndForget);
var arr = db.SortedSetScan(key).ToArray(); var arr = db.SortedSetScan(key).ToArray();
Assert.Equal(3, arr.Length); Assert.Equal(3, arr.Length);
...@@ -274,11 +274,11 @@ public void HashScan(bool supported) ...@@ -274,11 +274,11 @@ public void HashScan(bool supported)
{ {
RedisKey key = Me(); RedisKey key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.HashSet(key, "a", "1"); db.HashSet(key, "a", "1", flags: CommandFlags.FireAndForget);
db.HashSet(key, "b", "2"); db.HashSet(key, "b", "2", flags: CommandFlags.FireAndForget);
db.HashSet(key, "c", "3"); db.HashSet(key, "c", "3", flags: CommandFlags.FireAndForget);
var arr = db.HashScan(key).ToArray(); var arr = db.HashScan(key).ToArray();
Assert.Equal(3, arr.Length); Assert.Equal(3, arr.Length);
...@@ -315,7 +315,7 @@ public void HashScanLarge(int pageSize) ...@@ -315,7 +315,7 @@ public void HashScanLarge(int pageSize)
{ {
RedisKey key = Me() + pageSize; RedisKey key = Me() + pageSize;
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 0; i < 2000; i++) for (int i = 0; i < 2000; i++)
db.HashSet(key, "k" + i, "v" + i, flags: CommandFlags.FireAndForget); db.HashSet(key, "k" + i, "v" + i, flags: CommandFlags.FireAndForget);
...@@ -342,14 +342,14 @@ public void HashScanThresholds() ...@@ -342,14 +342,14 @@ public void HashScanThresholds()
private bool GotCursors(ConnectionMultiplexer conn, RedisKey key, int count) private bool GotCursors(ConnectionMultiplexer conn, RedisKey key, int count)
{ {
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var entries = new HashEntry[count]; var entries = new HashEntry[count];
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
entries[i] = new HashEntry("Item:" + i, i); entries[i] = new HashEntry("Item:" + i, i);
} }
db.HashSet(key, entries); db.HashSet(key, entries, CommandFlags.FireAndForget);
var found = false; var found = false;
var response = db.HashScan(key); var response = db.HashScan(key);
...@@ -375,7 +375,7 @@ public void SetScanLarge(int pageSize) ...@@ -375,7 +375,7 @@ public void SetScanLarge(int pageSize)
{ {
RedisKey key = Me() + pageSize; RedisKey key = Me() + pageSize;
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 0; i < 2000; i++) for (int i = 0; i < 2000; i++)
db.SetAdd(key, "s" + i, flags: CommandFlags.FireAndForget); db.SetAdd(key, "s" + i, flags: CommandFlags.FireAndForget);
...@@ -396,7 +396,7 @@ public void SortedSetScanLarge(int pageSize) ...@@ -396,7 +396,7 @@ public void SortedSetScanLarge(int pageSize)
{ {
RedisKey key = Me() + pageSize; RedisKey key = Me() + pageSize;
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 0; i < 2000; i++) for (int i = 0; i < 2000; i++)
db.SortedSetAdd(key, "z" + i, i, flags: CommandFlags.FireAndForget); db.SortedSetAdd(key, "z" + i, i, flags: CommandFlags.FireAndForget);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -31,7 +32,7 @@ public void ClientScripting() ...@@ -31,7 +32,7 @@ public void ClientScripting()
} }
[Fact] [Fact]
public void BasicScripting() public async Task BasicScripting()
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
...@@ -40,14 +41,14 @@ public void BasicScripting() ...@@ -40,14 +41,14 @@ public void BasicScripting()
new RedisKey[] { "key1", "key2" }, new RedisValue[] { "first", "second" }); new RedisKey[] { "key1", "key2" }, new RedisValue[] { "first", "second" });
var cache = conn.ScriptEvaluateAsync("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", var cache = conn.ScriptEvaluateAsync("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
new RedisKey[] { "key1", "key2" }, new RedisValue[] { "first", "second" }); new RedisKey[] { "key1", "key2" }, new RedisValue[] { "first", "second" });
var results = (string[])conn.Wait(noCache); var results = (string[])await noCache;
Assert.Equal(4, results.Length); Assert.Equal(4, results.Length);
Assert.Equal("key1", results[0]); Assert.Equal("key1", results[0]);
Assert.Equal("key2", results[1]); Assert.Equal("key2", results[1]);
Assert.Equal("first", results[2]); Assert.Equal("first", results[2]);
Assert.Equal("second", results[3]); Assert.Equal("second", results[3]);
results = (string[])conn.Wait(cache); results = (string[])await cache;
Assert.Equal(4, results.Length); Assert.Equal(4, results.Length);
Assert.Equal("key1", results[0]); Assert.Equal("key1", results[0]);
Assert.Equal("key2", results[1]); Assert.Equal("key2", results[1]);
...@@ -63,14 +64,14 @@ public void KeysScripting() ...@@ -63,14 +64,14 @@ public void KeysScripting()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.StringSet(key, "bar"); conn.StringSet(key, "bar", flags: CommandFlags.FireAndForget);
var result = (string)conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key }, null); var result = (string)conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key }, null);
Assert.Equal("bar", result); Assert.Equal("bar", result);
} }
} }
[Fact] [Fact]
public void TestRandomThingFromForum() public async Task TestRandomThingFromForum()
{ {
const string script = @"local currentVal = tonumber(redis.call('GET', KEYS[1])); const string script = @"local currentVal = tonumber(redis.call('GET', KEYS[1]));
if (currentVal <= 0 ) then return 1 elseif (currentVal - (tonumber(ARGV[1])) < 0 ) then return 0 end; if (currentVal <= 0 ) then return 1 elseif (currentVal - (tonumber(ARGV[1])) < 0 ) then return 0 end;
...@@ -80,22 +81,22 @@ public void TestRandomThingFromForum() ...@@ -80,22 +81,22 @@ public void TestRandomThingFromForum()
{ {
var prefix = Me(); var prefix = Me();
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
conn.StringSetAsync(prefix + "A", "0"); conn.StringSet(prefix + "A", "0", flags: CommandFlags.FireAndForget);
conn.StringSetAsync(prefix + "B", "5"); conn.StringSet(prefix + "B", "5", flags: CommandFlags.FireAndForget);
conn.StringSetAsync(prefix + "C", "10"); conn.StringSet(prefix + "C", "10", flags: CommandFlags.FireAndForget);
var a = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "A" }, new RedisValue[] { 6 }); var a = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "A" }, new RedisValue[] { 6 }).ForAwait();
var b = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "B" }, new RedisValue[] { 6 }); var b = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "B" }, new RedisValue[] { 6 }).ForAwait();
var c = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "C" }, new RedisValue[] { 6 }); var c = conn.ScriptEvaluateAsync(script, new RedisKey[] { prefix + "C" }, new RedisValue[] { 6 }).ForAwait();
var vals = conn.StringGetAsync(new RedisKey[] { prefix + "A", prefix + "B", prefix + "C" }); var vals = await conn.StringGetAsync(new RedisKey[] { prefix + "A", prefix + "B", prefix + "C" }).ForAwait();
Assert.Equal(1, (long)conn.Wait(a)); // exit code when current val is non-positive Assert.Equal(1, (long)await a); // exit code when current val is non-positive
Assert.Equal(0, (long)conn.Wait(b)); // exit code when result would be negative Assert.Equal(0, (long)await b); // exit code when result would be negative
Assert.Equal(4, (long)conn.Wait(c)); // 10 - 6 = 4 Assert.Equal(4, (long)await c); // 10 - 6 = 4
Assert.Equal("0", conn.Wait(vals)[0]); Assert.Equal("0", vals[0]);
Assert.Equal("5", conn.Wait(vals)[1]); Assert.Equal("5", vals[1]);
Assert.Equal("4", conn.Wait(vals)[2]); Assert.Equal("4", vals[2]);
} }
} }
...@@ -106,7 +107,7 @@ public void HackyGetPerf() ...@@ -106,7 +107,7 @@ public void HackyGetPerf()
{ {
var key = Me(); var key = Me();
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
conn.StringSetAsync(key + "foo", "bar"); conn.StringSet(key + "foo", "bar", flags: CommandFlags.FireAndForget);
var result = (long)conn.ScriptEvaluate(@" var result = (long)conn.ScriptEvaluate(@"
redis.call('psetex', KEYS[1], 60000, 'timing') redis.call('psetex', KEYS[1], 60000, 'timing')
for i = 1,100000 do for i = 1,100000 do
...@@ -122,66 +123,66 @@ public void HackyGetPerf() ...@@ -122,66 +123,66 @@ public void HackyGetPerf()
} }
[Fact] [Fact]
public void MultiIncrWithoutReplies() public async Task MultiIncrWithoutReplies()
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var prefix = Me(); var prefix = Me();
// prime some initial values // prime some initial values
conn.KeyDeleteAsync(new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }); conn.KeyDelete(new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }, CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "b"); conn.StringIncrement(prefix + "b", flags: CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "c"); conn.StringIncrement(prefix + "c", flags: CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "c"); conn.StringIncrement(prefix + "c", flags: CommandFlags.FireAndForget);
// run the script, passing "a", "b", "c", "c" to // run the script, passing "a", "b", "c", "c" to
// increment a & b by 1, c twice // increment a & b by 1, c twice
var result = conn.ScriptEvaluateAsync( var result = conn.ScriptEvaluateAsync(
"for i,key in ipairs(KEYS) do redis.call('incr', key) end", "for i,key in ipairs(KEYS) do redis.call('incr', key) end",
new RedisKey[] { prefix + "a", prefix + "b", prefix + "c", prefix + "c" }, // <== aka "KEYS" in the script new RedisKey[] { prefix + "a", prefix + "b", prefix + "c", prefix + "c" }, // <== aka "KEYS" in the script
null); // <== aka "ARGV" in the script null).ForAwait(); // <== aka "ARGV" in the script
// check the incremented values // check the incremented values
var a = conn.StringGetAsync(prefix + "a"); var a = conn.StringGetAsync(prefix + "a").ForAwait();
var b = conn.StringGetAsync(prefix + "b"); var b = conn.StringGetAsync(prefix + "b").ForAwait();
var c = conn.StringGetAsync(prefix + "c"); var c = conn.StringGetAsync(prefix + "c").ForAwait();
Assert.True(conn.Wait(result).IsNull, "result"); Assert.True((await result).IsNull, "result");
Assert.Equal(1, (long)conn.Wait(a)); Assert.Equal(1, (long)await a);
Assert.Equal(2, (long)conn.Wait(b)); Assert.Equal(2, (long)await b);
Assert.Equal(4, (long)conn.Wait(c)); Assert.Equal(4, (long)await c);
} }
} }
[Fact] [Fact]
public void MultiIncrByWithoutReplies() public async Task MultiIncrByWithoutReplies()
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var prefix = Me(); var prefix = Me();
// prime some initial values // prime some initial values
conn.KeyDeleteAsync(new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }); conn.KeyDelete(new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }, CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "b"); conn.StringIncrement(prefix + "b", flags: CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "c"); conn.StringIncrement(prefix + "c", flags: CommandFlags.FireAndForget);
conn.StringIncrementAsync(prefix + "c"); conn.StringIncrement(prefix + "c", flags: CommandFlags.FireAndForget);
//run the script, passing "a", "b", "c" and 1,2,3 //run the script, passing "a", "b", "c" and 1,2,3
// increment a &b by 1, c twice // increment a &b by 1, c twice
var result = conn.ScriptEvaluateAsync( var result = conn.ScriptEvaluateAsync(
"for i,key in ipairs(KEYS) do redis.call('incrby', key, ARGV[i]) end", "for i,key in ipairs(KEYS) do redis.call('incrby', key, ARGV[i]) end",
new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }, // <== aka "KEYS" in the script new RedisKey[] { prefix + "a", prefix + "b", prefix + "c" }, // <== aka "KEYS" in the script
new RedisValue[] { 1, 1, 2 }); // <== aka "ARGV" in the script new RedisValue[] { 1, 1, 2 }).ForAwait(); // <== aka "ARGV" in the script
// check the incremented values // check the incremented values
var a = conn.StringGetAsync(prefix + "a"); var a = conn.StringGetAsync(prefix + "a").ForAwait();
var b = conn.StringGetAsync(prefix + "b"); var b = conn.StringGetAsync(prefix + "b").ForAwait();
var c = conn.StringGetAsync(prefix + "c"); var c = conn.StringGetAsync(prefix + "c").ForAwait();
Assert.True(conn.Wait(result).IsNull, "result"); Assert.True((await result).IsNull, "result");
Assert.Equal(1, (long)conn.Wait(a)); Assert.Equal(1, (long)await a);
Assert.Equal(2, (long)conn.Wait(b)); Assert.Equal(2, (long)await b);
Assert.Equal(4, (long)conn.Wait(c)); Assert.Equal(4, (long)await c);
} }
} }
...@@ -192,7 +193,7 @@ public void DisableStringInference() ...@@ -192,7 +193,7 @@ public void DisableStringInference()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.StringSet(key, "bar"); conn.StringSet(key, "bar", flags: CommandFlags.FireAndForget);
var result = (byte[])conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key }); var result = (byte[])conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key });
Assert.Equal("bar", Encoding.UTF8.GetString(result)); Assert.Equal("bar", Encoding.UTF8.GetString(result));
} }
...@@ -205,7 +206,7 @@ public void FlushDetection() ...@@ -205,7 +206,7 @@ public void FlushDetection()
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.StringSet(key, "bar"); conn.StringSet(key, "bar", flags: CommandFlags.FireAndForget);
var result = (string)conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key }, null); var result = (string)conn.ScriptEvaluate("return redis.call('get', KEYS[1])", new RedisKey[] { key }, null);
Assert.Equal("bar", result); Assert.Equal("bar", result);
...@@ -270,24 +271,23 @@ public void NonAsciiScripts() ...@@ -270,24 +271,23 @@ public void NonAsciiScripts()
} }
[Fact] [Fact]
public void ScriptThrowsError() public async Task ScriptThrowsError()
{ {
Assert.Throws<RedisServerException>(() => await Assert.ThrowsAsync<RedisServerException>(async () =>
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var result = conn.ScriptEvaluateAsync("return redis.error_reply('oops')", null, null);
try try
{ {
conn.Wait(result); await conn.ScriptEvaluateAsync("return redis.error_reply('oops')", null, null).ForAwait();
} }
catch (AggregateException ex) catch (AggregateException ex)
{ {
throw ex.InnerExceptions[0]; throw ex.InnerExceptions[0];
} }
} }
}); }).ForAwait();
} }
[Fact] [Fact]
...@@ -297,7 +297,7 @@ public void ScriptThrowsErrorInsideTransaction() ...@@ -297,7 +297,7 @@ public void ScriptThrowsErrorInsideTransaction()
{ {
var key = Me(); var key = Me();
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
conn.KeyDeleteAsync(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
var beforeTran = (string)conn.StringGet(key); var beforeTran = (string)conn.StringGet(key);
Assert.Null(beforeTran); Assert.Null(beforeTran);
var tran = conn.CreateTransaction(); var tran = conn.CreateTransaction();
...@@ -307,9 +307,9 @@ public void ScriptThrowsErrorInsideTransaction() ...@@ -307,9 +307,9 @@ public void ScriptThrowsErrorInsideTransaction()
var c = tran.StringIncrementAsync(key); var c = tran.StringIncrementAsync(key);
var complete = tran.ExecuteAsync(); var complete = tran.ExecuteAsync();
Assert.True(tran.Wait(complete)); Assert.True(muxer.Wait(complete));
Assert.True(a.IsCompleted); Assert.True(a.IsCompleted, a.Status.ToString());
Assert.True(c.IsCompleted); Assert.True(c.IsCompleted, "State: " + c.Status);
Assert.Equal(1L, a.Result); Assert.Equal(1L, a.Result);
Assert.Equal(2L, c.Result); Assert.Equal(2L, c.Result);
...@@ -325,13 +325,13 @@ public void ScriptThrowsErrorInsideTransaction() ...@@ -325,13 +325,13 @@ public void ScriptThrowsErrorInsideTransaction()
} }
[Fact] [Fact]
public void ChangeDbInScript() public async Task ChangeDbInScript()
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
var key = Me(); var key = Me();
muxer.GetDatabase(1).StringSet(key, "db 1"); muxer.GetDatabase(1).StringSet(key, "db 1", flags: CommandFlags.FireAndForget);
muxer.GetDatabase(2).StringSet(key, "db 2"); muxer.GetDatabase(2).StringSet(key, "db 2", flags: CommandFlags.FireAndForget);
Log("Key: " + key); Log("Key: " + key);
var conn = muxer.GetDatabase(2); var conn = muxer.GetDatabase(2);
...@@ -339,20 +339,20 @@ public void ChangeDbInScript() ...@@ -339,20 +339,20 @@ public void ChangeDbInScript()
return redis.call('get','" + key + "')", null, null); return redis.call('get','" + key + "')", null, null);
var getResult = conn.StringGetAsync(key); var getResult = conn.StringGetAsync(key);
Assert.Equal("db 1", (string)conn.Wait(evalResult)); Assert.Equal("db 1", (string)await evalResult);
// now, our connection thought it was in db 2, but the script changed to db 1 // now, our connection thought it was in db 2, but the script changed to db 1
Assert.Equal("db 2", conn.Wait(getResult)); Assert.Equal("db 2", await getResult);
} }
} }
[Fact] [Fact]
public void ChangeDbInTranScript() public async Task ChangeDbInTranScript()
{ {
using (var muxer = GetScriptConn()) using (var muxer = GetScriptConn())
{ {
var key = Me(); var key = Me();
muxer.GetDatabase(1).StringSet(key, "db 1"); muxer.GetDatabase(1).StringSet(key, "db 1", flags: CommandFlags.FireAndForget);
muxer.GetDatabase(2).StringSet(key, "db 2"); muxer.GetDatabase(2).StringSet(key, "db 2", flags: CommandFlags.FireAndForget);
var conn = muxer.GetDatabase(2); var conn = muxer.GetDatabase(2);
var tran = conn.CreateTransaction(); var tran = conn.CreateTransaction();
...@@ -361,9 +361,9 @@ public void ChangeDbInTranScript() ...@@ -361,9 +361,9 @@ public void ChangeDbInTranScript()
var getResult = tran.StringGetAsync(key); var getResult = tran.StringGetAsync(key);
Assert.True(tran.Execute()); Assert.True(tran.Execute());
Assert.Equal("db 1", (string)conn.Wait(evalResult)); Assert.Equal("db 1", (string)await evalResult);
// now, our connection thought it was in db 2, but the script changed to db 1 // now, our connection thought it was in db 2, but the script changed to db 1
Assert.Equal("db 2", conn.Wait(getResult)); Assert.Equal("db 2", await getResult);
} }
} }
...@@ -376,8 +376,8 @@ public void TestBasicScripting() ...@@ -376,8 +376,8 @@ public void TestBasicScripting()
RedisValue newId = Guid.NewGuid().ToString(); RedisValue newId = Guid.NewGuid().ToString();
RedisKey key = Me(); RedisKey key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.HashSet(key, "id", 123); db.HashSet(key, "id", 123, flags: CommandFlags.FireAndForget);
var wasSet = (bool)db.ScriptEvaluate("if redis.call('hexists', KEYS[1], 'UniqueId') then return redis.call('hset', KEYS[1], 'UniqueId', ARGV[1]) else return 0 end", var wasSet = (bool)db.ScriptEvaluate("if redis.call('hexists', KEYS[1], 'UniqueId') then return redis.call('hset', KEYS[1], 'UniqueId', ARGV[1]) else return 0 end",
new RedisKey[] { key }, new RedisValue[] { newId }); new RedisKey[] { key }, new RedisValue[] { newId });
...@@ -393,7 +393,7 @@ public void TestBasicScripting() ...@@ -393,7 +393,7 @@ public void TestBasicScripting()
[Theory] [Theory]
[InlineData(true)] [InlineData(true)]
[InlineData(false)] [InlineData(false)]
public void CheckLoads(bool async) public async Task CheckLoads(bool async)
{ {
using (var conn0 = Create(allowAdmin: true)) using (var conn0 = Create(allowAdmin: true))
using (var conn1 = Create(allowAdmin: true)) using (var conn1 = Create(allowAdmin: true))
...@@ -425,17 +425,8 @@ public void CheckLoads(bool async) ...@@ -425,17 +425,8 @@ public void CheckLoads(bool async)
if (async) if (async)
{ {
// now: fails the first time // now: fails the first time
try var ex = await Assert.ThrowsAsync<RedisServerException>(async () => await db.ScriptEvaluateAsync(script).ForAwait()).ForAwait();
{ Assert.Equal("NOSCRIPT No matching script. Please use EVAL.", ex.Message);
db.Wait(db.ScriptEvaluateAsync(script));
Assert.True(false, "ScriptEvaluateAsync should fail");
}
catch (AggregateException ex)
{
Assert.Single(ex.InnerExceptions);
Assert.IsType<RedisServerException>(ex.InnerExceptions[0]);
Assert.Equal("NOSCRIPT No matching script. Please use EVAL.", ex.InnerExceptions[0].Message);
}
} }
else else
{ {
...@@ -472,8 +463,7 @@ public void CompareScriptToDirect() ...@@ -472,8 +463,7 @@ public void CompareScriptToDirect()
RedisKey[] keys = new[] { key }; // script takes an array RedisKey[] keys = new[] { key }; // script takes an array
// run via script // run via script
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{ {
...@@ -484,8 +474,7 @@ public void CompareScriptToDirect() ...@@ -484,8 +474,7 @@ public void CompareScriptToDirect()
TimeSpan scriptTime = watch.Elapsed; TimeSpan scriptTime = watch.Elapsed;
// run via raw op // run via raw op
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
watch = Stopwatch.StartNew(); watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{ {
...@@ -519,14 +508,14 @@ public void TestCallByHash() ...@@ -519,14 +508,14 @@ public void TestCallByHash()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
RedisKey[] keys = { key }; RedisKey[] keys = { key };
string hexHash = string.Concat(hash.Select(x => x.ToString("X2"))); string hexHash = string.Concat(hash.Select(x => x.ToString("X2")));
Assert.Equal("2BAB3B661081DB58BD2341920E0BA7CF5DC77B25", hexHash); Assert.Equal("2BAB3B661081DB58BD2341920E0BA7CF5DC77B25", hexHash);
db.ScriptEvaluate(hexHash, keys); db.ScriptEvaluate(hexHash, keys, flags: CommandFlags.FireAndForget);
db.ScriptEvaluate(hash, keys); db.ScriptEvaluate(hash, keys, flags: CommandFlags.FireAndForget);
var count = (int)db.StringGet(keys)[0]; var count = (int)db.StringGet(keys)[0];
Assert.Equal(2, count); Assert.Equal(2, count);
...@@ -595,11 +584,11 @@ public void LuaScriptWithKeys() ...@@ -595,11 +584,11 @@ public void LuaScriptWithKeys()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var p = new { key = (RedisKey)key, value = 123 }; var p = new { key = (RedisKey)key, value = 123 };
script.Evaluate(db, p); script.Evaluate(db, p, flags: CommandFlags.FireAndForget);
var val = db.StringGet(key); var val = db.StringGet(key);
Assert.Equal(123, (int)val); Assert.Equal(123, (int)val);
...@@ -627,11 +616,11 @@ public void NoInlineReplacement() ...@@ -627,11 +616,11 @@ public void NoInlineReplacement()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var p = new { key }; var p = new { key };
script.Evaluate(db, p); script.Evaluate(db, p, flags: CommandFlags.FireAndForget);
var val = db.StringGet(key); var val = db.StringGet(key);
Assert.Equal("hello@example", val); Assert.Equal("hello@example", val);
} }
...@@ -710,11 +699,11 @@ public void LoadedLuaScriptWithKeys() ...@@ -710,11 +699,11 @@ public void LoadedLuaScriptWithKeys()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var p = new { key = (RedisKey)key, value = 123 }; var p = new { key = (RedisKey)key, value = 123 };
prepared.Evaluate(db, p); prepared.Evaluate(db, p, flags: CommandFlags.FireAndForget);
var val = db.StringGet(key); var val = db.StringGet(key);
Assert.Equal(123, (int)val); Assert.Equal(123, (int)val);
...@@ -759,9 +748,7 @@ public void PurgeLuaScriptOnFinalize() ...@@ -759,9 +748,7 @@ public void PurgeLuaScriptOnFinalize()
// This has to be a separate method to guarantee that the created LuaScript objects go out of scope, // This has to be a separate method to guarantee that the created LuaScript objects go out of scope,
// and are thus available to be GC'd // and are thus available to be GC'd
_PurgeLuaScriptOnFinalize(Script); _PurgeLuaScriptOnFinalize(Script);
CollectGarbage();
GC.Collect(2, GCCollectionMode.Forced, blocking: true);
GC.WaitForPendingFinalizers();
Assert.Equal(0, LuaScript.GetCachedScriptCount()); Assert.Equal(0, LuaScript.GetCachedScriptCount());
...@@ -780,14 +767,14 @@ public void IDatabaseLuaScriptConvenienceMethods() ...@@ -780,14 +767,14 @@ public void IDatabaseLuaScriptConvenienceMethods()
var script = LuaScript.Prepare(Script); var script = LuaScript.Prepare(Script);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
db.ScriptEvaluate(script, new { key = (RedisKey)key, value = "value" }); db.ScriptEvaluate(script, new { key = (RedisKey)key, value = "value" }, flags: CommandFlags.FireAndForget);
var val = db.StringGet(key); var val = db.StringGet(key);
Assert.Equal("value", val); Assert.Equal("value", val);
var prepared = script.Load(conn.GetServer(conn.GetEndPoints()[0])); var prepared = script.Load(conn.GetServer(conn.GetEndPoints()[0]));
db.ScriptEvaluate(prepared, new { key = (RedisKey)(key + "2"), value = "value2" }); db.ScriptEvaluate(prepared, new { key = (RedisKey)(key + "2"), value = "value2" }, flags: CommandFlags.FireAndForget);
var val2 = db.StringGet(key + "2"); var val2 = db.StringGet(key + "2");
Assert.Equal("value2", val2); Assert.Equal("value2", val2);
} }
...@@ -805,11 +792,11 @@ public void IServerLuaScriptConvenienceMethods() ...@@ -805,11 +792,11 @@ public void IServerLuaScriptConvenienceMethods()
var server = conn.GetServer(conn.GetEndPoints()[0]); var server = conn.GetServer(conn.GetEndPoints()[0]);
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var prepared = server.ScriptLoad(script); var prepared = server.ScriptLoad(script);
db.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = "value3" }); db.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = "value3" }, flags: CommandFlags.FireAndForget);
var val = db.StringGet(key); var val = db.StringGet(key);
Assert.Equal("value3", val); Assert.Equal("value3", val);
} }
...@@ -844,10 +831,10 @@ public void LuaScriptWithWrappedDatabase() ...@@ -844,10 +831,10 @@ public void LuaScriptWithWrappedDatabase()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var wrappedDb = KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix-"); var wrappedDb = KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix-");
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var prepared = LuaScript.Prepare(Script); var prepared = LuaScript.Prepare(Script);
wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = 123 }); wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = 123 }, flags: CommandFlags.FireAndForget);
var val1 = wrappedDb.StringGet(key); var val1 = wrappedDb.StringGet(key);
Assert.Equal(123, (int)val1); Assert.Equal(123, (int)val1);
...@@ -870,11 +857,11 @@ public void LoadedLuaScriptWithWrappedDatabase() ...@@ -870,11 +857,11 @@ public void LoadedLuaScriptWithWrappedDatabase()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var wrappedDb = KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix2-"); var wrappedDb = KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix2-");
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
var server = conn.GetServer(conn.GetEndPoints()[0]); var server = conn.GetServer(conn.GetEndPoints()[0]);
var prepared = LuaScript.Prepare(Script).Load(server); var prepared = LuaScript.Prepare(Script).Load(server);
wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = 123 }); wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)key, value = 123 }, flags: CommandFlags.FireAndForget);
var val1 = wrappedDb.StringGet(key); var val1 = wrappedDb.StringGet(key);
Assert.Equal(123, (int)val1); Assert.Equal(123, (int)val1);
......
...@@ -19,15 +19,14 @@ public void SScan() ...@@ -19,15 +19,14 @@ public void SScan()
RedisKey key = Me(); RedisKey key = Me();
var db = conn.GetDatabase(); var db = conn.GetDatabase();
db.KeyDelete(key);
int totalUnfiltered = 0, totalFiltered = 0; int totalUnfiltered = 0, totalFiltered = 0;
for (int i = 0; i < 1000; i++) for (int i = 1; i < 1001; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
totalUnfiltered += i; totalUnfiltered += i;
if (i.ToString().Contains("3")) totalFiltered += i; if (i.ToString().Contains("3")) totalFiltered += i;
} }
var unfilteredActual = db.SetScan(key).Select(x => (int)x).Sum(); var unfilteredActual = db.SetScan(key).Select(x => (int)x).Sum();
Assert.Equal(totalUnfiltered, unfilteredActual); Assert.Equal(totalUnfiltered, unfilteredActual);
if (server.Features.Scan) if (server.Features.Scan)
...@@ -47,12 +46,12 @@ public async Task SetRemoveArgTests() ...@@ -47,12 +46,12 @@ public async Task SetRemoveArgTests()
var key = Me(); var key = Me();
RedisValue[] values = null; RedisValue[] values = null;
Assert.Throws<ArgumentNullException>(() => db.SetRemove(key, values, CommandFlags.HighPriority)); Assert.Throws<ArgumentNullException>(() => db.SetRemove(key, values));
await Assert.ThrowsAsync<ArgumentNullException>(async () => await db.SetRemoveAsync(key, values, CommandFlags.HighPriority).ForAwait()).ForAwait(); await Assert.ThrowsAsync<ArgumentNullException>(async () => await db.SetRemoveAsync(key, values).ForAwait()).ForAwait();
values = new RedisValue[0]; values = new RedisValue[0];
Assert.Equal(0, db.SetRemove(key, values, CommandFlags.HighPriority)); Assert.Equal(0, db.SetRemove(key, values));
Assert.Equal(0, await db.SetRemoveAsync(key, values, CommandFlags.HighPriority).ForAwait()); Assert.Equal(0, await db.SetRemoveAsync(key, values).ForAwait());
} }
} }
...@@ -66,10 +65,10 @@ public void SetPopMulti_Multi() ...@@ -66,10 +65,10 @@ public void SetPopMulti_Multi()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
{ {
db.SetAdd(key, i); db.SetAddAsync(key, i, CommandFlags.FireAndForget);
} }
var random = db.SetPop(key); var random = db.SetPop(key);
...@@ -92,10 +91,10 @@ public void SetPopMulti_Single() ...@@ -92,10 +91,10 @@ public void SetPopMulti_Single()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
} }
var random = db.SetPop(key); var random = db.SetPop(key);
...@@ -121,10 +120,10 @@ public async Task SetPopMulti_Multi_Async() ...@@ -121,10 +120,10 @@ public async Task SetPopMulti_Multi_Async()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
} }
var random = await db.SetPopAsync(key).ForAwait(); var random = await db.SetPopAsync(key).ForAwait();
...@@ -148,10 +147,10 @@ public async Task SetPopMulti_Single_Async() ...@@ -148,10 +147,10 @@ public async Task SetPopMulti_Single_Async()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
} }
var random = await db.SetPopAsync(key).ForAwait(); var random = await db.SetPopAsync(key).ForAwait();
...@@ -175,10 +174,10 @@ public async Task SetPopMulti_Zero_Async() ...@@ -175,10 +174,10 @@ public async Task SetPopMulti_Zero_Async()
var db = conn.GetDatabase(); var db = conn.GetDatabase();
var key = Me(); var key = Me();
db.KeyDelete(key); db.KeyDelete(key, CommandFlags.FireAndForget);
for (int i = 1; i < 11; i++) for (int i = 1; i < 11; i++)
{ {
db.SetAdd(key, i); db.SetAdd(key, i, CommandFlags.FireAndForget);
} }
var t = db.SetPopAsync(key, count: 0); var t = db.SetPopAsync(key, count: 0);
......
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -10,19 +11,19 @@ public class Strings : TestBase // https://redis.io/commands#string ...@@ -10,19 +11,19 @@ public class Strings : TestBase // https://redis.io/commands#string
public Strings(ITestOutputHelper output) : base(output) { } public Strings(ITestOutputHelper output) : base(output) { }
[Fact] [Fact]
public void Append() public async Task Append()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var server = GetServer(muxer); var server = GetServer(muxer);
var key = Me(); var key = Me();
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
var l0 = server.Features.StringLength ? conn.StringLengthAsync(key) : null; var l0 = server.Features.StringLength ? conn.StringLengthAsync(key) : null;
var s0 = conn.StringGetAsync(key); var s0 = conn.StringGetAsync(key);
conn.StringSetAsync(key, "abc"); conn.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
var s1 = conn.StringGetAsync(key); var s1 = conn.StringGetAsync(key);
var l1 = server.Features.StringLength ? conn.StringLengthAsync(key) : null; var l1 = server.Features.StringLength ? conn.StringLengthAsync(key) : null;
...@@ -30,51 +31,51 @@ public void Append() ...@@ -30,51 +31,51 @@ public void Append()
var s3 = conn.StringGetAsync(key); var s3 = conn.StringGetAsync(key);
var l2 = server.Features.StringLength ? conn.StringLengthAsync(key) : null; var l2 = server.Features.StringLength ? conn.StringLengthAsync(key) : null;
Assert.Null((string)conn.Wait(s0)); Assert.Null((string)await s0);
Assert.Equal("abc", conn.Wait(s1)); Assert.Equal("abc", await s1);
Assert.Equal(8, conn.Wait(result)); Assert.Equal(8, await result);
Assert.Equal("abcdefgh", conn.Wait(s3)); Assert.Equal("abcdefgh", await s3);
if (server.Features.StringLength) if (server.Features.StringLength)
{ {
Assert.Equal(0, conn.Wait(l0)); Assert.Equal(0, await l0);
Assert.Equal(3, conn.Wait(l1)); Assert.Equal(3, await l1);
Assert.Equal(8, conn.Wait(l2)); Assert.Equal(8, await l2);
} }
} }
} }
[Fact] [Fact]
public void Set() public async Task Set()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.KeyDeleteAsync(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
conn.StringSetAsync(key, "abc"); conn.StringSet(key, "abc", flags: CommandFlags.FireAndForget);
var v1 = conn.StringGetAsync(key); var v1 = conn.StringGetAsync(key);
conn.StringSetAsync(key, Encode("def")); conn.StringSet(key, Encode("def"), flags: CommandFlags.FireAndForget);
var v2 = conn.StringGetAsync(key); var v2 = conn.StringGetAsync(key);
Assert.Equal("abc", conn.Wait(v1)); Assert.Equal("abc", await v1);
Assert.Equal("def", Decode(conn.Wait(v2))); Assert.Equal("def", Decode(await v2));
} }
} }
[Fact] [Fact]
public void SetNotExists() public async Task SetNotExists()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var prefix = Me(); var prefix = Me();
conn.KeyDeleteAsync(prefix + "1"); conn.KeyDelete(prefix + "1", CommandFlags.FireAndForget);
conn.KeyDeleteAsync(prefix + "2"); conn.KeyDelete(prefix + "2", CommandFlags.FireAndForget);
conn.KeyDeleteAsync(prefix + "3"); conn.KeyDelete(prefix + "3", CommandFlags.FireAndForget);
conn.StringSetAsync(prefix + "1", "abc"); conn.StringSet(prefix + "1", "abc", flags: CommandFlags.FireAndForget);
var x0 = conn.StringSetAsync(prefix + "1", "def", when: When.NotExists); var x0 = conn.StringSetAsync(prefix + "1", "def", when: When.NotExists);
var x1 = conn.StringSetAsync(prefix + "1", Encode("def"), when: When.NotExists); var x1 = conn.StringSetAsync(prefix + "1", Encode("def"), when: When.NotExists);
...@@ -85,18 +86,18 @@ public void SetNotExists() ...@@ -85,18 +86,18 @@ public void SetNotExists()
var s2 = conn.StringGetAsync(prefix + "2"); var s2 = conn.StringGetAsync(prefix + "2");
var s3 = conn.StringGetAsync(prefix + "3"); var s3 = conn.StringGetAsync(prefix + "3");
Assert.False(conn.Wait(x0)); Assert.False(await x0);
Assert.False(conn.Wait(x1)); Assert.False(await x1);
Assert.True(conn.Wait(x2)); Assert.True(await x2);
Assert.True(conn.Wait(x3)); Assert.True(await x3);
Assert.Equal("abc", conn.Wait(s0)); Assert.Equal("abc", await s0);
Assert.Equal("def", conn.Wait(s2)); Assert.Equal("def", await s2);
Assert.Equal("def", conn.Wait(s3)); Assert.Equal("def", await s3);
} }
} }
[Fact] [Fact]
public void Ranges() public async Task Ranges()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -104,28 +105,28 @@ public void Ranges() ...@@ -104,28 +105,28 @@ public void Ranges()
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.KeyDeleteAsync(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
conn.StringSetAsync(key, "abcdefghi"); conn.StringSet(key, "abcdefghi", flags: CommandFlags.FireAndForget);
conn.StringSetRangeAsync(key, 2, "xy"); conn.StringSetRange(key, 2, "xy", CommandFlags.FireAndForget);
conn.StringSetRangeAsync(key, 4, Encode("z")); conn.StringSetRange(key, 4, Encode("z"), CommandFlags.FireAndForget);
var val = conn.StringGetAsync(key); var val = conn.StringGetAsync(key);
Assert.Equal("abxyzfghi", conn.Wait(val)); Assert.Equal("abxyzfghi", await val);
} }
} }
[Fact] [Fact]
public void IncrDecr() public async Task IncrDecr()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.KeyDeleteAsync(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
conn.StringSetAsync(key, "2"); conn.StringSet(key, "2", flags: CommandFlags.FireAndForget);
var v1 = conn.StringIncrementAsync(key); var v1 = conn.StringIncrementAsync(key);
var v2 = conn.StringIncrementAsync(key, 5); var v2 = conn.StringIncrementAsync(key, 5);
var v3 = conn.StringIncrementAsync(key, -2); var v3 = conn.StringIncrementAsync(key, -2);
...@@ -134,27 +135,27 @@ public void IncrDecr() ...@@ -134,27 +135,27 @@ public void IncrDecr()
var v6 = conn.StringDecrementAsync(key, -2); var v6 = conn.StringDecrementAsync(key, -2);
var s = conn.StringGetAsync(key); var s = conn.StringGetAsync(key);
Assert.Equal(3, conn.Wait(v1)); Assert.Equal(3, await v1);
Assert.Equal(8, conn.Wait(v2)); Assert.Equal(8, await v2);
Assert.Equal(6, conn.Wait(v3)); Assert.Equal(6, await v3);
Assert.Equal(5, conn.Wait(v4)); Assert.Equal(5, await v4);
Assert.Equal(0, conn.Wait(v5)); Assert.Equal(0, await v5);
Assert.Equal(2, conn.Wait(v6)); Assert.Equal(2, await v6);
Assert.Equal("2", conn.Wait(s)); Assert.Equal("2", await s);
} }
} }
[Fact] [Fact]
public void IncrDecrFloat() public async Task IncrDecrFloat()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
Skip.IfMissingFeature(muxer, nameof(RedisFeatures.IncrementFloat), r => r.IncrementFloat); Skip.IfMissingFeature(muxer, nameof(RedisFeatures.IncrementFloat), r => r.IncrementFloat);
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.KeyDelete(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
conn.StringSetAsync(key, "2"); conn.StringSet(key, "2", flags: CommandFlags.FireAndForget);
var v1 = conn.StringIncrementAsync(key, 1.1); var v1 = conn.StringIncrementAsync(key, 1.1);
var v2 = conn.StringIncrementAsync(key, 5.0); var v2 = conn.StringIncrementAsync(key, 5.0);
var v3 = conn.StringIncrementAsync(key, -2.0); var v3 = conn.StringIncrementAsync(key, -2.0);
...@@ -164,36 +165,36 @@ public void IncrDecrFloat() ...@@ -164,36 +165,36 @@ public void IncrDecrFloat()
var s = conn.StringGetAsync(key); var s = conn.StringGetAsync(key);
Assert.Equal(3.1, conn.Wait(v1), 5); Assert.Equal(3.1, await v1, 5);
Assert.Equal(8.1, conn.Wait(v2), 5); Assert.Equal(8.1, await v2, 5);
Assert.Equal(6.1, conn.Wait(v3), 5); Assert.Equal(6.1, await v3, 5);
Assert.Equal(5.1, conn.Wait(v4), 5); Assert.Equal(5.1, await v4, 5);
Assert.Equal(0.1, conn.Wait(v5), 5); Assert.Equal(0.1, await v5, 5);
Assert.Equal(2.1, conn.Wait(v6), 5); Assert.Equal(2.1, await v6, 5);
Assert.Equal(2.1, (double)conn.Wait(s), 5); Assert.Equal(2.1, (double)await s, 5);
} }
} }
[Fact] [Fact]
public void GetRange() public async Task GetRange()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.KeyDeleteAsync(key); conn.KeyDelete(key, CommandFlags.FireAndForget);
conn.StringSetAsync(key, "abcdefghi"); conn.StringSet(key, "abcdefghi", flags: CommandFlags.FireAndForget);
var s = conn.StringGetRangeAsync(key, 2, 4); var s = conn.StringGetRangeAsync(key, 2, 4);
var b = conn.StringGetRangeAsync(key, 2, 4); var b = conn.StringGetRangeAsync(key, 2, 4);
Assert.Equal("cde", conn.Wait(s)); Assert.Equal("cde", await s);
Assert.Equal("cde", Decode(conn.Wait(b))); Assert.Equal("cde", Decode(await b));
} }
} }
[Fact] [Fact]
public void BitCount() public async Task BitCount()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -201,19 +202,19 @@ public void BitCount() ...@@ -201,19 +202,19 @@ public void BitCount()
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.StringSetAsync(key, "foobar"); conn.StringSet(key, "foobar", flags: CommandFlags.FireAndForget);
var r1 = conn.StringBitCountAsync(key); var r1 = conn.StringBitCountAsync(key);
var r2 = conn.StringBitCountAsync(key, 0, 0); var r2 = conn.StringBitCountAsync(key, 0, 0);
var r3 = conn.StringBitCountAsync(key, 1, 1); var r3 = conn.StringBitCountAsync(key, 1, 1);
Assert.Equal(26, conn.Wait(r1)); Assert.Equal(26, await r1);
Assert.Equal(4, conn.Wait(r2)); Assert.Equal(4, await r2);
Assert.Equal(6, conn.Wait(r3)); Assert.Equal(6, await r3);
} }
} }
[Fact] [Fact]
public void BitOp() public async Task BitOp()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -223,24 +224,24 @@ public void BitOp() ...@@ -223,24 +224,24 @@ public void BitOp()
var key1 = prefix + "1"; var key1 = prefix + "1";
var key2 = prefix + "2"; var key2 = prefix + "2";
var key3 = prefix + "3"; var key3 = prefix + "3";
conn.StringSetAsync(key1, new byte[] { 3 }); conn.StringSet(key1, new byte[] { 3 }, flags: CommandFlags.FireAndForget);
conn.StringSetAsync(key2, new byte[] { 6 }); conn.StringSet(key2, new byte[] { 6 }, flags: CommandFlags.FireAndForget);
conn.StringSetAsync(key3, new byte[] { 12 }); conn.StringSet(key3, new byte[] { 12 }, flags: CommandFlags.FireAndForget);
var len_and = conn.StringBitOperationAsync(Bitwise.And, "and", new RedisKey[] { key1, key2, key3 }); var len_and = conn.StringBitOperationAsync(Bitwise.And, "and", new RedisKey[] { key1, key2, key3 });
var len_or = conn.StringBitOperationAsync(Bitwise.Or, "or", new RedisKey[] { key1, key2, key3 }); var len_or = conn.StringBitOperationAsync(Bitwise.Or, "or", new RedisKey[] { key1, key2, key3 });
var len_xor = conn.StringBitOperationAsync(Bitwise.Xor, "xor", new RedisKey[] { key1, key2, key3 }); var len_xor = conn.StringBitOperationAsync(Bitwise.Xor, "xor", new RedisKey[] { key1, key2, key3 });
var len_not = conn.StringBitOperationAsync(Bitwise.Not, "not", key1); var len_not = conn.StringBitOperationAsync(Bitwise.Not, "not", key1);
Assert.Equal(1, conn.Wait(len_and)); Assert.Equal(1, await len_and);
Assert.Equal(1, conn.Wait(len_or)); Assert.Equal(1, await len_or);
Assert.Equal(1, conn.Wait(len_xor)); Assert.Equal(1, await len_xor);
Assert.Equal(1, conn.Wait(len_not)); Assert.Equal(1, await len_not);
var r_and = ((byte[])conn.Wait(conn.StringGetAsync("and"))).Single(); var r_and = ((byte[])(await conn.StringGetAsync("and").ForAwait())).Single();
var r_or = ((byte[])conn.Wait(conn.StringGetAsync("or"))).Single(); var r_or = ((byte[])(await conn.StringGetAsync("or").ForAwait())).Single();
var r_xor = ((byte[])conn.Wait(conn.StringGetAsync("xor"))).Single(); var r_xor = ((byte[])(await conn.StringGetAsync("xor").ForAwait())).Single();
var r_not = ((byte[])conn.Wait(conn.StringGetAsync("not"))).Single(); var r_not = ((byte[])(await conn.StringGetAsync("not").ForAwait())).Single();
Assert.Equal((byte)(3 & 6 & 12), r_and); Assert.Equal((byte)(3 & 6 & 12), r_and);
Assert.Equal((byte)(3 | 6 | 12), r_or); Assert.Equal((byte)(3 | 6 | 12), r_or);
...@@ -250,15 +251,15 @@ public void BitOp() ...@@ -250,15 +251,15 @@ public void BitOp()
} }
[Fact] [Fact]
public void RangeString() public async Task RangeString()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
var conn = muxer.GetDatabase(); var conn = muxer.GetDatabase();
var key = Me(); var key = Me();
conn.StringSetAsync(key, "hello world"); conn.StringSet(key, "hello world", flags: CommandFlags.FireAndForget);
var result = conn.StringGetRangeAsync(key, 2, 6); var result = conn.StringGetRangeAsync(key, 2, 6);
Assert.Equal("llo w", conn.Wait(result)); Assert.Equal("llo w", await result);
} }
} }
......
...@@ -47,11 +47,9 @@ protected void Log(string message, params object[] args) ...@@ -47,11 +47,9 @@ protected void Log(string message, params object[] args)
protected void CollectGarbage() protected void CollectGarbage()
{ {
for (int i = 0; i < 3; i++) GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
{ GC.WaitForPendingFinalizers();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
}
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
...@@ -63,7 +61,7 @@ public void Dispose() ...@@ -63,7 +61,7 @@ public void Dispose()
#if VERBOSE #if VERBOSE
protected const int AsyncOpsQty = 100, SyncOpsQty = 10; protected const int AsyncOpsQty = 100, SyncOpsQty = 10;
#else #else
protected const int AsyncOpsQty = 100000, SyncOpsQty = 10000; protected const int AsyncOpsQty = 10000, SyncOpsQty = 10000;
#endif #endif
static TestBase() static TestBase()
...@@ -91,7 +89,7 @@ protected void OnConnectionFailed(object sender, ConnectionFailedEventArgs e) ...@@ -91,7 +89,7 @@ protected void OnConnectionFailed(object sender, ConnectionFailedEventArgs e)
Interlocked.Increment(ref privateFailCount); Interlocked.Increment(ref privateFailCount);
lock (privateExceptions) lock (privateExceptions)
{ {
privateExceptions.Add("Connection failed: " + EndPointCollection.ToString(e.EndPoint) + "/" + e.ConnectionType); privateExceptions.Add($"Connection failed ({e.FailureType}): {EndPointCollection.ToString(e.EndPoint)}/{e.ConnectionType}: {e.Exception}");
} }
} }
...@@ -113,7 +111,6 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e) ...@@ -113,7 +111,6 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
public void ClearAmbientFailures() public void ClearAmbientFailures()
{ {
Collect();
Interlocked.Exchange(ref privateFailCount, 0); Interlocked.Exchange(ref privateFailCount, 0);
lock (sharedFailCount) lock (sharedFailCount)
{ {
...@@ -135,18 +132,8 @@ public void SetExpectedAmbientFailureCount(int count) ...@@ -135,18 +132,8 @@ public void SetExpectedAmbientFailureCount(int count)
expectedFailCount = count; expectedFailCount = count;
} }
private static void Collect()
{
for (int i = 0; i < GC.MaxGeneration; i++)
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
}
}
public void Teardown() public void Teardown()
{ {
Collect();
int sharedFails; int sharedFails;
lock (sharedFailCount) lock (sharedFailCount)
{ {
......
...@@ -44,7 +44,7 @@ public void NestedTransactionThrows() ...@@ -44,7 +44,7 @@ public void NestedTransactionThrows()
[InlineData(false, true, false)] [InlineData(false, true, false)]
[InlineData(true, false, false)] [InlineData(true, false, false)]
[InlineData(true, true, true)] [InlineData(true, true, true)]
public void BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult) public async Task BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult)
{ {
using (var muxer = Create(disabledCommands: new[] { "info", "config" })) using (var muxer = Create(disabledCommands: new[] { "info", "config" }))
{ {
...@@ -62,17 +62,17 @@ public void BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, b ...@@ -62,17 +62,17 @@ public void BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, b
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (demandKeyExists == keyExists) if (demandKeyExists == keyExists)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -92,7 +92,7 @@ public void BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, b ...@@ -92,7 +92,7 @@ public void BasicTranWithExistsCondition(bool demandKeyExists, bool keyExists, b
[InlineData("x", null, false, true)] [InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)] [InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)] [InlineData(null, null, false, false)]
public void BasicTranWithEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult) public async Task BasicTranWithEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -111,17 +111,17 @@ public void BasicTranWithEqualsCondition(string expected, string value, bool exp ...@@ -111,17 +111,17 @@ public void BasicTranWithEqualsCondition(string expected, string value, bool exp
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectEqual == (value == expected)) if (expectEqual == (value == expected))
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -134,7 +134,7 @@ public void BasicTranWithEqualsCondition(string expected, string value, bool exp ...@@ -134,7 +134,7 @@ public void BasicTranWithEqualsCondition(string expected, string value, bool exp
[InlineData(false, true, false)] [InlineData(false, true, false)]
[InlineData(true, false, false)] [InlineData(true, false, false)]
[InlineData(true, true, true)] [InlineData(true, true, true)]
public void BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult) public async Task BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult)
{ {
using (var muxer = Create(disabledCommands: new[] { "info", "config" })) using (var muxer = Create(disabledCommands: new[] { "info", "config" }))
{ {
...@@ -153,17 +153,17 @@ public void BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExist ...@@ -153,17 +153,17 @@ public void BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExist
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (demandKeyExists == keyExists) if (demandKeyExists == keyExists)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -183,7 +183,7 @@ public void BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExist ...@@ -183,7 +183,7 @@ public void BasicTranWithHashExistsCondition(bool demandKeyExists, bool keyExist
[InlineData("x", null, false, true)] [InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)] [InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)] [InlineData(null, null, false, false)]
public void BasicTranWithHashEqualsCondition(string expected, string value, bool expectEqual, bool expectedTranResult) public async Task BasicTranWithHashEqualsCondition(string expected, string value, bool expectEqual, bool expectedTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -203,17 +203,17 @@ public void BasicTranWithHashEqualsCondition(string expected, string value, bool ...@@ -203,17 +203,17 @@ public void BasicTranWithHashEqualsCondition(string expected, string value, bool
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectedTranResult, db.Wait(exec)); Assert.Equal(expectedTranResult, await exec);
if (expectEqual == (value == expected)) if (expectEqual == (value == expected))
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -226,7 +226,7 @@ public void BasicTranWithHashEqualsCondition(string expected, string value, bool ...@@ -226,7 +226,7 @@ public void BasicTranWithHashEqualsCondition(string expected, string value, bool
[InlineData(false, true, false)] [InlineData(false, true, false)]
[InlineData(true, false, false)] [InlineData(true, false, false)]
[InlineData(true, true, true)] [InlineData(true, true, true)]
public void BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult) public async Task BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult)
{ {
using (var muxer = Create(disabledCommands: new[] { "info", "config" })) using (var muxer = Create(disabledCommands: new[] { "info", "config" }))
{ {
...@@ -244,17 +244,17 @@ public void BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExist ...@@ -244,17 +244,17 @@ public void BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExist
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.ListGetByIndex(key, 0); var get = db.ListGetByIndex(key, 0);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (demandKeyExists == keyExists) if (demandKeyExists == keyExists)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(push)); // eq: push Assert.Equal(1, await push); // eq: push
Assert.Equal("any value", (string)get); // eq: get Assert.Equal("any value", (string)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Null((string)get); // neq: get Assert.Null((string)get); // neq: get
...@@ -274,7 +274,7 @@ public void BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExist ...@@ -274,7 +274,7 @@ public void BasicTranWithListExistsCondition(bool demandKeyExists, bool keyExist
[InlineData("x", null, false, true)] [InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)] [InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)] [InlineData(null, null, false, false)]
public void BasicTranWithListEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult) public async Task BasicTranWithListEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -293,17 +293,17 @@ public void BasicTranWithListEqualsCondition(string expected, string value, bool ...@@ -293,17 +293,17 @@ public void BasicTranWithListEqualsCondition(string expected, string value, bool
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.ListGetByIndex(key, 0); var get = db.ListGetByIndex(key, 0);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectEqual == (value == expected)) if (expectEqual == (value == expected))
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(push)); // eq: push Assert.Equal(1, await push); // eq: push
Assert.Equal("any value", get); // eq: get Assert.Equal("any value", get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Null((string)get); // neq: get Assert.Null((string)get); // neq: get
...@@ -342,7 +342,7 @@ public enum ComparisonType ...@@ -342,7 +342,7 @@ public enum ComparisonType
[InlineData("", ComparisonType.GreaterThan, 0L, false)] [InlineData("", ComparisonType.GreaterThan, 0L, false)]
[InlineData(null, ComparisonType.GreaterThan, 1L, false)] [InlineData(null, ComparisonType.GreaterThan, 1L, false)]
[InlineData(null, ComparisonType.GreaterThan, 0L, false)] [InlineData(null, ComparisonType.GreaterThan, 0L, false)]
public void BasicTranWithStringLengthCondition(string value, ComparisonType type, long length, bool expectTranResult) public async Task BasicTranWithStringLengthCondition(string value, ComparisonType type, long length, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -383,18 +383,18 @@ public void BasicTranWithStringLengthCondition(string value, ComparisonType type ...@@ -383,18 +383,18 @@ public void BasicTranWithStringLengthCondition(string value, ComparisonType type
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringLength(key); var get = db.StringLength(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectSuccess) if (expectSuccess)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.True(db.Wait(push)); // eq: push Assert.True(await push); // eq: push
Assert.Equal("any value".Length, get); // eq: get Assert.Equal("any value".Length, get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Equal(0, get); // neq: get Assert.Equal(0, get); // neq: get
...@@ -420,7 +420,7 @@ public void BasicTranWithStringLengthCondition(string value, ComparisonType type ...@@ -420,7 +420,7 @@ public void BasicTranWithStringLengthCondition(string value, ComparisonType type
[InlineData("three", ComparisonType.GreaterThan, 3L, true)] [InlineData("three", ComparisonType.GreaterThan, 3L, true)]
[InlineData("", ComparisonType.GreaterThan, 2L, false)] [InlineData("", ComparisonType.GreaterThan, 2L, false)]
[InlineData("", ComparisonType.GreaterThan, 0L, false)] [InlineData("", ComparisonType.GreaterThan, 0L, false)]
public void BasicTranWithHashLengthCondition(string value, ComparisonType type, long length, bool expectTranResult) public async Task BasicTranWithHashLengthCondition(string value, ComparisonType type, long length, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -461,18 +461,18 @@ public void BasicTranWithHashLengthCondition(string value, ComparisonType type, ...@@ -461,18 +461,18 @@ public void BasicTranWithHashLengthCondition(string value, ComparisonType type,
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringLength(key); var get = db.StringLength(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectSuccess) if (expectSuccess)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.True(db.Wait(push)); // eq: push Assert.True(await push); // eq: push
Assert.Equal("any value".Length, get); // eq: get Assert.Equal("any value".Length, get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Equal(0, get); // neq: get Assert.Equal(0, get); // neq: get
...@@ -498,7 +498,7 @@ public void BasicTranWithHashLengthCondition(string value, ComparisonType type, ...@@ -498,7 +498,7 @@ public void BasicTranWithHashLengthCondition(string value, ComparisonType type,
[InlineData("three", ComparisonType.GreaterThan, 3L, true)] [InlineData("three", ComparisonType.GreaterThan, 3L, true)]
[InlineData("", ComparisonType.GreaterThan, 2L, false)] [InlineData("", ComparisonType.GreaterThan, 2L, false)]
[InlineData("", ComparisonType.GreaterThan, 0L, false)] [InlineData("", ComparisonType.GreaterThan, 0L, false)]
public void BasicTranWithSetCardinalityCondition(string value, ComparisonType type, long length, bool expectTranResult) public async Task BasicTranWithSetCardinalityCondition(string value, ComparisonType type, long length, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -539,18 +539,18 @@ public void BasicTranWithSetCardinalityCondition(string value, ComparisonType ty ...@@ -539,18 +539,18 @@ public void BasicTranWithSetCardinalityCondition(string value, ComparisonType ty
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringLength(key); var get = db.StringLength(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectSuccess) if (expectSuccess)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.True(db.Wait(push)); // eq: push Assert.True(await push); // eq: push
Assert.Equal("any value".Length, get); // eq: get Assert.Equal("any value".Length, get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Equal(0, get); // neq: get Assert.Equal(0, get); // neq: get
...@@ -563,7 +563,7 @@ public void BasicTranWithSetCardinalityCondition(string value, ComparisonType ty ...@@ -563,7 +563,7 @@ public void BasicTranWithSetCardinalityCondition(string value, ComparisonType ty
[InlineData(false, true, false)] [InlineData(false, true, false)]
[InlineData(true, false, false)] [InlineData(true, false, false)]
[InlineData(true, true, true)] [InlineData(true, true, true)]
public void BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult) public async Task BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult)
{ {
using (var muxer = Create(disabledCommands: new[] { "info", "config" })) using (var muxer = Create(disabledCommands: new[] { "info", "config" }))
{ {
...@@ -582,17 +582,17 @@ public void BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExis ...@@ -582,17 +582,17 @@ public void BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExis
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (demandKeyExists == keyExists) if (demandKeyExists == keyExists)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -618,7 +618,7 @@ public void BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExis ...@@ -618,7 +618,7 @@ public void BasicTranWithSetContainsCondition(bool demandKeyExists, bool keyExis
[InlineData("three", ComparisonType.GreaterThan, 3L, true)] [InlineData("three", ComparisonType.GreaterThan, 3L, true)]
[InlineData("", ComparisonType.GreaterThan, 2L, false)] [InlineData("", ComparisonType.GreaterThan, 2L, false)]
[InlineData("", ComparisonType.GreaterThan, 0L, false)] [InlineData("", ComparisonType.GreaterThan, 0L, false)]
public void BasicTranWithSortedSetCardinalityCondition(string value, ComparisonType type, long length, bool expectTranResult) public async Task BasicTranWithSortedSetCardinalityCondition(string value, ComparisonType type, long length, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -659,18 +659,18 @@ public void BasicTranWithSortedSetCardinalityCondition(string value, ComparisonT ...@@ -659,18 +659,18 @@ public void BasicTranWithSortedSetCardinalityCondition(string value, ComparisonT
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringLength(key); var get = db.StringLength(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectSuccess) if (expectSuccess)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.True(db.Wait(push)); // eq: push Assert.True(await push); // eq: push
Assert.Equal("any value".Length, get); // eq: get Assert.Equal("any value".Length, get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Equal(0, get); // neq: get Assert.Equal(0, get); // neq: get
...@@ -683,7 +683,7 @@ public void BasicTranWithSortedSetCardinalityCondition(string value, ComparisonT ...@@ -683,7 +683,7 @@ public void BasicTranWithSortedSetCardinalityCondition(string value, ComparisonT
[InlineData(false, true, false)] [InlineData(false, true, false)]
[InlineData(true, false, false)] [InlineData(true, false, false)]
[InlineData(true, true, true)] [InlineData(true, true, true)]
public void BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult) public async Task BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool keyExists, bool expectTranResult)
{ {
using (var muxer = Create(disabledCommands: new[] { "info", "config" })) using (var muxer = Create(disabledCommands: new[] { "info", "config" }))
{ {
...@@ -702,17 +702,17 @@ public void BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool k ...@@ -702,17 +702,17 @@ public void BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool k
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringGet(key); var get = db.StringGet(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (demandKeyExists == keyExists) if (demandKeyExists == keyExists)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.Equal(1, db.Wait(incr)); // eq: incr Assert.Equal(1, await incr); // eq: incr
Assert.Equal(1, (long)get); // eq: get Assert.Equal(1, (long)get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr Assert.Equal(TaskStatus.Canceled, incr.Status); // neq: incr
Assert.Equal(0, (long)get); // neq: get Assert.Equal(0, (long)get); // neq: get
...@@ -738,7 +738,7 @@ public void BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool k ...@@ -738,7 +738,7 @@ public void BasicTranWithSortedSetContainsCondition(bool demandKeyExists, bool k
[InlineData("three", ComparisonType.GreaterThan, 3L, true)] [InlineData("three", ComparisonType.GreaterThan, 3L, true)]
[InlineData("", ComparisonType.GreaterThan, 2L, false)] [InlineData("", ComparisonType.GreaterThan, 2L, false)]
[InlineData("", ComparisonType.GreaterThan, 0L, false)] [InlineData("", ComparisonType.GreaterThan, 0L, false)]
public void BasicTranWithListLengthCondition(string value, ComparisonType type, long length, bool expectTranResult) public async Task BasicTranWithListLengthCondition(string value, ComparisonType type, long length, bool expectTranResult)
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -779,18 +779,18 @@ public void BasicTranWithListLengthCondition(string value, ComparisonType type, ...@@ -779,18 +779,18 @@ public void BasicTranWithListLengthCondition(string value, ComparisonType type,
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
var get = db.StringLength(key); var get = db.StringLength(key);
Assert.Equal(expectTranResult, db.Wait(exec)); Assert.Equal(expectTranResult, await exec);
if (expectSuccess) if (expectSuccess)
{ {
Assert.True(db.Wait(exec), "eq: exec"); Assert.True(await exec, "eq: exec");
Assert.True(cond.WasSatisfied, "eq: was satisfied"); Assert.True(cond.WasSatisfied, "eq: was satisfied");
Assert.True(db.Wait(push)); // eq: push Assert.True(await push); // eq: push
Assert.Equal("any value".Length, get); // eq: get Assert.Equal("any value".Length, get); // eq: get
} }
else else
{ {
Assert.False(db.Wait(exec), "neq: exec"); Assert.False(await exec, "neq: exec");
Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.False(cond.WasSatisfied, "neq: was satisfied");
Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push Assert.Equal(TaskStatus.Canceled, push.Status); // neq: push
Assert.Equal(0, get); // neq: get Assert.Equal(0, get); // neq: get
...@@ -821,9 +821,9 @@ public async Task BasicTran() ...@@ -821,9 +821,9 @@ public async Task BasicTran()
Assert.False(d.IsCompleted); Assert.False(d.IsCompleted);
Assert.False(e.IsCompleted); Assert.False(e.IsCompleted);
Assert.False(f.IsCompleted); Assert.False(f.IsCompleted);
var result = db.Wait(tran.ExecuteAsync()); var result = await tran.ExecuteAsync().ForAwait();
Assert.True(result, "result"); Assert.True(result, "result");
db.WaitAll(a, b, c, d, e, f); await Task.WhenAll(a, b, c, d, e, f).ForAwait();
Assert.True(a.IsCompleted, "a"); Assert.True(a.IsCompleted, "a");
Assert.True(b.IsCompleted, "b"); Assert.True(b.IsCompleted, "b");
Assert.True(c.IsCompleted, "c"); Assert.True(c.IsCompleted, "c");
...@@ -844,7 +844,7 @@ public async Task BasicTran() ...@@ -844,7 +844,7 @@ public async Task BasicTran()
} }
[Fact] [Fact]
public void CombineFireAndForgetAndRegularAsyncInTransaction() public async Task CombineFireAndForgetAndRegularAsyncInTransaction()
{ {
using (var muxer = Create()) using (var muxer = Create())
{ {
...@@ -860,11 +860,11 @@ public void CombineFireAndForgetAndRegularAsyncInTransaction() ...@@ -860,11 +860,11 @@ public void CombineFireAndForgetAndRegularAsyncInTransaction()
Assert.True(tran.Execute()); Assert.True(tran.Execute());
var count = (long)db.StringGet(key); var count = (long)db.StringGet(key);
Assert.Equal(5, db.Wait(a)); Assert.Equal(5, await a);
Assert.Equal("state", a.AsyncState); Assert.Equal("state", a.AsyncState);
Assert.Equal(0, db.Wait(b)); Assert.Equal(0, await b);
Assert.Null(b.AsyncState); Assert.Null(b.AsyncState);
Assert.Equal(30, db.Wait(c)); Assert.Equal(30, await c);
Assert.Equal("state", a.AsyncState); Assert.Equal("state", a.AsyncState);
Assert.Equal(30, count); Assert.Equal(30, count);
} }
......
...@@ -7,7 +7,7 @@ namespace StackExchange.Redis.Tests ...@@ -7,7 +7,7 @@ namespace StackExchange.Redis.Tests
{ {
public class WithKeyPrefixTests : TestBase public class WithKeyPrefixTests : TestBase
{ {
public WithKeyPrefixTests(ITestOutputHelper output) : base (output) { } public WithKeyPrefixTests(ITestOutputHelper output) : base(output) { }
[Fact] [Fact]
public void BlankPrefixYieldsSame_Bytes() public void BlankPrefixYieldsSame_Bytes()
...@@ -34,7 +34,8 @@ public void BlankPrefixYieldsSame_String() ...@@ -34,7 +34,8 @@ public void BlankPrefixYieldsSame_String()
[Fact] [Fact]
public void NullPrefixIsError_Bytes() public void NullPrefixIsError_Bytes()
{ {
Assert.Throws<ArgumentNullException>(() => { Assert.Throws<ArgumentNullException>(() =>
{
using (var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(); var raw = conn.GetDatabase();
...@@ -46,7 +47,8 @@ public void NullPrefixIsError_Bytes() ...@@ -46,7 +47,8 @@ public void NullPrefixIsError_Bytes()
[Fact] [Fact]
public void NullPrefixIsError_String() public void NullPrefixIsError_String()
{ {
Assert.Throws<ArgumentNullException>(() => { Assert.Throws<ArgumentNullException>(() =>
{
using (var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(); var raw = conn.GetDatabase();
...@@ -61,7 +63,8 @@ public void NullPrefixIsError_String() ...@@ -61,7 +63,8 @@ public void NullPrefixIsError_String()
[InlineData(null)] [InlineData(null)]
public void NullDatabaseIsError(string prefix) public void NullDatabaseIsError(string prefix)
{ {
Assert.Throws<ArgumentNullException>(() => { Assert.Throws<ArgumentNullException>(() =>
{
IDatabase raw = null; IDatabase raw = null;
var prefixed = raw.WithKeyPrefix(prefix); var prefixed = raw.WithKeyPrefix(prefix);
}); });
...@@ -70,7 +73,7 @@ public void NullDatabaseIsError(string prefix) ...@@ -70,7 +73,7 @@ public void NullDatabaseIsError(string prefix)
[Fact] [Fact]
public void BasicSmokeTest() public void BasicSmokeTest()
{ {
using(var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(); var raw = conn.GetDatabase();
...@@ -82,11 +85,11 @@ public void BasicSmokeTest() ...@@ -82,11 +85,11 @@ public void BasicSmokeTest()
string s = Guid.NewGuid().ToString(), t = Guid.NewGuid().ToString(); string s = Guid.NewGuid().ToString(), t = Guid.NewGuid().ToString();
foo.StringSet(key, s); foo.StringSet(key, s, flags: CommandFlags.FireAndForget);
var val = (string)foo.StringGet(key); var val = (string)foo.StringGet(key);
Assert.Equal(s, val); // fooBasicSmokeTest Assert.Equal(s, val); // fooBasicSmokeTest
foobar.StringSet(key, t); foobar.StringSet(key, t, flags: CommandFlags.FireAndForget);
val = (string)foobar.StringGet(key); val = (string)foobar.StringGet(key);
Assert.Equal(t, val); // foobarBasicSmokeTest Assert.Equal(t, val); // foobarBasicSmokeTest
...@@ -104,18 +107,18 @@ public void BasicSmokeTest() ...@@ -104,18 +107,18 @@ public void BasicSmokeTest()
[Fact] [Fact]
public void ConditionTest() public void ConditionTest()
{ {
using(var conn = Create()) using (var conn = Create())
{ {
var raw = conn.GetDatabase(); var raw = conn.GetDatabase();
var prefix = Me() + ":"; var prefix = Me() + ":";
var foo = raw.WithKeyPrefix(prefix); var foo = raw.WithKeyPrefix(prefix);
raw.KeyDelete(prefix + "abc"); raw.KeyDelete(prefix + "abc", CommandFlags.FireAndForget);
raw.KeyDelete(prefix + "i"); raw.KeyDelete(prefix + "i", CommandFlags.FireAndForget);
// execute while key exists // execute while key exists
raw.StringSet(prefix + "abc", "def"); raw.StringSet(prefix + "abc", "def", flags: CommandFlags.FireAndForget);
var tran = foo.CreateTransaction(); var tran = foo.CreateTransaction();
tran.AddCondition(Condition.KeyExists("abc")); tran.AddCondition(Condition.KeyExists("abc"));
tran.StringIncrementAsync("i"); tran.StringIncrementAsync("i");
...@@ -125,7 +128,7 @@ public void ConditionTest() ...@@ -125,7 +128,7 @@ public void ConditionTest()
Assert.Equal(1, i); Assert.Equal(1, i);
// repeat without key // repeat without key
raw.KeyDelete(prefix + "abc"); raw.KeyDelete(prefix + "abc", CommandFlags.FireAndForget);
tran = foo.CreateTransaction(); tran = foo.CreateTransaction();
tran.AddCondition(Condition.KeyExists("abc")); tran.AddCondition(Condition.KeyExists("abc"));
tran.StringIncrementAsync("i"); tran.StringIncrementAsync("i");
......
...@@ -53,6 +53,6 @@ private static void AnyOrderCompletionHandler(object state) ...@@ -53,6 +53,6 @@ private static void AnyOrderCompletionHandler(object state)
{ {
ConnectionMultiplexer.TraceWithoutContext("Async completion error: " + ex.Message); ConnectionMultiplexer.TraceWithoutContext("Async completion error: " + ex.Message);
} }
} }
} }
} }
...@@ -186,10 +186,13 @@ public static string TryNormalize(string value) ...@@ -186,10 +186,13 @@ public static string TryNormalize(string value)
/// <summary> /// <summary>
/// Create a certificate validation check that checks against the supplied issuer even if not known by the machine /// Create a certificate validation check that checks against the supplied issuer even if not known by the machine
/// </summary> /// </summary>
/// <param name="issuerCertificatePath">The file system path to find the certificate at.</param>
public void TrustIssuer(string issuerCertificatePath) => CertificateValidationCallback = TrustIssuerCallback(issuerCertificatePath); public void TrustIssuer(string issuerCertificatePath) => CertificateValidationCallback = TrustIssuerCallback(issuerCertificatePath);
/// <summary> /// <summary>
/// Create a certificate validation check that checks against the supplied issuer even if not known by the machine /// Create a certificate validation check that checks against the supplied issuer even if not known by the machine
/// </summary> /// </summary>
/// <param name="issuer">The issuer to trust.</param>
public void TrustIssuer(X509Certificate2 issuer) => CertificateValidationCallback = TrustIssuerCallback(issuer); public void TrustIssuer(X509Certificate2 issuer) => CertificateValidationCallback = TrustIssuerCallback(issuer);
internal static RemoteCertificateValidationCallback TrustIssuerCallback(string issuerCertificatePath) internal static RemoteCertificateValidationCallback TrustIssuerCallback(string issuerCertificatePath)
...@@ -202,7 +205,8 @@ private static RemoteCertificateValidationCallback TrustIssuerCallback(X509Certi ...@@ -202,7 +205,8 @@ private static RemoteCertificateValidationCallback TrustIssuerCallback(X509Certi
=> sslPolicyError == SslPolicyErrors.RemoteCertificateChainErrors && certificate is X509Certificate2 v2 => sslPolicyError == SslPolicyErrors.RemoteCertificateChainErrors && certificate is X509Certificate2 v2
&& CheckTrustedIssuer(v2, issuer); && CheckTrustedIssuer(v2, issuer);
} }
static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X509Certificate2 authority)
private static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X509Certificate2 authority)
{ {
// reference: https://stackoverflow.com/questions/6497040/how-do-i-validate-that-a-certificate-was-created-by-a-particular-certification-a // reference: https://stackoverflow.com/questions/6497040/how-do-i-validate-that-a-certificate-was-created-by-a-particular-certification-a
X509Chain chain = new X509Chain(); X509Chain chain = new X509Chain();
...@@ -215,7 +219,6 @@ static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X509Certi ...@@ -215,7 +219,6 @@ static bool CheckTrustedIssuer(X509Certificate2 certificateToValidate, X509Certi
chain.ChainPolicy.ExtraStore.Add(authority); chain.ChainPolicy.ExtraStore.Add(authority);
return chain.Build(certificateToValidate); return chain.Build(certificateToValidate);
} }
/// <summary> /// <summary>
/// The client name to use for all connections /// The client name to use for all connections
...@@ -729,14 +732,8 @@ private void DoParse(string configuration, bool ignoreUnknown) ...@@ -729,14 +732,8 @@ private void DoParse(string configuration, bool ignoreUnknown)
} }
} }
private bool GetDefaultAbortOnConnectFailSetting() // Microsoft Azure team wants abortConnect=false by default
{ private bool GetDefaultAbortOnConnectFailSetting() => !IsAzureEndpoint();
// Microsoft Azure team wants abortConnect=false by default
if (IsAzureEndpoint())
return false;
return true;
}
private bool IsAzureEndpoint() private bool IsAzureEndpoint()
{ {
......
...@@ -452,7 +452,7 @@ internal void CheckMessage(Message message) ...@@ -452,7 +452,7 @@ internal void CheckMessage(Message message)
throw ExceptionFactory.AdminModeNotEnabled(IncludeDetailInExceptions, message.Command, message, null); throw ExceptionFactory.AdminModeNotEnabled(IncludeDetailInExceptions, message.Command, message, null);
CommandMap.AssertAvailable(message.Command); CommandMap.AssertAvailable(message.Command);
} }
const string NoContent = "(no content)"; private const string NoContent = "(no content)";
private static void WriteNormalizingLineEndings(string source, StreamWriter writer) private static void WriteNormalizingLineEndings(string source, StreamWriter writer)
{ {
if (source == null) if (source == null)
...@@ -645,8 +645,10 @@ private async Task<bool> WaitAllIgnoreErrorsAsync(Task[] tasks, int timeoutMilli ...@@ -645,8 +645,10 @@ private async Task<bool> WaitAllIgnoreErrorsAsync(Task[] tasks, int timeoutMilli
} }
var allTasks = Task.WhenAll(tasks).ObserveErrors(); var allTasks = Task.WhenAll(tasks).ObserveErrors();
var any = Task.WhenAny(allTasks, Task.Delay(remaining)).ObserveErrors(); var cts = new CancellationTokenSource();
var any = Task.WhenAny(allTasks, Task.Delay(remaining, cts.Token)).ObserveErrors();
bool all = await any.ForAwait() == allTasks; bool all = await any.ForAwait() == allTasks;
cts.Cancel();
LogLockedWithThreadPoolStats(log, all ? "All tasks completed cleanly" : $"Not all tasks completed cleanly (from {caller}#{callerLineNumber}, timeout {timeoutMilliseconds}ms)", out busyWorkerCount); LogLockedWithThreadPoolStats(log, all ? "All tasks completed cleanly" : $"Not all tasks completed cleanly (from {caller}#{callerLineNumber}, timeout {timeoutMilliseconds}ms)", out busyWorkerCount);
return all; return all;
} }
...@@ -798,13 +800,13 @@ private static ConnectionMultiplexer CreateMultiplexer(object configuration) ...@@ -798,13 +800,13 @@ private static ConnectionMultiplexer CreateMultiplexer(object configuration)
{ {
if (configuration == null) throw new ArgumentNullException(nameof(configuration)); if (configuration == null) throw new ArgumentNullException(nameof(configuration));
ConfigurationOptions config; ConfigurationOptions config;
if (configuration is string) if (configuration is string s)
{ {
config = ConfigurationOptions.Parse((string)configuration); config = ConfigurationOptions.Parse(s);
} }
else if (configuration is ConfigurationOptions) else if (configuration is ConfigurationOptions configurationOptions)
{ {
config = ((ConfigurationOptions)configuration).Clone(); config = (configurationOptions).Clone();
} }
else else
{ {
...@@ -871,7 +873,7 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul ...@@ -871,7 +873,7 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul
private readonly Hashtable servers = new Hashtable(); private readonly Hashtable servers = new Hashtable();
private volatile ServerSnapshot _serverSnapshot = ServerSnapshot.Empty; private volatile ServerSnapshot _serverSnapshot = ServerSnapshot.Empty;
internal ReadOnlySpan<ServerEndPoint> GetServerSnapshot() => _serverSnapshot.Span; internal ReadOnlySpan<ServerEndPoint> GetServerSnapshot() => _serverSnapshot.Span;
sealed class ServerSnapshot private sealed class ServerSnapshot
{ {
public static ServerSnapshot Empty { get; } = new ServerSnapshot(Array.Empty<ServerEndPoint>(), 0); public static ServerSnapshot Empty { get; } = new ServerSnapshot(Array.Empty<ServerEndPoint>(), 0);
private ServerSnapshot(ServerEndPoint[] arr, int count) private ServerSnapshot(ServerEndPoint[] arr, int count)
...@@ -879,8 +881,8 @@ private ServerSnapshot(ServerEndPoint[] arr, int count) ...@@ -879,8 +881,8 @@ private ServerSnapshot(ServerEndPoint[] arr, int count)
_arr = arr; _arr = arr;
_count = count; _count = count;
} }
private ServerEndPoint[] _arr; private readonly ServerEndPoint[] _arr;
private int _count; private readonly int _count;
public ReadOnlySpan<ServerEndPoint> Span => new ReadOnlySpan<ServerEndPoint>(_arr, 0, _count); public ReadOnlySpan<ServerEndPoint> Span => new ReadOnlySpan<ServerEndPoint>(_arr, 0, _count);
internal ServerSnapshot Add(ServerEndPoint value) internal ServerSnapshot Add(ServerEndPoint value)
...@@ -1293,11 +1295,13 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text ...@@ -1293,11 +1295,13 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
{ {
if (configuration.ResolveDns && configuration.HasDnsEndPoints()) if (configuration.ResolveDns && configuration.HasDnsEndPoints())
{ {
var cts = new CancellationTokenSource();
var dns = configuration.ResolveEndPointsAsync(this, log).ObserveErrors(); var dns = configuration.ResolveEndPointsAsync(this, log).ObserveErrors();
if ((await Task.WhenAny(dns, Task.Delay(TimeoutMilliseconds)).ForAwait()) != dns) if ((await Task.WhenAny(dns, Task.Delay(TimeoutMilliseconds, cts.Token)).ForAwait()) != dns)
{ {
throw new TimeoutException("Timeout resolving endpoints"); throw new TimeoutException("Timeout resolving endpoints");
} }
cts.Cancel();
} }
foreach (var endpoint in configuration.EndPoints) foreach (var endpoint in configuration.EndPoints)
{ {
...@@ -2251,8 +2255,10 @@ public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None ...@@ -2251,8 +2255,10 @@ public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None
/// <summary> /// <summary>
/// Get the hash-slot associated with a given key, if applicable; this can be useful for grouping operations /// Get the hash-slot associated with a given key, if applicable; this can be useful for grouping operations
/// </summary> /// </summary>
/// <param name="key">The <see cref="RedisKey"/> to determine the hash slot for.</param>
public int GetHashSlot(RedisKey key) => ServerSelectionStrategy.HashSlot(key); public int GetHashSlot(RedisKey key) => ServerSelectionStrategy.HashSlot(key);
} }
internal enum WriteResult internal enum WriteResult
{ {
Success, Success,
......
...@@ -831,13 +831,13 @@ protected ICollection<object> ToInner(ICollection<object> args) ...@@ -831,13 +831,13 @@ protected ICollection<object> ToInner(ICollection<object> args)
foreach(var oldArg in args) foreach(var oldArg in args)
{ {
object newArg; object newArg;
if (oldArg is RedisKey) if (oldArg is RedisKey key)
{ {
newArg = ToInner((RedisKey)oldArg); newArg = ToInner(key);
} }
else if (oldArg is RedisChannel) else if (oldArg is RedisChannel channel)
{ {
newArg = ToInner((RedisChannel)oldArg); newArg = ToInner(channel);
} }
else else
{ {
......
...@@ -547,7 +547,7 @@ internal WriteResult WriteMessageTakingWriteLock(PhysicalConnection physical, Me ...@@ -547,7 +547,7 @@ internal WriteResult WriteMessageTakingWriteLock(PhysicalConnection physical, Me
{ {
result = WriteMessageToServerInsideWriteLock(physical, next); result = WriteMessageToServerInsideWriteLock(physical, next);
} }
physical.WakeWriterAndCheckForThrottle(); result = physical.WakeWriterAndCheckForThrottle();
} }
finally finally
{ {
......
...@@ -106,11 +106,12 @@ internal async void BeginConnectAsync(TextWriter log) ...@@ -106,11 +106,12 @@ internal async void BeginConnectAsync(TextWriter log)
RemoteEndPoint = endpoint, RemoteEndPoint = endpoint,
}; };
_socketArgs.Completed += SocketAwaitable.Callback; _socketArgs.Completed += SocketAwaitable.Callback;
CancellationTokenSource timeoutSource = null;
try try
{ {
if (_socket.ConnectAsync(_socketArgs)) if (_socket.ConnectAsync(_socketArgs))
{ // asynchronous operation is pending { // asynchronous operation is pending
ConfigureTimeout(_socketArgs, Multiplexer.RawConfig.ConnectTimeout); timeoutSource = ConfigureTimeout(_socketArgs, Multiplexer.RawConfig.ConnectTimeout);
} }
else else
{ // completed synchronously { // completed synchronously
...@@ -125,6 +126,7 @@ internal async void BeginConnectAsync(TextWriter log) ...@@ -125,6 +126,7 @@ internal async void BeginConnectAsync(TextWriter log)
if (ignoreConnect) return; if (ignoreConnect) return;
await awaitable; // wait for the connect to complete or fail (will throw) await awaitable; // wait for the connect to complete or fail (will throw)
timeoutSource?.Cancel();
if (await ConnectedAsync(_socket, log, Multiplexer.SocketManager).ForAwait()) if (await ConnectedAsync(_socket, log, Multiplexer.SocketManager).ForAwait())
{ {
...@@ -175,9 +177,10 @@ internal async void BeginConnectAsync(TextWriter log) ...@@ -175,9 +177,10 @@ internal async void BeginConnectAsync(TextWriter log)
} }
} }
private static void ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilliseconds) private static CancellationTokenSource ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilliseconds)
{ {
var timeout = Task.Delay(timeoutMilliseconds); var cts = new CancellationTokenSource();
var timeout = Task.Delay(timeoutMilliseconds, cts.Token);
timeout.ContinueWith((_, state) => timeout.ContinueWith((_, state) =>
{ {
try try
...@@ -190,6 +193,7 @@ private static void ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilli ...@@ -190,6 +193,7 @@ private static void ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilli
} }
catch { } catch { }
}, args); }, args);
return cts;
} }
private enum ReadMode : byte private enum ReadMode : byte
...@@ -720,17 +724,18 @@ internal static int WriteRaw(Span<byte> span, long value, bool withLengthPrefix ...@@ -720,17 +724,18 @@ internal static int WriteRaw(Span<byte> span, long value, bool withLengthPrefix
return WriteCrlf(span, offset); return WriteCrlf(span, offset);
} }
internal void WakeWriterAndCheckForThrottle() internal WriteResult WakeWriterAndCheckForThrottle()
{ {
try try
{ {
var flush = _ioPipe.Output.FlushAsync(); var flush = _ioPipe.Output.FlushAsync();
if (!flush.IsCompletedSuccessfully) flush.AsTask().Wait(); if (!flush.IsCompletedSuccessfully) flush.AsTask().Wait();
return WriteResult.Success;
} }
catch (ConnectionResetException ex) catch (ConnectionResetException ex)
{ {
RecordConnectionFailed(ConnectionFailureType.SocketClosed, ex); RecordConnectionFailed(ConnectionFailureType.SocketClosed, ex);
throw; return WriteResult.WriteFailure;
} }
} }
......
...@@ -2638,7 +2638,7 @@ private Message GetStreamAddMessage(RedisKey key, RedisValue messageId, int? max ...@@ -2638,7 +2638,7 @@ private Message GetStreamAddMessage(RedisKey key, RedisValue messageId, int? max
var offset = 0; var offset = 0;
values[offset++] = messageId; values[offset++] = messageId;
if (maxLength.HasValue) if (maxLength.HasValue)
{ {
values[offset++] = StreamConstants.MaxLen; values[offset++] = StreamConstants.MaxLen;
...@@ -3060,7 +3060,7 @@ public long SortedSetLengthByValue(RedisKey key, RedisValue min, RedisValue max, ...@@ -3060,7 +3060,7 @@ public long SortedSetLengthByValue(RedisKey key, RedisValue min, RedisValue max,
public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags) public RedisValue[] SortedSetRangeByValue(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
=> SortedSetRangeByValue(key, min, max, exclude, Order.Ascending, skip, take, flags); => SortedSetRangeByValue(key, min, max, exclude, Order.Ascending, skip, take, flags);
static void ReverseLimits(Order order, ref Exclude exclude, ref RedisValue start, ref RedisValue stop) private static void ReverseLimits(Order order, ref Exclude exclude, ref RedisValue start, ref RedisValue stop)
{ {
bool reverseLimits = (order == Order.Ascending) == start.CompareTo(stop) > 0; bool reverseLimits = (order == Order.Ascending) == start.CompareTo(stop) > 0;
if (reverseLimits) if (reverseLimits)
...@@ -3097,6 +3097,7 @@ public Task<long> SortedSetLengthByValueAsync(RedisKey key, RedisValue min, Redi ...@@ -3097,6 +3097,7 @@ public Task<long> SortedSetLengthByValueAsync(RedisKey key, RedisValue min, Redi
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags) public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min, RedisValue max, Exclude exclude, long skip, long take, CommandFlags flags)
=> SortedSetRangeByValueAsync(key, min, max, exclude, Order.Ascending, skip, take, flags); => SortedSetRangeByValueAsync(key, min, max, exclude, Order.Ascending, skip, take, flags);
public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue), public Task<RedisValue[]> SortedSetRangeByValueAsync(RedisKey key, RedisValue min = default(RedisValue), RedisValue max = default(RedisValue),
Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None) Exclude exclude = Exclude.None, Order order = Order.Ascending, long skip = 0, long take = -1, CommandFlags flags = CommandFlags.None)
{ {
...@@ -3124,7 +3125,7 @@ internal class ScanIterator<T> : CursorEnumerable<T> ...@@ -3124,7 +3125,7 @@ internal class ScanIterator<T> : CursorEnumerable<T>
this.key = key; this.key = key;
this.pattern = pattern; this.pattern = pattern;
this.command = command; this.command = command;
this.Processor = processor; Processor = processor;
} }
protected override ResultProcessor<CursorEnumerable<T>.ScanResult> Processor { get; } protected override ResultProcessor<CursorEnumerable<T>.ScanResult> Processor { get; }
...@@ -3222,13 +3223,13 @@ protected override void WriteImpl(PhysicalConnection physical) ...@@ -3222,13 +3223,13 @@ protected override void WriteImpl(PhysicalConnection physical)
physical.WriteHeader(_command, args.Count); physical.WriteHeader(_command, args.Count);
foreach (object arg in args) foreach (object arg in args)
{ {
if (arg is RedisKey) if (arg is RedisKey key)
{ {
physical.Write((RedisKey)arg); physical.Write(key);
} }
else if (arg is RedisChannel) else if (arg is RedisChannel channel)
{ {
physical.Write((RedisChannel)arg); physical.Write(channel);
} }
else else
{ // recognises well-known types { // recognises well-known types
...@@ -3246,9 +3247,9 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) ...@@ -3246,9 +3247,9 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
int slot = ServerSelectionStrategy.NoSlot; int slot = ServerSelectionStrategy.NoSlot;
foreach (object arg in args) foreach (object arg in args)
{ {
if (arg is RedisKey) if (arg is RedisKey key)
{ {
slot = serverSelectionStrategy.CombineSlot(slot, (RedisKey)arg); slot = serverSelectionStrategy.CombineSlot(slot, key);
} }
} }
return slot; return slot;
...@@ -3260,7 +3261,9 @@ private sealed class ScriptEvalMessage : Message, IMultiMessage ...@@ -3260,7 +3261,9 @@ private sealed class ScriptEvalMessage : Message, IMultiMessage
private readonly RedisKey[] keys; private readonly RedisKey[] keys;
private readonly string script; private readonly string script;
private readonly RedisValue[] values; private readonly RedisValue[] values;
private byte[] asciiHash, hexHash; private byte[] asciiHash;
private readonly byte[] hexHash;
public ScriptEvalMessage(int db, CommandFlags flags, string script, RedisKey[] keys, RedisValue[] values) public ScriptEvalMessage(int db, CommandFlags flags, string script, RedisKey[] keys, RedisValue[] values)
: this(db, flags, ResultProcessor.ScriptLoadProcessor.IsSHA1(script) ? RedisCommand.EVALSHA : RedisCommand.EVAL, script, null, keys, values) : this(db, flags, ResultProcessor.ScriptLoadProcessor.IsSHA1(script) ? RedisCommand.EVALSHA : RedisCommand.EVAL, script, null, keys, values)
{ {
......
...@@ -179,7 +179,7 @@ private class TransactionMessage : Message, IMultiMessage ...@@ -179,7 +179,7 @@ private class TransactionMessage : Message, IMultiMessage
public TransactionMessage(int db, CommandFlags flags, List<ConditionResult> conditions, List<QueuedMessage> operations) public TransactionMessage(int db, CommandFlags flags, List<ConditionResult> conditions, List<QueuedMessage> operations)
: base(db, flags, RedisCommand.EXEC) : base(db, flags, RedisCommand.EXEC)
{ {
this.InnerOperations = (operations == null || operations.Count == 0) ? Array.Empty<QueuedMessage>() : operations.ToArray(); InnerOperations = (operations == null || operations.Count == 0) ? Array.Empty<QueuedMessage>() : operations.ToArray();
this.conditions = (conditions == null || conditions.Count == 0) ? Array.Empty<ConditionResult>(): conditions.ToArray(); this.conditions = (conditions == null || conditions.Count == 0) ? Array.Empty<ConditionResult>(): conditions.ToArray();
} }
......
...@@ -644,7 +644,9 @@ private static string ToHex(ReadOnlySpan<byte> src) ...@@ -644,7 +644,9 @@ private static string ToHex(ReadOnlySpan<byte> src)
if (MemoryMarshal.TryGetArray(value._memory, out var segment) if (MemoryMarshal.TryGetArray(value._memory, out var segment)
&& segment.Offset == 0 && segment.Offset == 0
&& segment.Count == (segment.Array?.Length ?? -1)) && segment.Count == (segment.Array?.Length ?? -1))
{
return segment.Array; // the memory is backed by an array, and we're reading all of it return segment.Array; // the memory is backed by an array, and we're reading all of it
}
return value._memory.ToArray(); return value._memory.ToArray();
case StorageType.Int64: case StorageType.Int64:
...@@ -738,8 +740,7 @@ private RedisValue Simplify() ...@@ -738,8 +740,7 @@ private RedisValue Simplify()
case StorageType.Double: case StorageType.Double:
// is the double actually an integer? // is the double actually an integer?
f64 = OverlappedValueDouble; f64 = OverlappedValueDouble;
if (f64 >= long.MinValue && f64 <= long.MaxValue if (f64 >= long.MinValue && f64 <= long.MaxValue && (i64 = (long)f64) == f64) return i64;
&& (i64 = (long)f64) == f64) return i64;
break; break;
} }
return this; return this;
...@@ -749,6 +750,7 @@ private RedisValue Simplify() ...@@ -749,6 +750,7 @@ private RedisValue Simplify()
/// Create a RedisValue from a MemoryStream; it will *attempt* to use the internal buffer /// Create a RedisValue from a MemoryStream; it will *attempt* to use the internal buffer
/// directly, but if this isn't possibly it will fallback to ToArray /// directly, but if this isn't possibly it will fallback to ToArray
/// </summary> /// </summary>
/// <param name="stream">The <see cref="MemoryStream"/> to create a value from.</param>
public static RedisValue CreateFrom(MemoryStream stream) public static RedisValue CreateFrom(MemoryStream stream)
{ {
if (stream == null) return Null; if (stream == null) return Null;
...@@ -764,28 +766,28 @@ public static RedisValue CreateFrom(MemoryStream stream) ...@@ -764,28 +766,28 @@ public static RedisValue CreateFrom(MemoryStream stream)
} }
} }
/// <summary> /// <summary>
/// Indicates whether the current value has the supplied value as a prefix /// Indicates whether the current value has the supplied value as a prefix.
/// </summary> /// </summary>
/// <param name="value">The <see cref="RedisValue"/> to check.</param>
public bool StartsWith(RedisValue value) public bool StartsWith(RedisValue value)
{ {
if (this.IsNull || value.IsNull) return false; if (IsNull || value.IsNull) return false;
if (value.IsNullOrEmpty) return true; if (value.IsNullOrEmpty) return true;
if (this.IsNullOrEmpty) return false; if (IsNullOrEmpty) return false;
ReadOnlyMemory<byte> rawThis, rawOther; ReadOnlyMemory<byte> rawThis, rawOther;
var thisType = this.Type; var thisType = Type;
if (thisType == value.Type) // same? can often optimize if (thisType == value.Type) // same? can often optimize
{ {
switch(thisType) switch(thisType)
{ {
case StorageType.String: case StorageType.String:
var sThis = ((string)this._objectOrSentinel); var sThis = ((string)_objectOrSentinel);
var sOther = ((string)value._objectOrSentinel); var sOther = ((string)value._objectOrSentinel);
return sThis.StartsWith(sOther, StringComparison.Ordinal); return sThis.StartsWith(sOther, StringComparison.Ordinal);
case StorageType.Raw: case StorageType.Raw:
rawThis = this._memory; rawThis = _memory;
rawOther = value._memory; rawOther = value._memory;
return rawThis.Span.StartsWith(rawOther.Span); return rawThis.Span.StartsWith(rawOther.Span);
} }
...@@ -793,7 +795,7 @@ public bool StartsWith(RedisValue value) ...@@ -793,7 +795,7 @@ public bool StartsWith(RedisValue value)
byte[] arr0 = null, arr1 = null; byte[] arr0 = null, arr1 = null;
try try
{ {
rawThis = this.AsMemory(out arr0); rawThis = AsMemory(out arr0);
rawOther = value.AsMemory(out arr1); rawOther = value.AsMemory(out arr1);
return rawThis.Span.StartsWith(rawOther.Span); return rawThis.Span.StartsWith(rawOther.Span);
...@@ -830,7 +832,6 @@ private ReadOnlyMemory<byte> AsMemory(out byte[] leased) ...@@ -830,7 +832,6 @@ private ReadOnlyMemory<byte> AsMemory(out byte[] leased)
leased = ArrayPool<byte>.Shared.Rent(PhysicalConnection.MaxInt64TextLen + 2); // reused code has CRLF terminator leased = ArrayPool<byte>.Shared.Rent(PhysicalConnection.MaxInt64TextLen + 2); // reused code has CRLF terminator
len = PhysicalConnection.WriteRaw(leased, _overlappedValue64) - 2; // drop the CRLF len = PhysicalConnection.WriteRaw(leased, _overlappedValue64) - 2; // drop the CRLF
return new ReadOnlyMemory<byte>(leased, 0, len); return new ReadOnlyMemory<byte>(leased, 0, len);
} }
leased = null; leased = null;
return default; return default;
......
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