C# StackExchange.Redis 模糊删除 模糊查找


 /// <summary>
        /// 模糊查找
        /// </summary>
        /// <param name="key"></param>
        public List<XJDataDll.Tag.Point> SelectTags(string pattern)
        {
            List<XJDataDll.Tag.Point> result = new List<XJDataDll.Tag.Point>();
            try
            {


                var redisResult = _Redisconnection.GetDatabase().ScriptEvaluate(LuaScript.Prepare(
                                //Redis的keys模糊查询:
                                " local res = redis.call('KEYS', @keypattern) " +
                                " return res "), new { @keypattern = pattern });

                if (!redisResult.IsNull)
                {
                    RedisKey[] preSult = (RedisKey[])redisResult;
                    var Tags = _Redisconnection.GetDatabase().StringGet(preSult);

                    if (Tags != null)
                    {
                        result = Tags.Select(o => XJDataDll.Json.DataJsonSerializer.JsonToObject<XJDataDll.Tag.Point>(o.ToString())).ToList();
                    }
                }



            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (result == null)
                {
                    result = new List<XJDataDll.Tag.Point>();
                }
            }

            return result;
        }
    /// <summary>
        /// 模糊删除
        /// </summary>
        /// <param name="key"></param>
        public void LikeRemove(string pattern)
        {
            try
            {


                var redisResult = _Redisconnection.GetDatabase().ScriptEvaluate(LuaScript.Prepare(
                                //Redis的keys模糊查询:
                                " local res = redis.call('KEYS', @keypattern) " +
                                " return res "), new { @keypattern = pattern });

                if (!redisResult.IsNull)
                {
                    RedisKey[] preSult = (RedisKey[])redisResult;
                    _Redisconnection.GetDatabase().KeyDelete(preSult);
                }
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM