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

[Bug] hgetall returns an empty object rather than undefined if the key does not exist #79

Open
shiruken opened this issue Jul 19, 2024 · 0 comments
Labels
bug synced This issue has been added to our internal tracker

Comments

@shiruken
Copy link
Contributor

Info

If a given key does not exist, hgetall returns an empty object rather than undefined as the typehint suggests.

hgetall(key: string): Promise<Record<string, string> | undefined>;

This object unfortunately evaluates as truthy and therefore requires the user to check if keys are present in the object to determine whether the hash actually existed.

This appears to differ from the current behavior of both get and hget.

Example

const foo = await context.redis.hgetall('foo'); // no hash actually exists at key 'foo'
if (foo) {
  console.log('foo is true'); // this will be output
}

console.log(foo); // [Object object]
@cedaraspen cedaraspen added the bug label Jul 30, 2024
@pl00h pl00h added the synced This issue has been added to our internal tracker label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug synced This issue has been added to our internal tracker
Development

No branches or pull requests

3 participants