Exemple #1
0
        /// <summary>
        /// query and format the value result by cache key type
        /// Hash、List、Set and String etc.
        /// they all has different format in order to modify by client
        /// </summary>
        /// <param name="key"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string QueryWithType(string key, CacheKeyType type)
        {
            if (!_client.IsConnected)
            {
                return(string.Empty);
            }
            try
            {
                IDatabase database = _client.GetDatabase();
                IOperator op       = null;
                switch (type)
                {
                case CacheKeyType.None: break;

                case CacheKeyType.String:
                    op = new RedisString();
                    break;

                case CacheKeyType.Hash:
                    op = new RedisHash();
                    break;

                case CacheKeyType.List:
                    op = new RedisList();
                    break;

                case CacheKeyType.Set:
                    op = new RedisSet();
                    break;

                case CacheKeyType.SortedSet:
                    op = new RedisSortedSet();
                    break;
                }
                if (op == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(op.Format(database, key));
                }
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }
        }
Exemple #2
0
        public bool Set(string key, CacheKeyType type, string value, int timeToLive)
        {
            if (!_client.IsConnected)
            {
                return(false);
            }
            IDatabase database = _client.GetDatabase();
            IOperator op       = null;

            switch (type)
            {
            case CacheKeyType.None:
            case CacheKeyType.String:
                op = new RedisString();
                break;

            case CacheKeyType.Hash:
                op = new RedisHash();
                break;

            case CacheKeyType.List:
                op = new RedisList();
                break;

            case CacheKeyType.Set:
                op = new RedisSet();
                break;

            case CacheKeyType.SortedSet:
                op = new RedisSortedSet();
                break;
            }
            if (op == null)
            {
                return(false);
            }
            else
            {
                return(op.Set(database, key, value, timeToLive));
            }
        }