public bool HashSet <TValue>(string key, CtSharpRedisValue field, TValue value, CtSharpWhen when = CtSharpWhen.Always) { if (when == CtSharpWhen.NotExists) { return(database.HSetNx(key, field.Value, CtSharpRedisValue.SerializeRedisValue(value).Value)); } return(database.HSet(key, field.Value, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
public long ListRightPush <T>(string key, T value, CtSharpWhen when = CtSharpWhen.Always) { if (when.Equals(CtSharpWhen.Exists)) { return(database.RPushX(key, CtSharpRedisValue.SerializeRedisValue(value).Value)); } return(database.RPush(key, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
/// <summary> /// 随机获取一个值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T SetRandomMember <T>(string key) { var redisValue = database.SRandMember(key); if (!string.IsNullOrWhiteSpace(redisValue)) { return(CtSharpRedisValue.DeserializeRedisValue <T>(redisValue)); } return(default(T)); }
public bool SortedSetAdd <T>(string key, T value, double score, CtSharpWhen when = CtSharpWhen.Always) { if (when.Equals(CtSharpWhen.Exists)) { throw new NotImplementedException("ctcsredis 不支持此命令"); } if (when.Equals(CtSharpWhen.NotExists)) { throw new NotImplementedException("ctcsredis 不支持此命令"); } Tuple <double, string> tupleValue = Tuple.Create(score, CtSharpRedisValue.SerializeRedisValue(value).Value); return(database.ZAdd(key, tupleValue) > 0); }
public long HashDelete(string key, CtSharpRedisValue[] fields) { if (fields == null) { throw new ArgumentNullException(nameof(fields)); } if (fields.IsNullOrEmptyArrary()) { return(0); } string[] hashFields = CtSharpRedisValue.ConvertToStringArrary(fields); return(database.HDel(key, hashFields)); }
public CtSharpRedisValue[] HashGet(string key, CtSharpRedisValue[] fields) { if (fields == null) { throw new ArgumentNullException(nameof(fields)); } if (fields.IsNullOrEmptyArrary()) { return(Array.Empty <CtSharpRedisValue>()); } string[] hashFields = CtSharpRedisValue.ConvertToStringArrary(fields); var redisValues = database.HMGet(key, hashFields); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public CtSharpRedisValue[] ListRange(string key, long startIndex, long stopIndex) { var redisValues = database.LRange(key, startIndex, stopIndex); if (redisValues.IsNullOrEmptyArrary()) { return(Array.Empty <CtSharpRedisValue>()); } CtSharpRedisValue[] result = new CtSharpRedisValue[redisValues.Length]; for (int i = 0; i < redisValues.Length; i++) { result[i] = redisValues[i]; } return(result); }
public long SortedSetRemoveRangeByValue <TMinMember, TMaxMember>(string key, TMinMember minMember, TMaxMember maxMember, Exclusive exclusive = Exclusive.None) { var min = CtSharpRedisValue.SerializeRedisValue(minMember).Value; var max = CtSharpRedisValue.SerializeRedisValue(maxMember).Value; if (exclusive.Equals(Exclusive.Both)) { return(database.ZRemRangeByLex(key, $"({min}", $"({max}")); } if (exclusive.Equals(Exclusive.Start)) { return(database.ZRemRangeByLex(key, $"({min}", $"[{max}")); } if (exclusive.Equals(Exclusive.Stop)) { return(database.ZRemRangeByLex(key, $"[{min}", $"({max}")); } return(database.ZRemRangeByLex(key, $"[{min}", $"[{max}")); }
public long SortedSetLengthByValue <TMinMember, TMaxMember>(string key, TMinMember minValue, TMaxMember maxValue, Exclusive exclusive = Exclusive.None) { string min = CtSharpRedisValue.SerializeRedisValue(minValue).Value; string max = CtSharpRedisValue.SerializeRedisValue(maxValue).Value; if (exclusive.Equals(Exclusive.Both)) { return(database.ZLexCount(key, $"({min}", $"({max}")); } if (exclusive.Equals(Exclusive.Start)) { return(database.ZLexCount(key, $"({min}", $"[{max}")); } if (exclusive.Equals(Exclusive.Stop)) { return(database.ZLexCount(key, $"[{min}", $"({max}")); } return(database.ZLexCount(key, $"[{min}", $"[{max}")); }
public CtSharpRedisValue[] SortedSetRangeByScoreDesc(string key, double maxScore, double minScore, long offset, long count, Exclusive exclusive = Exclusive.None) { string[] redisValues = null; if (exclusive.Equals(Exclusive.Both)) { redisValues = database.ZRevRangeByScore(key, maxScore, minScore, false, true, true, offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } if (exclusive.Equals(Exclusive.Start)) { redisValues = database.ZRevRangeByScore(key, maxScore, minScore, false, true, false, offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } if (exclusive.Equals(Exclusive.Stop)) { redisValues = database.ZRevRangeByScore(key, maxScore, minScore, false, false, true, offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } redisValues = database.ZRevRangeByScore(key, maxScore, minScore, false, false, false, offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public bool StringSet <T>(string key, T value, TimeSpan?expiry = null, CtSharpWhen when = CtSharpWhen.Always) { object redisValue = CtSharpRedisValue.SerializeRedisValue(value).Value; string result = string.Empty; if (expiry.HasValue) { if (when.Equals(CtSharpWhen.NotExists)) { bool isSet = database.SetNx(key, redisValue); if (isSet) { database.Expire(key, expiry.Value); } return(isSet); } result = database.SetEx(key, (long)expiry.Value.TotalSeconds, redisValue); if (result.Equals("ok", StringComparison.CurrentCultureIgnoreCase)) { return(true); } return(false); } if (when.Equals(CtSharpWhen.NotExists)) { return(database.SetNx(key, redisValue)); } result = database.Set(key, redisValue); if (result.Equals("ok", StringComparison.CurrentCultureIgnoreCase)) { return(true); } return(false); }
public CtSharpRedisValue[] SortedSetRangeByValueAsc <TMinMember, TMaxMember>(string key, TMinMember minMember, TMaxMember maxMember, long offset, long count, Exclusive exclusive = Exclusive.None) { var min = CtSharpRedisValue.SerializeRedisValue(minMember).Value.Trim(); var max = CtSharpRedisValue.SerializeRedisValue(maxMember).Value.Trim(); string[] redisValues = null; if (exclusive.Equals(Exclusive.Both)) { redisValues = database.ZRangeByLex(key, $"({min}", $"({max}", offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } if (exclusive.Equals(Exclusive.Start)) { redisValues = database.ZRangeByLex(key, $"({min}", $"[{max}", offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } if (exclusive.Equals(Exclusive.Stop)) { redisValues = database.ZRangeByLex(key, $"[{min}", $"({max}", offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); } redisValues = database.ZRangeByLex(key, $"[{min}", $"[{max}", offset, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public bool SetRemove <T>(string key, T value) { return(database.SRem(key, CtSharpRedisValue.SerializeRedisValue(value).Value) > 0); }
public CtSharpRedisValue[] SetRandomMembers(string key, long count) { var redisValues = database.SRandMember(key, count); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public CtSharpRedisValue[] HashKeys(string key) { var redisValues = database.HKeys(key); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public bool SetMove <T>(string sourceKey, string destinationKey, T value) { return(database.SMove(sourceKey, destinationKey, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
/// <summary> /// 从队列的左边出队一个元素 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T ListLeftPop <T>(string key) { string redisValue = database.LPop(key); return(CtSharpRedisValue.DeserializeRedisValue <T>(redisValue)); }
public CtSharpRedisValue[] SetCombineUnion(string firstKey, string secondKey) { string[] redisValues = database.SUnion(firstKey, secondKey); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public bool HyperLogLogAdd <T>(string key, T value) { return(database.PfAdd(key, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
public T ListRightPopLeftPush <T>(string key, string destinationKey) { return(CtSharpRedisValue.DeserializeRedisValue <T>(database.RPopLPush(key, destinationKey))); }
public T ListRightPop <T>(string key) { return(CtSharpRedisValue.DeserializeRedisValue <T>(database.RPop(key))); }
public void ListSetByIndex <T>(string key, long index, T value) { database.LSet(key, index, CtSharpRedisValue.SerializeRedisValue(value).Value); }
public long ListRemove <T>(string key, T value, long count) { return(database.LRem(key, count, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
/// <summary> /// 获取一个元素,通过其索引列表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="index"></param> /// <returns></returns> public T ListGetByIndex <T>(string key, long index) { string redisValue = database.LIndex(key, index); return(CtSharpRedisValue.DeserializeRedisValue <T>(redisValue)); }
public double SortedSetDecrement <T>(string key, T value, double incScore) { return(database.ZIncrBy(key, -incScore, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
public CtSharpRedisValue[] SetCombineUnion(string[] keys) { string[] redisValues = database.SUnion(keys); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public CtSharpRedisValue[] SortedSetRangeByRankDesc(string key, long start, long stop) { var redisValues = database.ZRevRange(key, start, stop); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValues)); }
public CtSharpRedisValue[] SetMembers(string key) { var redisValue = database.SMembers(key); return(CtSharpRedisValue.ConvertToRedisValueArrary(redisValue)); }
public bool SetContains <T>(string key, T value) { return(database.SIsMember(key, CtSharpRedisValue.SerializeRedisValue(value).Value)); }
public long ListInsertBefore <TPivot, TValue>(string key, TPivot pivot, TPivot value) { return(database.LInsert(key, RedisInsert.Before, CtSharpRedisValue.SerializeRedisValue(pivot).Value, CtSharpRedisValue.SerializeRedisValue(value).Value)); }