Пример #1
0
        /// <summary>
        /// 存储数据到hash表
        /// </summary>
        /// <param name="kValues"></param>
        /// <param name="second"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public bool HashSet <T>(Dictionary <string, Dictionary <string, T> > kValues, long second = -1,
                                bool isSetHashKeyExpire = true)
        {
            Dictionary <string, object[]> keyValues = new Dictionary <string, object[]>();

            foreach (var item in kValues)
            {
                List <object> dataKeyValues = new List <object>();
                foreach (var kvp in item.Value)
                {
                    dataKeyValues.Add(isSetHashKeyExpire ? GetKey(kvp.Key) : kvp.Key);
                    dataKeyValues.Add(ConvertJson(kvp.Value));
                }

                keyValues.Add(isSetHashKeyExpire ? GetKey(item.Key) : item.Key, dataKeyValues.ToArray());
            }

            if (isSetHashKeyExpire)
            {
                return(string.Equals(QuickHelperBase.HashSetHashFileExpire(keyValues, GetExpire(second)), "OK",
                                     StringComparison.OrdinalIgnoreCase));
            }

            return(string.Equals(QuickHelperBase.HashSetExpire(keyValues, GetExpire(second)), "OK",
                                 StringComparison.OrdinalIgnoreCase));
        }
Пример #2
0
        /// <summary>
        /// 存储数据到hash表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="dataKey"></param>
        /// <param name="t"></param>
        /// <param name="second">秒</param>
        /// <param name="isSetHashKeyExpire">false:设置key的过期时间,true:设置hashkey的过期时间,默认设置的为HashKey的过期时间。</param>
        /// <returns></returns>
        public bool HashSet <T>(string key, string dataKey, T t, long second = -1, bool isSetHashKeyExpire = true)
        {
            string value = "";

            if (!isSetHashKeyExpire)
            {
                value =
                    QuickHelperBase.HashSetExpire(key, GetExpire(second), dataKey, ConvertJson(t));
            }
            else
            {
                value = QuickHelperBase.HashSetHashFileExpire(GetKey(key), GetKey(dataKey), GetExpire(second),
                                                              ConvertJson(t));
            }

            bool result = string.Equals(value, "OK",
                                        StringComparison.OrdinalIgnoreCase);

            return(result);
        }
Пример #3
0
        /// <summary>
        ///  存储数据到hash表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="kvalues"></param>
        /// <param name="second">秒</param>
        /// <param name="isSetHashKeyExpire"></param>
        /// <returns></returns>
        public bool HashSet <T>(string key, Dictionary <string, T> kvalues, long second = -1,
                                bool isSetHashKeyExpire = true)
        {
            List <object> keyValues = new List <object>();

            foreach (var kvp in kvalues)
            {
                keyValues.Add(isSetHashKeyExpire ? GetKey(kvp.Key) : kvp.Key);
                keyValues.Add(ConvertJson(kvp.Value));
            }

            if (isSetHashKeyExpire)
            {
                return(string.Equals(
                           QuickHelperBase.HashSetHashFileExpire(GetKey(key), GetExpire(second), keyValues.ToArray()),
                           "OK",
                           StringComparison.OrdinalIgnoreCase));
            }

            return(string.Equals(QuickHelperBase.HashSetExpire(key, GetExpire(second), keyValues.ToArray()), "OK",
                                 StringComparison.OrdinalIgnoreCase));
        }
Пример #4
0
        /// <summary>
        /// 存储数据到hash表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="dataKey"></param>
        /// <param name="t"></param>
        /// <param name="second">秒</param>
        /// <param name="isSetHashKeyExpire">false:设置key的过期时间(整个键使用一个过期时间),true:设置hashkey的过期时间,默认设置的为HashKey的过期时间(单个datakey使用一个过期时间)。</param>
        /// <param name="overdueStrategy"></param>
        /// <returns></returns>
        public bool HashSet <T>(string key, string dataKey, T t, long second = -1L, bool isSetHashKeyExpire = true,
                                OverdueStrategy overdueStrategy = null)
        {
            string value = "";

            return(base.Execute(overdueStrategy, () =>
            {
                if (!isSetHashKeyExpire)
                {
                    value =
                        QuickHelperBase.HashSetExpire(key, GetExpire(second), dataKey, ConvertJson(t));
                }
                else
                {
                    value = QuickHelperBase.HashSetHashFileExpire(GetKey(key), GetKey(dataKey), GetExpire(second),
                                                                  ConvertJson(t));
                }

                bool result = string.Equals(value, "OK",
                                            StringComparison.OrdinalIgnoreCase);
                return result;
            }, () => { return false; }));
        }