Exemplo n.º 1
0
        public async ValueTask PublishAsync(TKey key, TMessage message, CancellationToken cancellationToken)
        {
            var channel = CreateChannel(key);
            var value   = serializer.Serialize(message);

            // Redis.PublishAsync has no cancellationToken overload.
            await connectionFactory.GetConnectionMultiplexer(key).GetSubscriber().PublishAsync(channel, value).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="item">The item.</param>
        /// <param name="keepAlive">The keep alive.</param>
        public void Set(string name, object item, TimeSpan?keepAlive = null)
        {
            var cInfo = new CacheDataInfo <object>
            {
                CachedDateTime = DateTime.Now,
                KeepAlive      = keepAlive ?? TimeSpan.Zero,
                NewCacheData   = item,
            };

            _container.Set(name, _serialier.Serialize(cInfo), keepAlive);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1" /> at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted.</param>
 /// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1" />.</param>
 public void Insert(int index, T item)
 {
     if (RedisDb.ListLength(RedisKey) > index)
     {
         var before = RedisDb.ListGetByIndex(RedisKey, index);
         RedisDb.ListInsertBefore(RedisKey, before, Serializer.Serialize(item));
     }
     else
     {
         throw new IndexOutOfRangeException($"Index: '{index}' for Redis list: '{RedisKey}' is out of range.");
     }
 }
Exemplo n.º 4
0
        public bool Set(ConfigType type, string code, string json)
        {
            var descriptor = _configs.FirstOrDefault(m => m.Code.EqualsIgnoreCase(code) && m.Type == type);

            if (descriptor == null)
            {
                throw new NotImplementedException("没有找到配置类型");
            }

            //持久化
            if (_storageProvider.SaveJson(type, code, json).GetAwaiter().GetResult())
            {
                var key    = _redisHelper.GetKey($"{CACHE_KEY}:{descriptor.Type.ToString().ToUpper()}:{descriptor.Code.ToUpper()}");
                var config = JsonConvert.DeserializeObject(json, descriptor.ImplementType);
                _redisHelper.Db.StringSetAsync(key, _redisSerializer.Serialize(config)).GetAwaiter().GetResult();
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Adds the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="when">The when.</param>
 /// <returns></returns>
 public bool Add(TKey key, TValue value, When when)
 {
     return(RedisDb.HashSet(RedisKey, KeySerializer.Serialize(key), ValueSerializer.Serialize(value), when: when));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 写入字符串类型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="obj"></param>
 /// <param name="expiry"></param>
 /// <returns></returns>
 public Task <bool> StringSetAsync <T>(string key, T obj, TimeSpan?expiry = null)
 {
     return(Db.StringSetAsync(GetKey(key), _redisSerializer.Serialize(obj), expiry));
 }