Base solution for your next web application
Open Closed

RedisOnlineClientStore.GetAllAsync returns clients with all properties null #12697


User avatar
0
saaspartners created

Package / version: Abp.RedisCache 11.0.0 and 11.1.0 (net10.0)

Description

When Redis is enabled with Configuration.Caching.UseRedis(...), IOnlineClientManager.GetAllClientsAsync() returns the right number of clients, but every one has all properties null (ConnectionId, IpAddress, TenantId, UserId, ConnectTime, …).

TryGetAsync, GetAllByUserIdAsync and TryRemoveAsync on the same store return correct data.

Steps to reproduce

  1. Enable Redis caching with Configuration.Caching.UseRedis(...), which registers RedisOnlineClientStore as IOnlineClientStore.
  2. Connect one or more SignalR clients so they are stored in the {OnlineClientsStoreKey}.Clients hash.
  3. Call IOnlineClientManager.GetAllClientsAsync().

Expected: each IOnlineClient has the values stored in Redis. Actual: each IOnlineClient has null or default values for every property.

Root cause In src/Abp.RedisCache/Runtime/Caching/Redis/RealTime/RedisOnlineClientStore.cs, GetAllAsync serializes the RedisValue struct itself rather than reading the JSON string stored in it:

public async Task<IReadOnlyList<IOnlineClient>> GetAllAsync() { return (await GetDatabase().HashGetAllAsync(_clientStoreKey).ConfigureAwait(false)) .Select(entry => JsonSerializer.Deserialize<OnlineClient>(entry.Value.ToJsonString())) .Cast<IOnlineClient>() .ToImmutableList(); } entry.Value.ToJsonString() produces JSON describing the RedisValue struct's own properties. Deserializing that into OnlineClient matches none of its properties, so every field stays null.

The other methods in the same class read the value correctly with .ToString(), for example in TryGetAsync:

var client = JsonSerializer.Deserialize<OnlineClient>(clientValue.ToString());

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for your report, we have fixed this bug and merged the pull request https://github.com/aspnetzero/aspnetboilerplate/pull/39. It will be in the next release of ASP.NET Boilerplate. In the meantime, you can replace RedisOnlineClientStore.cs with your own implementation.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)