配置文件更改

This commit is contained in:
陈淳
2022-10-26 20:01:18 +08:00
parent fd9f3d04d9
commit 3a634d7888
11 changed files with 577 additions and 248 deletions

View File

@@ -9,34 +9,16 @@ using System.Threading.Tasks;
using System.IO;
using Yi.Framework.Common.IOCOptions;
using CSRedis;
using static CSRedis.CSRedisClient;
namespace Yi.Framework.Core
{
public abstract class CacheInvoker
{
private readonly RedisConnOptions _RedisOptions;
protected CacheInvoker Client { get; set; }
public CacheInvoker Db { get { return Client; } set { } }
public CacheInvoker(IOptionsMonitor<RedisConnOptions> redisConnOptions)
public virtual bool Exits(string key)
{
}
public virtual bool Exit(string key)
{
throw new NotImplementedException();
}
public virtual long Remove(string key)
{
throw new NotImplementedException();
}
public virtual long HRemove(string key, params string[] par)
{
throw new NotImplementedException();
throw new NotImplementedException();
}
public virtual T Get<T>(string key)
{
@@ -52,27 +34,120 @@ namespace Yi.Framework.Core
{
throw new NotImplementedException();
}
public virtual T QueuePop<T>(string key)
{
throw new NotImplementedException();
}
public virtual long QueuePush<T>(string key, T data)
{
throw new NotImplementedException();
}
public virtual long QueueLen(string key)
public virtual long Del(string key)
{
throw new NotImplementedException();
}
public virtual bool HSet<T>(string key, string fieId, T data)
{
throw new NotImplementedException();
}
public virtual bool HSet<T>(string key, string fieId, T data, TimeSpan time)
public virtual bool HSet(string key, string fieId, object data)
{
throw new NotImplementedException();
}
public virtual bool HSet(string key, string fieId, object data, TimeSpan time)
{
throw new NotImplementedException();
}
public virtual T HGet<T>(string key, string field)
{
throw new NotImplementedException();
}
public virtual long HDel(string key, params string[] par)
{
throw new NotImplementedException();
}
public virtual long HLen(string key)
{
throw new NotImplementedException();
}
public virtual Dictionary<string, string> HGetAll(string key)
{
throw new NotImplementedException();
}
/// <summary>
/// 简单发布
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
/// <returns></returns>
public virtual long Publish(string channel, string message)
{
throw new NotImplementedException();
}
/// <summary>
/// 简单订阅广播无持久化需要Publish写入队列
/// </summary>
/// <param name="channels"></param>
/// <returns></returns>
public virtual SubscribeObject Subscribe(params (string, Action<SubscribeMessageEventArgs>)[] channels)
{
throw new NotImplementedException();
}
/// <summary>
/// 多端争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public virtual SubscribeListObject SubscribeList(string listKey, Action<string> onMessage)
{
throw new NotImplementedException();
}
/// <summary>
/// 多端非争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="clientId"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public virtual SubscribeListBroadcastObject SubscribeListBroadcast(string listKey, string clientId, Action<string> onMessage)
{
throw new NotImplementedException();
}
public virtual bool LSet(string key, long index, object value)
{
throw new NotImplementedException();
}
/// <summary>
/// 列表插入头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public virtual long LPush<T>(string key, params T[] value)
{
throw new NotImplementedException();
}
/// <summary>
/// 列表弹出头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public virtual T LPop<T>(string key)
{
throw new NotImplementedException();
}
public virtual string[] Keys(string pattern)
{
throw new NotImplementedException();
}
}
}

View File

@@ -9,12 +9,16 @@ using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.Core.Cache
{
public class MemoryCacheClient: CacheInvoker
public class MemoryCacheClient : CacheInvoker
{
private IMemoryCache _client;
public MemoryCacheClient(IOptionsMonitor<RedisConnOptions> redisConnOptions):base(redisConnOptions)
public MemoryCacheClient()
{
_client = new MemoryCache(new MemoryCacheOptions() { });
_client = new MemoryCache(new MemoryCacheOptions());
}
public override bool Exits(string key)
{
return _client.TryGetValue(key, out var _);
}
public override T Get<T>(string key)
{
@@ -29,5 +33,11 @@ namespace Yi.Framework.Core.Cache
{
return _client.Set(key, item, time) is not null;
}
public override long Del(string key)
{
_client.Remove(key);
return 1;
}
}
}

View File

@@ -0,0 +1,164 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Yi.Framework.Common.IOCOptions;
using CSRedis;
using static CSRedis.CSRedisClient;
namespace Yi.Framework.Core.Cache
{
public class RedisCacheClient : CacheInvoker
{
private readonly RedisConnOptions _RedisOptions;
private CSRedisClient _client;
public RedisCacheClient(IOptionsMonitor<RedisConnOptions> redisConnOptions)
{
this._RedisOptions = redisConnOptions.CurrentValue;
_client = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={ _RedisOptions.DB }");
}
public override bool Exits(string key)
{
return _client.Exists(key);
}
public override T Get<T>(string key)
{
return _client.Get<T>(key);
}
public override bool Set<T>(string key, T data, TimeSpan time)
{
return _client.Set(key, data, time);
}
public override bool Set<T>(string key, T data)
{
return _client.Set(key, data);
}
public override long Del(string key)
{
return _client.Del(key);
}
public override bool HSet(string key, string fieId, object data)
{
return _client.HSet(key, fieId, data);
}
public override bool HSet(string key, string fieId, object data, TimeSpan time)
{
var res = _client.HSet(key, fieId, data);
var res2 = _client.Expire(key, time);
return res && res2;
}
public override T HGet<T>(string key, string field)
{
return _client.HGet<T>(key, field);
}
public override long HDel(string key, params string[] par)
{
return _client.HDel(key, par);
}
public override long HLen(string key)
{
return _client.HLen(key);
}
public override Dictionary<string, string> HGetAll(string key)
{
return _client.HGetAll(key);
}
/// <summary>
/// 简单发布
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
/// <returns></returns>
public override long Publish(string channel, string message)
{
return _client.Publish(channel, message);
}
/// <summary>
/// 简单订阅广播无持久化需要Publish写入队列
/// </summary>
/// <param name="channels"></param>
/// <returns></returns>
public override SubscribeObject Subscribe(params (string, Action<SubscribeMessageEventArgs>)[] channels)
{
return _client.Subscribe(channels);
}
/// <summary>
/// 多端争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public override SubscribeListObject SubscribeList(string listKey, Action<string> onMessage)
{
return _client.SubscribeList(listKey, onMessage);
}
/// <summary>
/// 多端非争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="clientId"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public override SubscribeListBroadcastObject SubscribeListBroadcast(string listKey, string clientId, Action<string> onMessage)
{
return _client.SubscribeListBroadcast(listKey, clientId, onMessage);
}
public override bool LSet(string key, long index, object value)
{
return _client.LSet(key, index, value);
}
/// <summary>
/// 列表插入头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public override long LPush<T>(string key, params T[] value)
{
return _client.LPush<T>(key,value);
}
/// <summary>
/// 列表弹出头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public override T LPop<T>(string key)
{
return _client.LPop<T>(key);
}
public override string[] Keys(string pattern)
{
return _client.Keys(pattern);
}
}
}

View File

@@ -1,42 +0,0 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Yi.Framework.Common.IOCOptions;
using CSRedis;
namespace Yi.Framework.Core
{
public class RedisClient: CacheInvoker
{
private readonly RedisConnOptions _RedisOptions;
private CSRedisClient _client;
public RedisClient(IOptionsMonitor<RedisConnOptions> redisConnOptions):base(redisConnOptions)
{
this._RedisOptions = redisConnOptions.CurrentValue;
_client = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={ _RedisOptions.DB }");
}
public override T Get<T>(string key)
{
return _client.Get<T>(key);
}
public override bool Set<T>(string key, T data, TimeSpan time)
{
return _client.Set(key, data, time);
}
public override bool Set<T>(string key, T data)
{
return _client.Set(key, data);
}
}
}