/// <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);
}
}
