redis自动过期
我當時設置如登陸自動過期的時間。自己找的做了下。
設置自動過期時間。
public static PooledRedisClientManager poolreds;
static RedisPool()
{
try
{
poolreds = new PooledRedisClientManager(10, new string[] { “101210.212.:1213” });
}
catch (Exception ex)
{
?
}
}
public static void GetSession(string key,string value){try{using (var client = poolreds.GetClient()){if (key != null){//查詢是否存在var count = client.ContainsKey("openId:" + key);//存在就不插入if (!count){//設置過期時間 (時,分,秒)TimeSpan ts11 = new TimeSpan(10,0,0);//寫入redis中client.SetEntry(key, value);//設置過期 這個過期會自動刪除的。測試了得還可以。client.ExpireEntryIn(key, ts11);}}}}catch (Exception ex){Result.Log("redis:異常:" + ex.ToString() + "\r\n");}}
如果登陸是第一次登陸,就插入redis,如不是第一次就跳過。可以自己設置登錄過期的時間。?
轉載于:https://www.cnblogs.com/linbicheng/p/5395602.html
總結
- 上一篇: 求一个微笑的短句子个性签名。
- 下一篇: 人工智能第二次作业