42 lines
1.3 KiB
C#
Raw Normal View History

2025-04-17 20:28:50 +08:00
using System.Diagnostics;
using FreeRedis;
2025-04-15 16:05:07 +08:00
using JiShe.CollectBus.Common.Helpers;
2025-04-17 20:28:50 +08:00
using JiShe.CollectBus.FreeRedis.Options;
2025-03-17 08:35:19 +08:00
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
2025-04-17 20:28:50 +08:00
namespace JiShe.CollectBus.FreeRedis
2025-03-17 08:35:19 +08:00
{
public class FreeRedisProvider : IFreeRedisProvider, ISingletonDependency
{
private readonly FreeRedisOptions _option;
/// <summary>
/// FreeRedis
/// </summary>
public FreeRedisProvider(IOptions<FreeRedisOptions> options)
{
_option = options.Value;
GetInstance();
}
2025-04-15 15:49:51 +08:00
public RedisClient Instance { get; set; } = new(string.Empty);
2025-03-17 08:35:19 +08:00
/// <summary>
/// 获取 FreeRedis 客户端
/// </summary>
/// <returns></returns>
public IRedisClient GetInstance()
{
2025-04-15 15:49:51 +08:00
2025-04-16 17:36:46 +08:00
var connectionString = $"{_option.Configuration},defaultdatabase={_option.DefaultDB},MaxPoolSize={_option.MaxPoolSize}";
2025-03-17 08:35:19 +08:00
Instance = new RedisClient(connectionString);
Instance.Serialize = obj => BusJsonSerializer.Serialize(obj);
Instance.Deserialize = (json, type) => BusJsonSerializer.Deserialize(json, type);
2025-04-16 17:36:46 +08:00
Instance.Notice += (s, e) => Trace.WriteLine(e.Log);
2025-03-17 08:35:19 +08:00
return Instance;
}
2025-03-17 08:35:19 +08:00
}
}