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

Aperta
#79 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
redis, typescript
Ambito
databases

Direzione di ricerca

Start with packages/public-api/src/types/redis.ts at the hgetall declaration and trace the corresponding implementation and tests. Reproduce the missing-key case described in the issue, then verify that hgetall returns undefined consistently with the stated typehint and the existing get and hget behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Info

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

https://github.com/reddit/devvit/blob/fb29ce4fb63b82bc0d8b91f9a6c0c76688d6ae02/packages/public-api/src/types/redis.ts#L511

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]

Lingua principale
TypeScript
Stelle
210
Fork
88
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di reddit/devvit

Tutte le issue di reddit/devvit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.