新增:Redis,用于和CRICS交换信息
This commit is contained in:
95
UI/CSRedisCacheHelper.cs
Normal file
95
UI/CSRedisCacheHelper.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using CSRedis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using static CSRedis.CSRedisClient;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Redis缓存辅助类
|
||||
/// </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";
|
||||
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");
|
||||
var DingYueMsg = ("CellCorelDRAWUser", new Action<SubscribeMessageEventArgs>(async (args) =>
|
||||
{
|
||||
string body = args.Body;
|
||||
}));
|
||||
|
||||
CSRedisCacheHelper.redis.Subscribe(DingYueMsg);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void Set<T>(string key, T value, int ExpireTime)
|
||||
{
|
||||
redis?.Set(key, value, ExpireTime * 60);
|
||||
}
|
||||
|
||||
public static T Get<T>(string key)
|
||||
{
|
||||
return redis.Get<T>(key);
|
||||
}
|
||||
|
||||
public static void Forever<T>(string key, T value)
|
||||
{
|
||||
redis.Set(key, value, -1);
|
||||
}
|
||||
public static void Del(string key)
|
||||
{
|
||||
redis.Del(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否存在
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static bool Contains(string key)
|
||||
{
|
||||
bool result = redis.Exists(key);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布消息
|
||||
/// </summary>
|
||||
/// <param name="Topic"></param>
|
||||
/// <param name="Payload"></param>
|
||||
public static void Publish(string Topic, string Payload)
|
||||
{
|
||||
CSRedisCacheHelper.redis.PublishNoneMessageId(Topic, Payload);
|
||||
}
|
||||
|
||||
|
||||
public static void LPush(string Key, Dictionary<string, string> Value)
|
||||
{
|
||||
CSRedisCacheHelper.redis.LPush<Dictionary<string,string>>(Key,Value);
|
||||
}
|
||||
|
||||
public static T BRPop<T>(string Key)
|
||||
{
|
||||
return CSRedisCacheHelper.redis.BRPop<T>(3,Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user