47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
|
|
using FreeRedis;
|
|||
|
|
using JetBrains.Annotations;
|
|||
|
|
using JiShe.CollectBus.FreeRedisProvider.Options;
|
|||
|
|
using Microsoft.Extensions.Options;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Volo.Abp.DependencyInjection;
|
|||
|
|
|
|||
|
|
namespace JiShe.CollectBus.FreeRedisProvider
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public class FreeRedisProvider : IFreeRedisProvider, ISingletonDependency
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
private readonly FreeRedisOptions _option;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// FreeRedis
|
|||
|
|
/// </summary>
|
|||
|
|
public FreeRedisProvider(IOptions<FreeRedisOptions> options)
|
|||
|
|
{
|
|||
|
|
_option = options.Value;
|
|||
|
|
GetInstance();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public RedisClient Instance { get; set; } = new (string.Empty);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取 FreeRedis 客户端
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public IRedisClient GetInstance()
|
|||
|
|
{
|
|||
|
|
var connectionString = $"{_option.Configuration},defaultdatabase={_option.DefaultDB}";
|
|||
|
|
Instance = new RedisClient(connectionString);
|
|||
|
|
Instance.Serialize = obj => JsonSerializer.Serialize(obj);
|
|||
|
|
Instance.Deserialize = (json, type) => JsonSerializer.Deserialize(json, type);
|
|||
|
|
Instance.Notice += (s, e) => Trace.WriteLine(e.Log);
|
|||
|
|
return Instance;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|