# `query.redis_unsupported`

A query reads an entity kept in Redis in a way only a database can serve, such as a range, an `include` or an order.

Area 6, [Reads and writes](/docs/reads-and-writes.md); not declinable; the next step is usually the human's.

## Why Jadpo refuses it

Redis keeps no indexes of its own. Jadpo finds a record there by its
`id`, by the key it keeps for each value of a field with `unique: true`,
or, for a field `indexes:` lists, by the set it keeps for each value,
which gives a page in creation order and its `count()`. A query that
asks anything else, a range, `in`, `or`, an `order:`, an `include:`,
`matches`, a search inside text or a `geo.` test, would have to read
every record, and Redis keeps no list of them.

## What it looks like

`app.jadpo` declares `drafts`, a Redis connection:



domains/accounts/entities/sign_up_draft.jadpo:

```jadpo
use accounts/types { Attempts }

/// A sign-up someone has started and not yet finished.
entity SignUpDraft {
    id: Uuid
    email: Email
    attempts: Attempts

    store: drafts
    expires_after: 2h
    indexes: {
        by_attempts: [attempts]
    }
}
```

domains/accounts/queries/locked_out.jadpo:

```jadpo
use accounts/entities { SignUpDraft }

/// The sign-ups that have used up their tries.
query locked_out() -> List<SignUpDraft> {
    from: SignUpDraft
    where: SignUpDraft.attempts >= 5
    limit: 50
}
```

```text
error: `locked_out` reads `SignUpDraft`, kept in Redis, with a range
 --> domains/accounts/queries/locked_out.jadpo:6:5
  |
6 |     where: SignUpDraft.attempts >= 5
  |     ^^^^^ only a database can
  reason: `drafts` is a Redis connection. Redis keeps no order of a field's values, only a set for each one, so it finds records holding a value and nothing between two. A query of an entity in Redis finds records by `id`, by a field with `unique: true`, or by `==` on one field `indexes:` lists, a page in creation order or its `count()`.
  next: Keep `SignUpDraft` in a PostgreSQL store, or find its records by `id`, a unique field or an indexed one (human)
  rule: query.redis_unsupported
  help: https://jadpo.dev/docs/errors/query.redis_unsupported

check failed: 1 error, 4 files
```

A search inside text reads a trigram index, which Redis doesn't keep
either:



domains/accounts/queries/drafts_from.jadpo:

```jadpo
use accounts/entities { SignUpDraft }

/// The sign-ups whose address holds what someone typed.
query drafts_from(part: SignUpDraft.email) -> List<SignUpDraft> {
    from: SignUpDraft
    where: text.contains_ignoring_case(SignUpDraft.email, part)
    limit: 50
}
```

```text
error: `drafts_from` reads `SignUpDraft`, kept in Redis, with a search inside text, `text.contains_ignoring_case`
 --> domains/accounts/queries/drafts_from.jadpo:6:5
  |
6 |     where: text.contains_ignoring_case(SignUpDraft.email, part)
  |     ^^^^^ only a database can
  reason: `drafts` is a Redis connection. A search inside text reads a trigram index, which only PostgreSQL keeps. A query of an entity in Redis finds records by `id`, by a field with `unique: true`, or by `==` on one field `indexes:` lists, a page in creation order or its `count()`.
  next: Keep `SignUpDraft` in a PostgreSQL store, or find its records by `id`, a unique field or an indexed one (human)
  rule: query.redis_unsupported
  help: https://jadpo.dev/docs/errors/query.redis_unsupported

check failed: 1 error, 3 files
```

`(human)` at the end of the `next:` line tells your coding agent to stop
and ask you which fix you want, because the choice is yours to make: it
decides where the records are kept, and which of them the query finds.

## How to fix it

**If the records belong in a database**, keep the entity there, and the
query reads them as it is:

```jadpo
entity SignUpDraft {
    id: Uuid
    email: Email
    attempts: Attempts
}
```





The range is now one `WHERE` in PostgreSQL.

**If they stay in Redis**, test one value with `==`, which the set Jadpo
keeps for each value of `attempts` serves:

```jadpo
query locked_out() -> List<SignUpDraft> {
    from: SignUpDraft
    where: SignUpDraft.attempts == 5
    limit: 50
}
```






The query now reads the sign-ups that have tried exactly five codes, in
the order they were made.

## Related

- [Reading and writing entities in Redis](/docs/queries-on-entities-in-redis.md)
- [`data.redis_unsupported`](/docs/errors/data.redis_unsupported.md)
