Ejemplo n.º 1
0
        //更新集合
        public static bool SetUpdate <T>(string key, T oldValue, T newValue, string sql, string user, string HospitalID, string tableName)
        {
            bool b = false;

            if (RedisWriteHelper.KeyExists(key))
            {
                try
                {
                    var result = RedisWriteHelper.SetRemoveAsync(key, JsonSerializer.SerializeToString(oldValue));
                    if (result.Result)
                    {
                        var isSuccess = RedisWriteHelper.SetAddAsync(key, JsonSerializer.SerializeToString(newValue));
                        if (isSuccess.Result)
                        {
                            //BsMsgRecord msgRecord = new BsMsgRecord() { HospitalID = Convert.ToInt32(HospitalID), tableName = tableName, cacheKey = key, oldValue = JsonSerializer.SerializeToString(oldValue), newValue = JsonSerializer.SerializeToString(newValue), curUser = user, sqlRecord = sql, updateTime = DateTime.Now.ToString("yyyyMMddhhmmss") };
                            //Producer.Topic(ExchangeName, Routingkey, msgRecord);//发消息
                        }
                        b = isSuccess.Result;
                    }
                }
                catch (Exception)
                {
                    RedisWriteHelper.SetRemove(key, JsonSerializer.SerializeToString(newValue));
                    RedisWriteHelper.SetAdd(key, JsonSerializer.SerializeToString(oldValue));
                    return(false);
                }
            }
            return(b);
        }
Ejemplo n.º 2
0
        //从Hash中模糊查找
        public static List <T> HashSearch <T>(string key, int cursor, string pattern, int count)
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                value = RedisWriteHelper.HashScan <T>(key, cursor, pattern, count);
            }
            return(value);
        }
Ejemplo n.º 3
0
        //从集合中模糊查找
        public static List <Object> SetSearch(string key, int cursor, string pattern, int count)
        {
            var value = new List <object>();

            if (RedisWriteHelper.KeyExists(key))
            {
                value = RedisWriteHelper.SetScan(key, cursor, pattern, count);
            }
            return(value);
        }
Ejemplo n.º 4
0
        //获取指定的类型的所有数据
        public static List <T> RetrieveSet <T>(string key) where T : class, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.SetMembersAsync <T>(key);//内存取数
                return(result.Result);
            }
            return(value);
        }
Ejemplo n.º 5
0
        //获取指定的HashTable
        public static List <T> RetrieveHash <T>(string key) where T : Orm.Model.BaseModel, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.GetAll <T>(key);//内存取数
                return(result);
            }
            return(value);
        }
Ejemplo n.º 6
0
        //获取指定的HashTable
        public static List <T> RetrieveHash <T>(string key) where T : Orm.Model.BaseModel, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.GetAll <T>(key);//内存取数
                return(result);
            }
            //else
            //{
            //    value = _dbService.DataRepository.GetQueryable<T>().ToList();//数据取数据
            //    if (value.Count() > 0)
            //    {
            //        foreach (var item in value)
            //        {
            //            RedisWriteHelper.SetHash<T>(key, item.GUID, item);
            //        }
            //    }
            //}
            return(value);
        }
Ejemplo n.º 7
0
        //根据IQueryable,获取一条数据
        public static T GetModelByIQueryable <T>(string key, IQueryable <T> query, string HospitalID, string tableName) where T : class, new()
        {
            T value = null;

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.StringGetAsync <T>(key);//内存取数
                return(result.Result);
            }
            else
            {
                try
                {
                    value = query.FirstOrDefault();               //数据取数据
                    RedisWriteHelper.SetAsync(key, value).Wait(); //加到内存里
                }
                catch (Exception)
                {
                    return(value);
                }
            }
            return(value);
        }
Ejemplo n.º 8
0
        //根据IQueryable,获取指定的类型的部分数据
        //public static List<T> RetrieveSetByIQueryable<T>(string key, IQueryable<T> query) where T : class, new()
        public static List <T> RetrieveSetByIQueryable <T>(string key, IQueryable <T> query) where T : Model.BaseModel, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.SetMembersAsync <T>(key);//内存取数
                return(result.Result);
            }
            else
            {
                value = query.ToList();//数据取数据
                if (value.Count() > 0)
                {
                    foreach (var item in value)
                    {
                        RedisWriteHelper.SetAddAsync(key, JsonSerializer.SerializeToString(item)).Wait();
                        //RedisHelper.SetHash<T>(key, item.GUID, item);
                        //RedisHelper.SetAsync(item.GUID, item).Wait();
                    }
                }
            }
            return(value);
        }