This commit is contained in:
Haiping Chen 2024-11-26 05:56:10 +00:00
parent 6a21158594
commit a336cc9dc5
3 changed files with 7 additions and 3 deletions

View file

@ -10,7 +10,7 @@ public interface IEventPublisher
/// <returns></returns>
Task BroadcastAsync(string channel, string message);
Task PublishAsync(string channel, string message, EventPriority? priority = null);
Task<string?> PublishAsync(string channel, string message, EventPriority? priority = null);
Task ReDispatchAsync(string channel, int count = 10, string order = "asc");

View file

@ -1,7 +1,9 @@
using BotSharp.Abstraction.Infrastructures;
using System.Diagnostics;
namespace BotSharp.Abstraction.Utilities;
[DebuggerStepThrough]
public class Pagination : ICacheKey
{
private int _page;

View file

@ -21,7 +21,7 @@ public class RedisPublisher : IEventPublisher
await _subscriber.PublishAsync(channel, message);
}
public async Task PublishAsync(string channel, string message, EventPriority? priority = null)
public async Task<string?> PublishAsync(string channel, string message, EventPriority? priority = null)
{
var db = _redis.GetDatabase();
@ -34,7 +34,7 @@ public class RedisPublisher : IEventPublisher
if (CheckMessageExists(db, channel, "message", message))
{
_logger.LogError($"The message already exists {channel} {message}");
return;
return null;
}
// Add a message to the stream, keeping only the latest 1 million messages
@ -46,6 +46,8 @@ public class RedisPublisher : IEventPublisher
maxLength: 1000 * 10000);
_logger.LogInformation($"Published message {channel} {message} ({messageId})");
return messageId;
}
private bool CheckMessageExists(IDatabase db, string channel, string fieldName, string desiredValue)