public async Task <bool> StringSetAsync(string cacheKey, string cacheValue, System.TimeSpan?expiration, string when)
        {
            ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

            bool flag = false;

            RedisExistence?exists = null;

            if (when.Equals("nx", System.StringComparison.OrdinalIgnoreCase))
            {
                exists = RedisExistence.Nx;
            }
            else if (when.Equals("xx", System.StringComparison.OrdinalIgnoreCase))
            {
                exists = RedisExistence.Xx;
            }

            if (expiration.HasValue)
            {
                flag = await _cache.SetAsync(cacheKey, cacheValue, (int)expiration.Value.TotalSeconds, exists : exists);
            }
            else
            {
                flag = await _cache.SetAsync(cacheKey, cacheValue, exists : exists);
            }

            return(flag);
        }
Beispiel #2
0
        public static bool SetList(string key, object value, int expireSeconds = -1, RedisExistence?exists = null)
        {
            key = RedisConstants.RedisPrefix + key;
            object redisValule = cs.SerializeRedisValueInternal(value);

            if (expireSeconds <= 0 && exists == null)
            {
                return(cs.ExecuteScalar(key, (c, k) => c.Value.Set(k, redisValule)) == "OK");
            }
            return(false);
        }
 public string Set(string key, object value, long?expirationMilliseconds = null, RedisExistence?condition = null) => Multi((client) => client.Set(key, value, expirationMilliseconds, condition));
 public string Set(string key, object value, TimeSpan expiration, RedisExistence?condition = null) => Multi((client) => client.Set(key, value, expiration, condition));
Beispiel #5
0
 /// <summary>
 /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value">值</param>
 /// <param name="expire">过期时间</param>
 /// <param name="exists"></param>
 /// <returns></returns>
 public Task <bool> SetAsync(string key, object value, TimeSpan expire, RedisExistence?exists = null)
 {
     return(RedisHelper.SetAsync(key, value, expire, exists));
 }
Beispiel #6
0
 /// <summary>
 /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value">值</param>
 /// <param name="expire">过期时间</param>
 /// <param name="exists"></param>
 /// <returns></returns>
 public bool Set(string key, object value, TimeSpan expire, RedisExistence?exists = null)
 {
     return(RedisHelper.Set(key, value, expire, exists));
 }
 public string Set(string key, object value, int?expirationSeconds = null, RedisExistence?condition = null) => Multi(StringCommands.Set(key, value, expirationSeconds, null, condition));
Beispiel #8
0
        private static RedisStatus.Nullable Set(string key, object value, int?expirationSeconds = null, long?expirationMilliseconds = null, RedisExistence?exists = null)
        {
            var args = new List <string> {
                key, value.ToString()
            };

            if (expirationSeconds != null)
            {
                args.AddRange(new[] { "EX", expirationSeconds.ToString() });
            }
            if (expirationMilliseconds != null)
            {
                args.AddRange(new[] { "PX", expirationMilliseconds.ToString() });
            }
            if (exists != null)
            {
                args.AddRange(new[] { exists.ToString().ToUpperInvariant() });
            }
            return(new RedisStatus.Nullable("SET", args.ToArray()));
        }
 public Task <string> Set(string key, object value, long?expirationMilliseconds = null, RedisExistence?condition = null)
 {
     return(Write(RedisCommand.Set(key, value, expirationMilliseconds, condition)));
 }
 public Task <string> Set(string key, object value, TimeSpan expiration, RedisExistence?condition = null)
 {
     return(Write(RedisCommand.Set(key, value, expiration, condition)));
 }
        /// <summary>
        /// 设置指定key的值
        /// </summary>
        /// <param name="key">需要设置的key</param>
        /// <param name="value">需要设置的值</param>
        /// <param name="expirationSeconds">过期时间(秒)</param>
        /// <param name="expirationMilliseconds">过期时间(毫秒)</param>
        /// <param name="exists">其他限定条件</param>
        /// <returns>命令对象</returns>
        public static ReturnTypeWithStatus Set(string key, object value, int?expirationSeconds = null, long?expirationMilliseconds = null, RedisExistence?exists = null)
        {
            var args = new List <string> {
                key, value.ToString()
            };

            if (expirationSeconds != null)
            {
                args.AddRange(new[] { "EX", expirationSeconds.ToString() });
            }
            if (expirationMilliseconds != null)
            {
                args.AddRange(new[] { "PX", expirationMilliseconds.ToString() });
            }
            if (exists != null)
            {
                args.AddRange(new[] { exists.ToString().ToUpperInvariant() });
            }
            var cmd = new ReturnTypeWithStatus("SET", args.ToArray());

            cmd.IsNullable = true;
            return(cmd);
        }
Beispiel #12
0
 public async Task SetItemAsync(string key, object value, int time = -1, RedisExistence?exist = null)
 {
     await csredis.SetAsync(key, value, time, exist);
 }
Beispiel #13
0
 public void SetItem(string key, object value, int time = -1, RedisExistence?exist = null)
 {
     csredis.Set(key, value, time, exist);
 }
 public Task <string> SetAsync(string key, object value, long?expirationMilliseconds = null, RedisExistence?condition = null) => MultiAsync(StringCommands.Set(key, value, null, expirationMilliseconds, condition));
Beispiel #15
0
 public static RedisStatus.Nullable Set(string key, object value, TimeSpan expiration, RedisExistence?condition = null)
 {
     return(Set(key, value, (long)expiration.TotalMilliseconds, condition));
 }
Beispiel #16
0
 public static RedisStatus.Nullable Set(string key, object value, long?expirationMilliseconds = null, RedisExistence?condition = null)
 {
     return(Set(key, value, null, expirationMilliseconds, condition));
 }
Beispiel #17
0
 public static RedisStatusNull Set(string key, object value, int?expirationSeconds = null, RedisExistence?condition = null)
 {
     return(Set(key, value, expirationSeconds, null, condition));
 }
Beispiel #18
0
 /// <summary>
 /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value">值</param>
 /// <param name="expireSeconds">过期(秒单位)</param>
 /// <param name="exists">0 Nx| 1 Xx</param>
 /// <returns></returns>
 public static new async Task <bool> SetAsync(string key, object value, int expireSeconds = -1, RedisExistence?exists = null)
 {
     try
     {
         return(await _redisManager.SetAsync(key, value, expireSeconds, exists));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public Task <string> SetAsync(string key, object value, TimeSpan expiration, RedisExistence?condition = null) => MultiAsync(StringCommands.Set(key, value, (int)expiration.TotalSeconds, null, condition));