Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The SearchKeysAsync method does not behave as expected in the recent NuGet version 10.1.0. #586

Open
Madhushankha opened this issue Jan 17, 2024 · 2 comments

Comments

@Madhushankha
Copy link

Describe the bug

Update the StackExchange.Redis.Extensions.Core version from 9.1.0 to 10.1.0. However, the existing unit tests failed after the upgrade.

To Reproduce

Revert the NuGet package to version 9.1.0, debug the code to ascertain the count of keys matching a specific pattern, and confirm that it provides the accurate result. However, when using the newer version of the NuGet package, it consistently returns a count of 0 for keys matching the specified pattern.

Additional context

In the previous version 9.1.0, the code in RedisDatabase.cs at inside SearchKeysAsync method line 424 utilized the Database instance to execute a scan command:
var redisResult = await Database.ExecuteAsync("SCAN", nextCursor.ToString(), "MATCH", pattern, "COUNT", "1000").ConfigureAwait(false);

However, in the updated version, a modification is observed. Instead of using the Database instance, the code now employs an instance named unused within a loop iterating over servers:

var servers = ServerIteratorFactory
.GetServers(connectionPoolManager.GetConnection(), serverEnumerationStrategy)
.ToArray();

foreach (var unused in servers)
{
var redisResult = await unused.ExecuteAsync("SCAN", nextCursor.ToString(), "MATCH", pattern, "COUNT", "1000").ConfigureAwait(false);
// Additional code handling the redisResult may be present here.
}

@imperugo
Copy link
Owner

Hi @Madhushankha

first thanks for the feedback.
If I look the code now, it looks good to me and wrong the old version.

The scan now is executed only on the servers that have been retrieved from the enumerate strategy. If u use the Database.ExecuteAsync instead of unused.ExecuteAsync (I know that must be renamed with something that makes sense) there is no sense to iterate the servers.

@clinta74
Copy link

clinta74 commented Apr 9, 2024

I even found this is true with 10.2.0 as well.

Calling _redisClient.Db0.SearchKeysAsync("YourFirstKey") does return keys. But a second call _redisClient.Db0.SearchKeysAsync("YourSecondKey") returns no results.

If I call _redisClient.ExecuteAsync("SCAN", 0, "MATCH", "YourSecondKey", "COUNT", "1000") before I _redisClient.Db0.SearchKeysAsync("YourSecondKey") they both return the expected results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants