You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.3 KiB
102 lines
3.3 KiB
using ServiceStack.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.WebCommon
|
|
{
|
|
public class RedisHelp
|
|
{
|
|
//邮件发送账号
|
|
string redisIp = System.Configuration.ConfigurationManager.AppSettings["redisIp"] + "";
|
|
//邮件发送授权码
|
|
string redisPort = System.Configuration.ConfigurationManager.AppSettings["redisPort"] + "";
|
|
//邮件发送SMTP
|
|
string redisPwd = System.Configuration.ConfigurationManager.AppSettings["redisPwd"] + "";
|
|
|
|
public void SetRedis(string key, string Val)
|
|
{
|
|
try
|
|
{
|
|
int.TryParse(redisPort, out int redisPortNum);
|
|
redisPwd = string.IsNullOrWhiteSpace(redisPwd) ? null : redisPwd;
|
|
using (RedisClient client = new RedisClient(redisIp, redisPortNum, redisPwd))
|
|
{
|
|
if (client == null)
|
|
{
|
|
return;
|
|
}
|
|
if (client.ContainsKey(key))
|
|
{
|
|
client.Replace<string>(key, Val);
|
|
}
|
|
else
|
|
{
|
|
client.Set<string>(key, Val);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "写入Redis异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "RedisLog"
|
|
});
|
|
}
|
|
}
|
|
|
|
public string GetRedis(string key)
|
|
{
|
|
try
|
|
{
|
|
int.TryParse(redisPort, out int redisPortNum);
|
|
redisPwd = string.IsNullOrWhiteSpace(redisPwd) ? null : redisPwd;
|
|
using (RedisClient client = new RedisClient(redisIp, redisPortNum, redisPwd))
|
|
{
|
|
return client.Get<string>(key);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "读取Redis异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "RedisLog"
|
|
});
|
|
}
|
|
return "";
|
|
}
|
|
|
|
|
|
public string RemoveLoginAllReids(string usersId)
|
|
{
|
|
try
|
|
{
|
|
SetRedis("XJAPPlogin_" + usersId, "");
|
|
SetRedis("XCXlogin_" + usersId, "");
|
|
SetRedis("AppLoginByAppId_" + usersId, "");
|
|
SetRedis("XCXLoginByOpenId_" + usersId, "");
|
|
SetRedis("pwdCache_" + usersId, "");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "读取Redis异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "RedisLog"
|
|
});
|
|
}
|
|
return "";
|
|
}
|
|
|
|
}
|
|
}
|