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

[redis] support preConnect option #469

Open
olivbau opened this issue Jul 30, 2024 · 4 comments
Open

[redis] support preConnect option #469

olivbau opened this issue Jul 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@olivbau
Copy link

olivbau commented Jul 30, 2024

Environment

Unstorage v1.10.2

Reproduction

  1. Create a Driver or Storage object without manually calling getRedisClient().
  2. Attempt to call setItem or getItem.

Describe the bug

The Redis instance is initialized only when the getRedisClient() function is called. However, getRedisClient() is never invoked during the creation of the Driver or the Storage objects. As a result, the first call to getRedisClient() occurs only when setItem or getItem is called.

This causes an issue where the Redis instance is created and attempts to get or set an item, but the ioredis instance has not yet established a connection to the Redis server.

Expected Behavior

The Redis instance should be initialized and connected to the Redis server before any get or set operations are performed.

Actual Behavior

The Redis instance is created at the time of the first setItem or getItem call, and the ioredis instance is not yet connected.

Possible Solution

Ensure that the getRedisClient() function is called after beeing defined to establish a connection to the Redis server before any operations are performed.
From what I can see, it seems to be same for Mongodb

Additional context

No response

Logs

No response

@olivbau olivbau added the bug Something isn't working label Jul 30, 2024
@GalacticHypernova
Copy link
Contributor

This is not a bug, it's expected behavior
image

@pi0
Copy link
Member

pi0 commented Dec 5, 2024

Indeed it is intended for perf, an im not sure what issue it is causing.

But we can introduce a preconnect: true driver option to allow this.

@olivbau
Copy link
Author

olivbau commented Dec 6, 2024

This would be useful for 2 reasons:

  1. To know that the connection information is not good directly at launch or that the Redis server is unreachable.
  2. Gain performance on the first call

@pi0
Copy link
Member

pi0 commented Dec 6, 2024

Alternative is that you do a getItem as healthcheack on server startup. (this, also allows you to directly catch errors instead of relying on global rejection)

PR is still welcome 🙏

@pi0 pi0 changed the title Redis driver is coded in way that it's lazyConnect [redis] support preConnect option Dec 18, 2024
@pi0 pi0 added enhancement New feature or request and removed bug Something isn't working labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants