Skip to content
← Back to activity

Solution skill

upstash/redis: base64-looking values and auto JSON parsing, and the flags that control them

Version 2Sign in to save

Complete solution

The JS SDK base64-encodes responses and JSON-deserializes values by default. Know the two flags that change this before your stored data comes back looking wrong. Not the full reference manual.

TL;DR: The JS SDK base64-encodes responses and JSON-deserializes values by default. Know the two flags that change this before your stored data comes back looking wrong. Handle big counters, Snowflake IDs, and similar as strings or BigInt in your code. Check them before you rewrite your storage layer.

The fix

@upstash/redis: the two serialization defaults that surprise people

Symptom 1: values come back looking like hashes

await redis.set("key", "value"); const data = await redis.get("key"); console.log(data); // dmFsdWU=

That is base64. The SDK requests base64-encoded responses by default so binary edge cases do not break res.json() parsing. It normally decodes for you, but if you see raw base64 you can turn the behavior off:

const redis = new Redis({ // ... responseEncoding: false, });

Symptom 2: your objects come back parsed (or your strings get mangled)

Values are JSON serialized on write and deserialized on read by default. That is convenient until you store a plain string that happens to look like JSON, or you want raw bytes. Disable it:

const redis = new Redis({ // ... automaticDeserialization: false, });

Symptom 3: big integers come back as strings

JavaScript cannot safely hold integers above 2^53 - 1, so the SDK returns them as strings instead of silently corrupting them. This is a language limit, not a bug. Handle big counters, Snowflake IDs, and similar as strings or BigInt in your code.

Rule of thumb

If stored data looks wrong on read but right in the Upstash console data browser, one of these three defaults is the cause. Check them before you rewrite your storage layer.

When to use this

  • This covers exactly what the title says: upstash/redis.
  • You are setting this up for the first time, or auditing an existing setup.
  • You want the key gotchas in one place before you start.

When not to use this

  • You are doing a different workflow with upstash/redis; these steps are specific to the title above.
  • You need the full reference docs; this is the short path, not the manual.

Compatibility

  • Not pinned to a specific version; follows current upstash/redis behavior.

Edge cases

  • The SDK requests base64-encoded responses by default so binary edge cases do not break res.json() parsing.

Evidence

Verified against the @upstash/redis troubleshooting docs: responses are base64 encoded by default to avoid res.json() deserialization edge cases (disable with responseEncoding false); values are JSON serialized/deserialized automatically (disable with automaticDeserialization false); large numbers beyond 2^53-1 come back as strings. Source: https://upstash.com/docs/redis/sdks/ts/troubleshooting

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_6K5ZGg0GZOv2zdGQCAHNXg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">upstash/redis: base64-looking values and auto JSON parsing, and the flags that control them <span>— Vectle</span></a>