Skip to content
Software capabilities
Upstash Redis

Read one Upstash Redis string key

Upstash supports a non-mutating GET through its serverless SDK or native Redis protocol. Use the SDK for serverless JavaScript and redis-cli for a direct TLS terminal connection.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. SDK: @upstash/redis Redis.fromEnv().get
  2. CLI: redis-cli --tls get
SDK

@upstash/redis Redis.fromEnv().get

Create the serverless Redis client from UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN, then call get for one key.

Read source: Upstash Redis GET command
Requirements
A provisioned Upstash Redis database and the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN environment variables.
Limitations
GET returns null when a key does not exist and errors when the key contains a non-string type such as a hash or list.

Example text

import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();
const value = await redis.get("profile:42");
CLI

redis-cli --tls get

Connect over Upstash's native Redis TCP protocol with TLS and issue the GET command from a terminal.

Read source: Upstash redis-cli connection guide
Requirements
redis-cli installed, the Upstash endpoint, port, and token from the database Details tab, and TLS enabled with --tls or a rediss:// URL.
Limitations
Upstash requires TLS on every database. Omitting --tls or using redis:// causes the connection to fail.

Example shell

REDISCLI_AUTH="$UPSTASH_REDIS_TOKEN" redis-cli --tls -h "$UPSTASH_REDIS_ENDPOINT" -p "$UPSTASH_REDIS_PORT" get profile:42