.net 如何在stackexchange.redi中使用ConnectionMultiplexer中的KeyScan
我有以下关于redis连接的代码.net 如何在stackexchange.redi中使用ConnectionMultiplexer中的KeyScan,.net,redis,stackexchange.redis,.net,Redis,Stackexchange.redis,我有以下关于redis连接的代码 private static readonly Lazy<ConnectionMultiplexer> Conn = new Lazy<ConnectionMultiplexer>( () => { try { if (ConfigOptions != null &&am
private static readonly Lazy<ConnectionMultiplexer> Conn = new Lazy<ConnectionMultiplexer>(
() =>
{
try
{
if (ConfigOptions != null && ConfigOptions.Value != null)
{
return ConnectionMultiplexer.Connect(ConfigOptions.Value);
}
return null;
}
catch (Exception ex)
{
Logger.Fatal(ex.Message, ex);
return null;
}
});
private static ConnectionMultiplexer Muxer => Conn.Value;
public static bool KeyExists(string key)
{
var result = false;
try
{
IDatabase getDatabase;
if (Muxer != null && (getDatabase = Muxer.GetDatabase()) != null)
{
result = getDatabase.KeyExists(key);
//https://riptutorial.com/stackexchange-redis/topic/66/scan
}
}
catch (Exception ex)
{
Logger.Fatal(ex.Message, ex);
}
return result;
}
private static readonly Lazy Conn=new Lazy(
() =>
{
尝试
{
if(ConfigOptions!=null&&ConfigOptions.Value!=null)
{
返回ConnectionMultiplexer.Connect(ConfigOptions.Value);
}
返回null;
}
捕获(例外情况除外)
{
记录器。致命(例如消息,例如);
返回null;
}
});
专用静态连接多路复用器Muxer=>连接值;
公共静态布尔键存在(字符串键)
{
var结果=假;
尝试
{
IDatabase数据库;
if(Muxer!=null&(getDatabase=Muxer.getDatabase())!=null)
{
结果=getDatabase.KeyExists(键);
//https://riptutorial.com/stackexchange-redis/topic/66/scan
}
}
捕获(例外情况除外)
{
记录器。致命(例如消息,例如);
}
返回结果;
}
键命令是昂贵的命令
知道如何使用在StackExchange实现中实现的scan命令吗
公共IEnumerable键(int-database=0,RedisValue-pattern=default(RedisValue),int-pageSize=CursorUtils.DefaultPageSize,long-CursorUtils.Origin,int-pageOffset=0,CommandFlags=CommandFlags.None)
从Muxer对象中?Stackexchange.Redis将在其密钥实现中使用扫描(如果Redis版本>=2.8)。使其在Redis端安全,因为它是一种非阻塞操作 不过,你应该确保你的应用程序能够处理大量回复。扫描迭代是Stackexchange的内部迭代,您不能在每次迭代中添加逻辑 你应该多读一些