respx

module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0

README

Redis compatible server implemented with buntdb

GitHub Go Reference report Build coverage

Features

respx is an embedded, high-performance Document DB with a Redis-compatible API. It seamlessly blends standard Redis Key-Value operations with advanced MongoDB-style JSON querying capabilities.

1. Native Redis Commands

respx natively supports a subset of standard Redis commands, allowing you to drop it into existing ecosystems with minimal friction:

  • Connection Management: AUTH, HELLO, PING, QUIT, CLIENT
  • Key-Value Operations: SET, SETEX, SETNX, GET, DEL, KEYS
  • Pub/Sub: PUBLISH, SUBSCRIBE, PSUBSCRIBE

2. Extend (X) Commands

The true power of respx lies in its extended document querying capabilities. By treating stored strings as JSON documents and defining schemas with indexes, you can perform complex queries using a declarative DSL.

BYINDEX

Performs a MongoDB-style query on a specific JSON index.

Syntax:

BYINDEX <schema_name> <index_attribute> <json_filter> [ASC|DESC]
  • schema_name: The logical namespace of the data (e.g., user).
  • index_attribute: The JSON path used as the driving index for the query (e.g., email, age).
  • json_filter: A MongoDB-style JSON string defining the composite filtering conditions.
  • [ASC|DESC]: Optional order direction. Default is ASC.
BYKEY

Performs a MongoDB-style query over keys matching a glob pattern within a schema.

Syntax:

BYKEY <schema_name> <pattern> <json_filter> [ASC|DESC]
  • schema_name: The logical namespace of the data (e.g., user).
  • pattern: A BuntDB glob pattern to match the keys (e.g., *, 123*).
  • json_filter: A MongoDB-style JSON string defining the composite filtering conditions.
  • [ASC|DESC]: Optional order direction. Default is ASC.
Examples & Client Usage

respx provides a powerful, fluent Go client that automatically translates your Go code into the underlying JSON query expressions.

1. Simple Equality Match

Find a user whose email is exactly ken@example.com.

Raw Redis Command:

BYINDEX user email {"email": {"$eq": "ken@example.com"}}
// or simply
BYINDEX user email {"email": "ken@example.com"}

Go Client (client.ByIndex):

import (
    "github.com/kcmvp/respx/client"
    "github.com/kcmvp/respx/x"
)

res := client.ByIndex("user", "email", x.Eq("email", "ken@example.com"), false)
users := res.MustGet()
2. Range Query (Greater Than)

Find users whose age is greater than 18.

Raw Redis Command:

BYINDEX user age {"age": {"$gt": 18}}

Go Client:

res := client.ByIndex("user", "age", x.Gt("age", 18), false)
3. Composite Query (Logical AND)

Find users whose age is greater than 18 AND status is "active".

Raw Redis Command:

BYINDEX user age {"$and": [{"age": {"$gt": 18}}, {"status": "active"}]}

Go Client:

res := client.ByIndex("user", "age", x.And(
    x.Gt("age", 18),
    x.Eq("status", "active"),
), false)
4. Complex Nested Query (AND + OR)

Find users who are either (age < 20) OR (age > 18 AND status is "active").

Raw Redis Command:

BYINDEX user age {"$or": [
    {"age": {"$lt": 20}},
    {"$and": [{"age": {"$gt": 18}}, {"status": "active"}]}
]}

Go Client:

res := client.ByIndex("user", "age", x.Or(
    x.Lt("age", 20),
    x.And(
        x.Gt("age", 18),
        x.Eq("status", "active"),
    ),
), false)

Installation

go get github.com/kcmvp/respx

Directories

Path Synopsis
x

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL