Redis Protocol Examples

This document provides examples for using the ChronDB Redis protocol interface with redis-cli and JavaScript.

Redis Protocol Overview

ChronDB implements a subset of the Redis protocol, allowing you to connect using standard Redis clients. This makes it easy to integrate with existing applications that already use Redis or to leverage the simplicity of the Redis command structure.

The Redis protocol server can be configured in the config.edn file:

:servers {
  :redis {
    :enabled true
    :host "0.0.0.0"
    :port 6379
  }
}

Standard Redis Commands

ChronDB supports the following standard Redis commands:

  • GET - Retrieve a document

  • SET - Create or update a document

  • DEL - Delete a document

  • EXISTS - Check if a document exists

  • KEYS - List keys matching a pattern

  • HGET - Get a specific field from a document

  • HSET - Set a specific field in a document

  • HDEL - Remove a specific field from a document

  • HGETALL - Get all fields from a document

ChronDB-Specific Commands

In addition to standard Redis commands, ChronDB provides special commands:

  • CHRONDB.HISTORY - Get document history

  • CHRONDB.GETAT - Get document at a point in time

  • CHRONDB.DIFF - Compare document versions

  • CHRONDB.BRANCH.LIST - List branches

  • CHRONDB.BRANCH.CREATE - Create a new branch

  • CHRONDB.BRANCH.CHECKOUT - Switch to a branch

  • CHRONDB.BRANCH.MERGE - Merge branches

Schema Validation Commands

  • SCHEMA.SET namespace schema [MODE strict|warning] - Create or update a validation schema

  • SCHEMA.GET namespace - Get a validation schema

  • SCHEMA.DEL namespace - Delete a validation schema

  • SCHEMA.LIST - List all validation schemas

  • SCHEMA.VALIDATE namespace document - Validate a document without saving

Examples with redis-cli

Connecting to ChronDB

Document Operations

Working with Document Fields

Searching for Documents

Version Control Commands

Branch Operations

Examples with JavaScript

Setting Up

The following examples use the standard redisarrow-up-right package for Node.js.

Document Operations

Working with Document Fields (Hash Operations)

Searching for Documents

Version Control Operations

Branch Operations

Schema Validation Examples

ChronDB supports optional JSON Schema validation per namespace. See the Schema Validation documentation for full details.

Validation with redis-cli

Validation with JavaScript

Complete Example: Inventory Tracking System

Last updated