新增Redis方法

This commit is contained in:
2025-12-20 15:35:14 +08:00
parent 48d3dbdcb7
commit 67f9192182
4 changed files with 61 additions and 9 deletions

View File

@@ -13,19 +13,15 @@ namespace Common
/// </summary>
public class CSRedisCacheHelper
{
public static CSRedisClient? redis;
public static CSRedisClient? redis1;
private const string ip = "10.8.8.208";
//private const string port = "6379";
private const string port = "10079";
public static CSRedisClient redis;
private const string ip = "localhost";
private const string port = "26379";
static CSRedisCacheHelper()
{
var redisHostStr = string.Format("{0}:{1}", ip, port);
if (!string.IsNullOrEmpty(redisHostStr))
{
redis = new CSRedisClient(redisHostStr + ",password=blw@redis-ser@123,defaultDatabase=0");
redis1 = new CSRedisClient(redisHostStr + ",password=blw@redis-ser@123,defaultDatabase=1");
redis = new CSRedisClient(redisHostStr + ",password=1001^_^lool,defaultDatabase=0");
var DingYueMsg = ("CellCorelDRAWUser", new Action<SubscribeMessageEventArgs>(async (args) =>
{
string body = args.Body;
@@ -91,5 +87,44 @@ namespace Common
{
return CSRedisCacheHelper.redis.BRPop<T>(3,Key);
}
/// <summary>
/// 添加Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void HMSet(string key, params object[] value)
{
redis.HMSet(key, value);
}
public static void HMSet(int ExpireTime_M, string key, params object[] value)
{
redis.HMSet(key, value);
redis.Expire(key, new TimeSpan(0, ExpireTime_M, 0));
}
/// <summary>
/// 获取Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static T[] HMGet<T>(string key, string KeyV)
{
return redis.HMGet<T>(key, KeyV);
}
/// <summary>
/// Example
/// WXFault_酒店编号_房间号
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static Dictionary<string, string> HMGetAll(string key)
{
return redis.HGetAll(key);
}
}
}

View File

@@ -1,4 +1,5 @@
using Models;
using Common;
using Models;
using Models.ModelItems;
using Models.View;
using Newtonsoft.Json;
@@ -1589,6 +1590,14 @@ namespace UI.Controllers
return ri;
}
public void A()
{
string code = "";
string roonumber = "";
string a = $"WXFault_{code}_{roonumber}";
CSRedisCacheHelper.HMGetAll("'");
}

View File

@@ -50,6 +50,9 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="CSRedisCore, Version=3.8.807.0, Culture=neutral, PublicKeyToken=9aa6a3079358d437, processorArchitecture=MSIL">
<HintPath>..\packages\CSRedisCore.3.8.807\lib\net45\CSRedisCore.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
@@ -117,6 +120,9 @@
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />

View File

@@ -3,6 +3,7 @@
<package id="Antlr" version="3.5.0.2" targetFramework="net461" />
<package id="bootstrap" version="3.3.7" targetFramework="net461" />
<package id="BouncyCastle" version="1.8.5" targetFramework="net461" />
<package id="CSRedisCore" version="3.8.807" targetFramework="net48" />
<package id="EntityFramework" version="6.4.4" targetFramework="net461" />
<package id="Google.Protobuf" version="3.19.4" targetFramework="net461" />
<package id="jQuery" version="3.3.1" targetFramework="net461" />
@@ -35,5 +36,6 @@
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
<package id="WebGrease" version="1.6.0" targetFramework="net461" />
</packages>