# ZINTER

> Get sorted set intersection.

Use `ZINTER` to get the members that appear in every one of the given sorted sets.

`<numkeys>` states how many keys follow. By default the score of each member in the result is the sum of its scores across all the inputs, which is what makes intersections useful for combining rankings. `WEIGHTS` multiplies each input's scores by a factor before they are combined, so one source can count more than another, and `AGGREGATE` replaces the sum with `MIN` or `MAX`. `WITHSCORES` returns the computed scores along with the members.

The result is not stored; use [`ZINTERSTORE`](/redis/commands/sorted-set/zinterstore) to keep it or [`ZINTERCARD`](/redis/commands/sorted-set/zintercard) when only the size matters.

## Syntax

```redis
ZINTER <numkeys> <key> [<key> ...]
  [WEIGHTS <weight> [<weight> ...]]
  [AGGREGATE SUM | MIN | MAX]
  [WITHSCORES]
```

## Arguments

| Argument | Required | Repeatable | Description |
| --- | --- | --- | --- |
| `<numkeys>` | Yes | No | Number of key arguments that follow. |
| `<key>` | Yes | Yes | Redis key targeted by the command. |
| `WEIGHTS <weight>` | No | Yes | Multiplier applied to each input key's scores, in the order the keys were given. |
| `(AGGREGATE SUM \| MIN \| MAX)` | No | No | Under `AGGREGATE`, choose one form: `SUM`; `MIN`; `MAX`. |
| `WITHSCORES` | No | No | Include sorted-set scores. |

## Important points

- `numkeys` must equal the number of key arguments that immediately follow it.
- Pair-based results may be flattened into one alternating array in RESP2 while RESP3 preserves nested pairs or a map.
- RESP2 represents floating-point reply values as bulk strings; RESP3 may use native double replies. Client libraries commonly decode either form to a language number.

## Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

| Protocol | Reply |
| --- | --- |
| RESP2 | Array of members, or flat member/score array with `WITHSCORES` |
| RESP3 | Array of members, or array of member/score pairs with `WITHSCORES` |

<Note>
  Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
</Note>

## Examples

TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

<AccordionGroup>

<Accordion title="Redis CLI" icon="terminal">

```bash
ZINTER 1 my-key
```

</Accordion>

<Accordion title="@upstash/redis" icon="node-js" iconType="brands">

<Note>
  This command is not supported yet in `@upstash/redis`.
</Note>

</Accordion>

<Accordion title="upstash_redis" icon="python" iconType="brands">

```python
from upstash_redis import Redis

redis = Redis.from_env()
result = redis.zinter(["my-key"])
print(result)
```

</Accordion>

<Accordion title="ioredis" icon="node-js" iconType="brands">

```ts
import Redis from "ioredis";

const redis = new Redis(process.env.REDIS_URL!);
const result = await redis.zinter("1", "my-key");
console.log(result);
```

</Accordion>

<Accordion title="node-redis" icon="node-js" iconType="brands">

```ts
import { createClient } from "redis";

const client = await createClient({ url: process.env.REDIS_URL })
  .on("error", console.error)
  .connect();
const result = await client.zInter("my-key");
console.log(result);
```

</Accordion>

<Accordion title="redis-py" icon="python" iconType="brands">

```python
import os
import redis

client = redis.from_url(os.environ["REDIS_URL"])
result = client.zinter(["my-key"])
print(result)
```

</Accordion>

<Accordion title="go-redis" icon="golang" iconType="brands">

```go
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/redis/go-redis/v9"
)

func main() {
    opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
    if err != nil {
        panic(err)
    }
    client := redis.NewClient(opts)
    result, err := client.ZInter(context.Background(), &redis.ZStore{Keys: []string{"my-key"}}).Result()
    if err != nil {
        panic(err)
    }
    fmt.Println(result)
}
```

</Accordion>

<Accordion title="jedis" icon="java" iconType="brands">

```java
import java.net.URI;

import redis.clients.jedis.Jedis;

try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
  Object result = jedis.zinter(new redis.clients.jedis.params.ZParams(), "my-key");
  System.out.println(result);
}
```

</Accordion>

<Accordion title="redis-rs" icon="rust" iconType="brands">

```rust
fn main() -> redis::RedisResult<()> {
    let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
    let client = redis::Client::open(url)?;
    let mut connection = client.get_connection()?;

    let mut command = redis::cmd("ZINTER");
    command.arg("1");
    command.arg("my-key");
    let result: redis::Value = command.query(&mut connection)?;
    println!("{result:?}");
    Ok(())
}
```

</Accordion>

</AccordionGroup>
