Skip to content

Commit

Permalink
- opt Blocking timeout error;#182
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Apr 24, 2024
1 parent e635ae7 commit 5e67d55
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
11 changes: 11 additions & 0 deletions examples/console_net8_cluster/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ class Program

static void Main(string[] args)
{
var tblv1 = cli.BLPop("testblist01", 5);
var tblv2 = cli.BLPop("testblist02", 5);
var tblv3 = cli.BLPop("testblist03", 5);

cli.LPush("testblist01", "value1");
tblv1 = cli.BLPop("testblist01", 5);
cli.LPush("testblist02", "value2");
tblv2 = cli.BLPop("testblist02", 5);
cli.LPush("testblist03", "value3");
tblv3 = cli.BLPop("testblist03", 5);

//预热
cli.Set(Guid.NewGuid().ToString(), "我也不知道为什么刚刚好十五个字");
sedb.StringSet(Guid.NewGuid().ToString(), "我也不知道为什么刚刚好十五个字");
Expand Down
5 changes: 5 additions & 0 deletions src/FreeRedis/CommandPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ internal bool IsReadOnlyCommand()
var cmdset = CommandSets.Get(_command);
return cmdset != null && ((cmdset.Tag & CommandSets.ServerTag.read) == CommandSets.ServerTag.read || (cmdset.Flag & CommandSets.ServerFlag.@readonly) == CommandSets.ServerFlag.@readonly);
}
internal bool IsBlockingCommand()
{
var cmdset = CommandSets.Get(_command);
return cmdset != null && ((cmdset.Tag & CommandSets.ServerTag.blocking) == CommandSets.ServerTag.blocking);
}
}

static class CommandPacketExtensions
Expand Down
4 changes: 2 additions & 2 deletions src/FreeRedis/RedisClient/Adapter/ClusterAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override TValue AdapterCall<TValue>(CommandPacket cmd, Func<RedisResult,
}
catch (Exception ex)
{
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down Expand Up @@ -242,7 +242,7 @@ async public override Task<TValue> AdapterCallAsync<TValue>(CommandPacket cmd, F
}
catch (Exception ex)
{
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/FreeRedis/RedisClient/Adapter/NormanAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public override TValue AdapterCall<TValue>(CommandPacket cmd, Func<RedisResult,
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down Expand Up @@ -193,7 +193,7 @@ async public override Task<TValue> AdapterCallAsync<TValue>(CommandPacket cmd, F
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/FreeRedis/RedisClient/Adapter/PoolingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override TValue AdapterCall<TValue>(CommandPacket cmd, Func<RedisResult,
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down Expand Up @@ -136,7 +136,7 @@ public override Task<TValue> AdapterCallAsync<TValue>(CommandPacket cmd, Func<Re
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
}
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/FreeRedis/RedisClient/Adapter/SentinelAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public override TValue AdapterCall<TValue>(CommandPacket cmd, Func<RedisResult,
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
RecoverySentinel();
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public override Task<TValue> AdapterCallAsync<TValue>(CommandPacket cmd, Func<Re
catch (Exception ex)
{
var pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool;
if (pool?.SetUnavailable(ex, getTime) == true)
if (cmd.IsBlockingCommand() == false && pool?.SetUnavailable(ex, getTime) == true)
{
RecoverySentinel();
}
Expand Down

0 comments on commit 5e67d55

Please sign in to comment.