bug处理,二楼空载具料架入库
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Tnb.Common.Redis
|
||||
{
|
||||
public class RedisData : ISingleton
|
||||
{
|
||||
private static CSRedisClient _instance;
|
||||
private CSRedisClient _instance;
|
||||
public delegate void rcvMsgHandler(string Channel, string Body);
|
||||
public event rcvMsgHandler rcvMsg;
|
||||
public RedisData()
|
||||
@@ -25,14 +25,14 @@ namespace Tnb.Common.Redis
|
||||
RedisOptions _RedisOptions = App.GetConfig<RedisOptions>("Redis", true);
|
||||
_instance = new CSRedis.CSRedisClient(string.Format(_RedisOptions.RedisConnectionString, _RedisOptions.ip, _RedisOptions.port, _RedisOptions.password));
|
||||
|
||||
_instance.Subscribe(("devdata_change", msg =>
|
||||
{
|
||||
if (rcvMsg != null)
|
||||
{
|
||||
rcvMsg(msg.Channel, msg.Body);
|
||||
}
|
||||
}
|
||||
));
|
||||
//_instance.Subscribe(("devdata_change", msg =>
|
||||
//{
|
||||
// if (rcvMsg != null)
|
||||
// {
|
||||
// rcvMsg(msg.Channel, msg.Body);
|
||||
// }
|
||||
//}
|
||||
//));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
88
common/Tnb.Common/Redis/StackExRedisHelper.cs
Normal file
88
common/Tnb.Common/Redis/StackExRedisHelper.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
using JNPF;
|
||||
using JNPF.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
using Spire.Xls.Core;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.Common.Redis
|
||||
{
|
||||
public class StackExRedisHelper : ISingleton
|
||||
{
|
||||
private ConnectionMultiplexer _redis;
|
||||
private IDatabase _db;
|
||||
|
||||
// 初始化 Redis 连接
|
||||
public StackExRedisHelper()
|
||||
{
|
||||
RedisOptions _RedisOptions = App.GetConfig<RedisOptions>("Redis", true);
|
||||
_redis = ConnectionMultiplexer.Connect($"{_RedisOptions.ip}:{_RedisOptions.port},password={_RedisOptions.password}");
|
||||
_db = _redis.GetDatabase();
|
||||
}
|
||||
|
||||
// 存储字符串值
|
||||
public void SetString(string key, string value)
|
||||
{
|
||||
_db.StringSet(key, value);
|
||||
}
|
||||
|
||||
// 获取字符串值
|
||||
public string GetString(string key)
|
||||
{
|
||||
return _db.StringGet(key);
|
||||
}
|
||||
|
||||
// 存储哈希值
|
||||
public void SetHash(string key, string field, string value)
|
||||
{
|
||||
_db.HashSet(key, field, value);
|
||||
}
|
||||
|
||||
// 获取哈希值
|
||||
public string GetHash(string key, string field)
|
||||
{
|
||||
return _db.HashGet(key, field);
|
||||
}
|
||||
|
||||
// 存储列表值
|
||||
public void ListRightPush(string key, string value)
|
||||
{
|
||||
_db.ListRightPush(key, value);
|
||||
}
|
||||
|
||||
// 关闭 Redis 连接
|
||||
public void Close()
|
||||
{
|
||||
if (_redis != null && _redis.IsConnected)
|
||||
{
|
||||
_redis.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T> TryGetValueByKeyField<T>(string key, string field)
|
||||
{
|
||||
if (_db.HashExists(key, field))
|
||||
{
|
||||
string data = GetHash(key, field);
|
||||
Dictionary<String, String> json = JsonConvert.DeserializeObject<Dictionary<String, String>>(data);
|
||||
Type type = typeof(T);
|
||||
if ((!type.IsValueType && type.GetGenericArguments().Length > 0) || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
{
|
||||
return (T)Convert.ChangeType(json["Value"], type.GetGenericArguments()[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T)Convert.ChangeType(json["Value"], type);
|
||||
}
|
||||
// return ;
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<GenerateDocumentationFile>False</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8618;CS8619;CS8625;CS1572;CS1573;</NoWarn>
|
||||
<Configurations>Debug;Release;tianyi</Configurations>
|
||||
<ServerGarbageCollection>false</ServerGarbageCollection>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -17,6 +18,7 @@
|
||||
<PackageReference Include="CSRedisCore" Version="3.8.3" />
|
||||
<PackageReference Include="FreeSpire.Office" Version="4.3.1" />
|
||||
<PackageReference Include="NPOI" Version="2.5.5" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.7.33" />
|
||||
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
|
||||
<PackageReference Include="System.Management" Version="6.0.0" />
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
|
||||
Reference in New Issue
Block a user