public async Task PublishTests(object value) { var connection = ConfigurationHelper.GetNewConnection(); var library = new MemoScriptLibrary(connection); var db = connection.GetDatabase(); var root = Guid.NewGuid().ToString().Substring(0, 8); var key = new MemoKey(root, "key", TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); var parameters = new MemoSetValueParameters(key, RedisValue.Unbox(value)); try { await ResetKeys(db, parameters); var message = RedisValue.Null; await connection.GetSubscriber().SubscribeAsync(parameters.MemoChannelKey, (c, v) => message = v); await library.PublishAsync(parameters); await Task.Delay(500); var expectedValue = value == null ? RedisValue.EmptyString : RedisValue.Unbox(value); Assert.Equal(expectedValue, message); Assert.Equal(expectedValue, await db.StringGetAsync(parameters.MemoKey)); } finally { await ResetKeys(db, parameters); } }
public async Task SubscribeTests() { var connection = ConfigurationHelper.GetNewConnection(); var library = new MemoScriptLibrary(connection); var db = connection.GetDatabase(); var timeout = 500; var root = Guid.NewGuid().ToString().Substring(0, 8); var key = new MemoKey(root, "key", TimeSpan.FromMilliseconds(timeout), TimeSpan.FromSeconds(1)); var result = false; await library.SubscribeAsync(key.GetSubscribtionChannel(), (c, v) => result = true); await db.PublishAsync(key.GetValueChannel(), "identifier"); await Task.Delay(30); Assert.True(result); }