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() + " "); } }

  如果登陆是第一次登陆,就插入redis,如不是第一次就跳过。可以自己设置登录过期的时间。 

原文地址:https://www.cnblogs.com/linbicheng/p/5395602.html