← Files Upstash RedisARCHIVED FILE

skills/upstash-redis-js/search/adapters.md

2.83 KB · Oct 3, 2026 · 06:22 UTC

↓ Download file

# Adapters

## Overview

`@upstash/redis` works over HTTP, which is ideal for serverless environments. If you need TCP-based connections (e.g., long-running servers with `redis` or `ioredis`), use the adapter packages `@upstash/search-redis` and `@upstash/search-ioredis`. They provide the exact same search API.

## Packages

| Package                   | Client     | Protocol  | Install                                       |
| ------------------------- | ---------- | --------- | --------------------------------------------- |
| `@upstash/redis`          | Built-in   | HTTP/REST | `npm install @upstash/redis`                  |
| `@upstash/search-redis`   | node-redis | TCP       | `npm install @upstash/search-redis redis`     |
| `@upstash/search-ioredis` | ioredis    | TCP       | `npm install @upstash/search-ioredis ioredis` |

## Examples

### With @upstash/redis (HTTP)

```typescript
import { Redis, s } from "@upstash/redis";

const redis = Redis.fromEnv();

const index = await redis.search.createIndex({
  name: "products",
  prefix: "product:",
  dataType: "json",
  schema: s.object({ name: s.string(), price: s.number("F64") }),
});

const results = await index.query({
  filter: { name: { $eq: "laptop" } },
  select: { name: true, price: true },
});
```

### With node-redis (TCP)

```typescript
import { createClient } from "redis";
import { createSearch, s } from "@upstash/search-redis";

const client = createClient({ url: process.env.REDIS_URL });
await client.connect();

const search = createSearch(client);

const index = await search.createIndex({
  name: "products",
  prefix: "product:",
  dataType: "json",
  schema: s.object({ name: s.string(), price: s.number("F64") }),
});

const results = await index.query({
  filter: { name: { $eq: "laptop" } },
  select: { name: true, price: true },
});

await client.disconnect();
```

### With ioredis (TCP)

```typescript
import IORedis from "ioredis";
import { createSearch, s } from "@upstash/search-ioredis";

const ioredis = new IORedis(process.env.REDIS_URL);

const search = createSearch(ioredis);

const index = await search.createIndex({
  name: "products",
  prefix: "product:",
  dataType: "json",
  schema: s.object({ name: s.string(), price: s.number("F64") }),
});

const results = await index.query({
  filter: { name: { $eq: "laptop" } },
  select: { name: true, price: true },
});

await ioredis.disconnect();
```

## API Parity

All three packages expose identical search APIs:

- `search.createIndex()` / `createSearch(client).createIndex()`
- `search.index()` / `createSearch(client).index()`
- `search.alias.list()`, `search.alias.add()`, `search.alias.delete()`
- `index.query()`, `index.aggregate()`, `index.count()`
- `index.describe()`, `index.drop()`, `index.waitIndexing()`
- `index.addAlias()`

The only difference is initialization. The `s` schema builder is re-exported from all packages.

SHA-256: 27e86405a147b6ac80b60322dc4b4752458a7c8cdb94437c9d2e9467151d6f4b