redis / node-redis

Redis Node.js client
https://redis.js.org/
MIT License
16.95k stars 1.89k forks source link

feat: add credentialProvider option when creating clients #2849

Open dhensby opened 1 month ago

dhensby commented 1 month ago

Description

In some instances, credentials for the redis client will be short-lived and need to be fetched on-demand when connecting to redis. This is the case when connecting in AWS using IAM authentication or Entra ID in Azure.

This feature allows for a credentialProvider to be provided which is a callable function returning a Promise that resolves to a username/password object.

Closes #821

A potential enhancement to this feature could be to also return a TTL with the credentials and then automatically attempt to re-auth the client before the credentials expire; however I've assumed that logic will be the responsibility of the consumer rather than the library. Worst case scenario is that the socket disconnects due to authentication error and then re-authenticates on a future reconnection retry attempt.

Something else that is missing is an explicit decision on how errors from the credentialProvider should be surfaced.


Checklist