Как очистить информацию о подключении 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();
}`
Я вызываю кэш Redis в загрузке страницы приложения asp.net следующим образом:
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)
{
}
}