public static void RemoveLoginUserSession(int userId) { if (userId <= 0) { return; } string redis_key = "SESS_*_LoginUser_UserID:" + userId.ToString(); using (RedisNativeClient RNC = GetNativeClientForKeySpace(space)) { var temp = RNC.Keys(redis_key); if (temp != null && temp.Length > 0) { for (int i = 0; i < temp.Length; i++) { var tempKey = Encoding.UTF8.GetString(temp[i], 0, temp[i].Length); if (tempKey != null) { RNC.Del(tempKey.ToString()); } } } } }
public static void RedisIncrement() { using (IRedisNativeClient nrc = new RedisNativeClient()) { nrc.Del("Increment"); for (int i = 0; i < iterations; i++) { nrc.Incr("Increment"); } } }
public static void RemoveSession(string key) { if (string.IsNullOrEmpty(key) || key == "-1") { return; } string redis_key = "SESS_" + key; using (RedisNativeClient RNC = GetNativeClientForKeySpace(space)) { RNC.Del(redis_key); } }
protected void btnReDelete(object sender, EventArgs e) { RedisNativeClient rclient = new RedisNativeClient("192.168.1.207", 6379); string keyval = key2.Text.Trim(); try { if (rclient.Exists(keyval) == 1) { rclient.Del(keyval); Response.Write("<script>window.alert('删除成功!');window.location.href='../Mem_RedisTest.aspx'</script>"); } else { Response.Write("<script>window.alert('Key不存在!');window.location.href='../Mem_RedisTest.aspx'</script>"); } } catch { Response.Write("<script>window.alert('删除失败!');window.location.href='../Mem_RedisTest.aspx'</script>"); } }
//------------------------------------------------------------------ // GENERAL public long Del(string key) { RedisNativeClient client = this.pool.GetRedisClient(key); return((client == null) ? 0L : client.Del(key)); }