visual-studio - Redis 缓存显示相同的用户详细信息,不同的用户也登录。我应该如何、何时以及从何处处理连接
问题描述
如何刷新 Redis 连接信息。我什么时候应该刷新信息。我应该从哪里刷新/处理 Redis 缓存连接。
我将会话信息存储在 Redis 缓存中。我们正在将应用程序从物理服务器移动到 Azure,因此我实现了 Redis 缓存来代替会话。
Redis 连接我存储在一个连接到 Redis 数据库的类文件中。
public class RedisStore
{
private static readonly Lazy<ConnectionMultiplexer> LazyConnection;`
static RedisStore()
{
//var configurationOptions = new ConfigurationOptions
//{
// EndPoints = { ConfigurationManager.AppSettings["redis.connection"] }
//};
LazyConnection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("server:343, server2:344, PASSWORD = abc$"));
}
public static ConnectionMultiplexer Connection => LazyConnection.Value;
public static IDatabase RedisCache => Connection.GetDatabase();
}`
我在 asp.net 应用程序的页面加载中调用 Redis 缓存,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
try
{
var redis = RedisStore.RedisCache;
clsLogin objLogin = new clsLogin();
var key = "Username";
var _userName = redis.StringSet(key, HttpContext.Current.User.Identity.Name;);
DataSet dtLoginInfo = objLogin.ValidateLoginInfo();
if (dtLoginInfo.Tables[0].Rows.Count > 0)
{
redis.StringSet("ResourceName", dtLoginInfo.Tables[0].Rows[0]["ResourceName"].ToString());
var val = redis.StringGet("ResourceName");
redis.StringSet("Role", dtLoginInfo.Tables[0].Rows[0]["IsAdmin"].ToString());
lblProgress.Text = HttpContext.Current.User.Identity.Name + " Please wait logging in progress. ";
Response.Redirect("abc.aspx",false);
}
else
lblProgress.Text = HttpContext.Current.User.Identity.Name + " is not authorized to access this page. Please check with Admin";
}
catch (Exception ex)
{
}
}
解决方案
推荐阅读
- mysql - 使用 LOAD DATA INFILE 将数据从 txt 文件加载到 MySQL 时遇到问题
- c - 如何使用 void 指针参数构造 C 函数并在运行时有条件地将它们转换为其他类型?
- python - 调用 PyPI 包中的其他脚本
- javascript - 如何防止子事件中的代码执行父元素事件
- sql-server - 使用“In”的 SQL 到实体框架
- javascript - 使用 requestAnimationFrame 添加限制?
- batch-file - 杀死从另一个 cmd 框卡住的批处理文件
- c# - 如何创建一个带有问题的无限循环,该问题在回答时将答案分类为 3 个不同数组中的 1 个?
- extjs - 浮动经典树列表在单击以展开时关闭
- python - 如何在 date_range 函数生成的日期时间中应用条件?