Skip to content

Commit b959508

Browse files
committed
Avoid error for Redis.
1 parent ac78e6d commit b959508

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<LangVersion>12.0</LangVersion>
5-
<BotSharpVersion>3.0.0</BotSharpVersion>
5+
<BotSharpVersion>4.0.0</BotSharpVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<GenerateDocumentationFile>false</GenerateDocumentationFile>
88
</PropertyGroup>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ It's written in C# running on .Net Core that is full cross-platform framework, t
2323
* Built-in multi-agents and conversation with state management.
2424
* Support multiple LLM Planning approaches to handle different tasks from simple to complex.
2525
* Built-in RAG related interfaces, Memory based vector searching.
26-
* Support multiple AI platforms (ChatGPT 3.5 / 4.0, PaLM 2, LLaMA 3, Claude Sonnet 3.5, HuggingFace).
26+
* Support multiple AI platforms (ChatGPT 3.5/ 4o/ o1, Gemini 2, LLaMA 3, Claude Sonnet 3.5, HuggingFace).
2727
* Allow multiple agents with different responsibilities cooperate to complete complex tasks.
2828
* Build, test, evaluate and audit your LLM agent in one place.
2929
* Build-in `BotSharp UI` written in [SvelteKit](https://kit.svelte.dev/).

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ private static void AddRedisEvents(IServiceCollection services, IConfiguration c
105105
var dbSettings = new BotSharpDatabaseSettings();
106106
config.Bind("Database", dbSettings);
107107

108+
if (string.IsNullOrEmpty(dbSettings.Redis))
109+
{
110+
return;
111+
}
112+
108113
services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect(dbSettings.Redis));
109114
services.AddSingleton<IEventPublisher, RedisPublisher>();
110115
services.AddSingleton<IEventSubscriber, RedisSubscriber>();

src/Infrastructure/BotSharp.Core/Infrastructures/DistributedLocker.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ namespace BotSharp.Core.Infrastructures;
66

77
public class DistributedLocker : IDistributedLocker
88
{
9-
private readonly IConnectionMultiplexer _redis;
9+
private readonly IServiceProvider _services;
1010
private readonly ILogger _logger;
1111

12-
public DistributedLocker(IConnectionMultiplexer redis, ILogger<DistributedLocker> logger)
12+
public DistributedLocker(IServiceProvider services, ILogger<DistributedLocker> logger)
1313
{
14-
_redis = redis;
14+
_services = services;
1515
_logger = logger;
1616
}
1717

1818
public async Task<bool> LockAsync(string resource, Func<Task> action, int timeoutInSeconds = 30)
1919
{
2020
var timeout = TimeSpan.FromSeconds(timeoutInSeconds);
2121

22-
var @lock = new RedisDistributedLock(resource, _redis.GetDatabase());
22+
var redis = _services.GetRequiredService<IConnectionMultiplexer>();
23+
var @lock = new RedisDistributedLock(resource, redis.GetDatabase());
2324
await using (var handle = await @lock.TryAcquireAsync(timeout))
2425
{
2526
if (handle == null)
@@ -37,7 +38,8 @@ public bool Lock(string resource, Action action, int timeoutInSeconds = 30)
3738
{
3839
var timeout = TimeSpan.FromSeconds(timeoutInSeconds);
3940

40-
var @lock = new RedisDistributedLock(resource, _redis.GetDatabase());
41+
var redis = _services.GetRequiredService<IConnectionMultiplexer>();
42+
var @lock = new RedisDistributedLock(resource, redis.GetDatabase());
4143
using (var handle = @lock.TryAcquire(timeout))
4244
{
4345
if (handle == null)

0 commit comments

Comments
 (0)