-
Notifications
You must be signed in to change notification settings - Fork 85
feat: Мove creation of redis client outside of cache service #4409
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
feat: Мove creation of redis client outside of cache service #4409
Conversation
…#4398) Signed-off-by: nikolay <n.atanasow94@gmail.com>
…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>
7db1dd3
to
c32ceda
Compare
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>
* | ||
* @returns {Promise<void>} A Promise that resolves when the client is connected. | ||
*/ | ||
async connectRedisClient(): Promise<void> { |
There was a problem hiding this comment.
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
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
840a110
to
4066a23
Compare
…/transaction-pool
…/transaction-pool
* @returns {Promise<void>} A Promise that resolves when the cache is cleared. | ||
*/ | ||
async clear(): Promise<void> { | ||
await this.client.flushAll(); |
There was a problem hiding this comment.
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
There was a problem hiding this 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
…-client-outside-of-cache-service
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
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
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
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
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