Disable automatic serialization

Your data is (de)serialized as json by default. This works for most use cases but you can disable it if you want:

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

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

This probably breaks quite a few types, but it’s a first step in that direction. Please report bugs and broken types here.

keepalive

@upstash/redis is capable of reusing connections where possible to minimize latency. Connections can be reused if the client is stored in memory and not initialized with every new function invocation. The easiest way to achieve this is by creating the client outside of your handler and adding an https agent:

// Nextjs api route
import { Redis } from "@upstash/redis";
import https from "https";

const redis = Redis.fromEnv({
  agent: new https.Agent({ keepAlive: true }),
});

export default async function (req, res) {
  // use redis here
}

Whenever your hot lambda receives a new request the client is already initialized and the previously established connection to upstash is reused.