Skip to content

Conversation

konstantinabl
Copy link
Contributor

@konstantinabl konstantinabl commented Sep 24, 2025

Description

This PR's goal to move the redis client creation out of the RedisCache class, since the client will be reused to connect to Redis for out Transaction Pool feature. On top of this, RedisCache's main purpose is to handle operations for get,set, delete etc from Redis, not maintaining the client.

Related issue(s)

Fixes #4387

Changes from original design (optional)

In our original design, the creation of the redis client and the maintenance of the connection was handled in the Redis Cache class, which breaks the first SOLID principle. Now the creation of the client and the connection is moved to a RedisClientManager class, which will manage the client and any operations on it. All client related methods are removed from RedisCache and CacheService classes.

Notes for Reviewer

  1. We always pass a connected client, so there is no need to re-check here
    https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/4409/files#diff-244a262ac886fc247f5483123909ff160f65a2acfe6957f1a5b35d58453b725eL307

  2. Redis may not be enabled, then the redisClient will be undefined and we need to switch to LRU cache
    https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/4409/files#diff-6885de8b57b52c8ab19662969cbcf2d242b9944777fe284d756168a2af093d0dR93

  3. These methods have been deleted, since they were only ever used in tests, which is not a good practice
    https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/4409/files#diff-6885de8b57b52c8ab19662969cbcf2d242b9944777fe284d756168a2af093d0dL127

  4. These tests have been deleted because they belong in the test file for the new RedisClientManager
    https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/4409/files#diff-7aaa58f003fccbb2493cf321726c1878a5532f99de9148f2876aae60978722ceL226
    https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/4409/files#diff-7aaa58f003fccbb2493cf321726c1878a5532f99de9148f2876aae60978722ceL499

Additional work needed (optional)

N/A

Checklist

  • I've assigned an assignee to this PR and related issue(s) (if applicable)
  • I've assigned a label to this PR and related issue(s) (if applicable)
  • I've assigned a milestone to this PR and related issue(s) (if applicable)
  • I've updated documentation (code comments, README, etc. if applicable)
  • I've done sufficient testing (unit, integration, etc.)

natanasow and others added 7 commits September 23, 2025 16:41
…olService` interface (#4405)

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
@konstantinabl konstantinabl force-pushed the 4387-move-creation-of-redis-client-outside-of-cache-service branch from 7db1dd3 to c32ceda Compare September 24, 2025 15:44
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
@konstantinabl konstantinabl self-assigned this Sep 29, 2025
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
*
* @returns {Promise<void>} A Promise that resolves when the client is connected.
*/
async connectRedisClient(): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are deleted, since they were only used in tests

@konstantinabl konstantinabl added the internal For changes that affect the project's internal workings but not its outward-facing functionality. label Sep 29, 2025
@konstantinabl konstantinabl added this to the 0.72.0 milestone Sep 29, 2025
@konstantinabl konstantinabl marked this pull request as ready for review September 29, 2025 12:55
@konstantinabl konstantinabl requested review from a team as code owners September 29, 2025 12:55
@konstantinabl konstantinabl changed the title Мove creation of redis client outside of cache service feat: Мove creation of redis client outside of cache service Sep 30, 2025
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
* @returns {Promise<void>} A Promise that resolves when the cache is cleared.
*/
async clear(): Promise<void> {
await this.client.flushAll();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the PR, but using flushAll could be dangerous, as it might also delete data related to rate limiting, transaction pool, etc. Perhaps we should look into that

Copy link
Contributor

@simzzz simzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left one unrelated concern

@konstantinabl konstantinabl merged commit ef7f6bd into feat/transaction-pool Oct 1, 2025
5 checks passed
@konstantinabl konstantinabl deleted the 4387-move-creation-of-redis-client-outside-of-cache-service branch October 1, 2025 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal For changes that affect the project's internal workings but not its outward-facing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants