public (bool sent, bool clients) TrySendMessage(string parentPipeName, string childPipeName, object body, int maxListLength = int.MaxValue, TimeSpan?expiry = null) { if (body == null) { throw new ArgumentNullException(nameof(body)); } //will throw ArgumentException is body is not a supported type var redisValue = RedisValue.Unbox(body); var db = _redis.GetDatabase(); var parentInfoPath = CreateParentChildSetPath(parentPipeName); var childPipePath = PipeInfo.Create(parentPipeName, childPipeName); var trans = db.CreateTransaction(); { if (maxListLength < int.MaxValue) { trans.AddCondition(Condition.ListLengthLessThan(childPipePath.PipePath, maxListLength)); } //ensure the name of the new pipe exists for the pipe monitor (before checking list length) db.SetAdd(RedisTaskMultiplexorConstants.PipeNameSetKey, parentPipeName); //add the child to the parents hash set (and update the expiry time on it) db.HashSet(parentInfoPath, childPipeName, DateConverters.ExpiryToTimeString(expiry ?? TimeSpan.FromDays(7))); //add the message to the left of the list, and is later popped from the right. db.ListLeftPush(childPipePath.PipePath, redisValue); } var executed = trans.Execute(); if (!executed) { return(false, false); } var sub = _redis.GetSubscriber(); var listeners = sub.Publish(childPipePath.BroadcastPath, $"{{\"type\":\"new\",\"parent\":\"{parentPipeName}\",\"child\":\"{childPipeName}\"}}"); return(true, listeners > 0); }
public static RedisValue MakeBatchInfo(TimeSpan expiry, string pipePath) { return($"{DateConverters.ExpiryToTimeString(expiry)}|{pipePath}"); }