public static void CleanupTags(this IRedisClient client) { if (client == null) { throw new ArgumentNullException("client"); } client.ExecLuaAsInt(Script(LuaResources.CleanupTags)); }
/// <summary> /// Sets a key/value pair, and marks the key with one or more specified tags. /// </summary> public static int SetWithTags <T>(this IRedisClient client, string key, T value, IList <string> tags, TimeSpan?expiresIn = null) { if (client == null) { throw new ArgumentNullException("client"); } if (key == null) { throw new ArgumentNullException("key"); } if (tags == null) { throw new ArgumentNullException("tags"); } if (value == null) { throw new ArgumentNullException("value", "Use Remove(key) intead."); } if (tags.Count == 0) { if (expiresIn.HasValue) { client.Set(key, value, expiresIn.Value); } else { client.Set(key, value); } return(0); } string[] keys = new string[tags.Count + 1]; keys[0] = key; tags.CopyTo(keys, 1); string serializedValue = SerializeValue(value); var args = new List <string> { serializedValue }; if (expiresIn.HasValue) { int seconds = (int)expiresIn.Value.TotalSeconds; args.Add(seconds.ToString(CultureInfo.InvariantCulture)); } CleanupByProbability(client); // NOTE: Scripts should be executed by their SHA1 hash rather than by sending // the full text across the wire each time. Left as an excercise for the reader. int numberOfTagsAdded = (int)client.ExecLuaAsInt(Script(LuaResources.AddWithTags), keys, args.ToArray()); return(numberOfTagsAdded); }
/** * 释放分布式锁 * @param jedis Redis客户端 * @param lockKey 锁 * @param requestId 请求标识 * @return 是否释放成功 */ public override bool ReleaseDistributedLock(String lockKey, String requestId) { long RELEASE_SUCCESS = 1L; using (IRedisClient redis = GetRedisClient()) { String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; Object result = redis.ExecLuaAsInt(script, lockKey, requestId); if (RELEASE_SUCCESS.Equals(result)) { return(true); } return(false); } }
public static int RemoveKeysByPattern(this IRedisClient client, string pattern) { return((int)client.ExecLuaAsInt(Script.RemoveKeysByPatternScript, pattern)); }