Skip to content

haha-systems/demon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demon

A high-performance Zig client for the Phage key-value database. Demon provides both interactive (REPL) and command-line interfaces for connecting to Phage servers.

Features

  • Dual Interface: Interactive REPL mode or single command execution
  • Full Protocol Support: All Phage commands (SET, GET, DELETE, KEYS, PING, BENCHMARK)
  • ZeroMQ Networking: High-performance communication with Phage servers
  • Cross-platform: Works on Linux, macOS, and Windows

Installation

Prerequisites

  • Zig 0.11+
  • ZeroMQ library (libzmq)

Build

zig build

The executable will be created at zig-out/bin/demon.

Usage

Interactive Mode (REPL)

./zig-out/bin/demon

This starts an interactive session where you can type commands:

demon> SET mykey "hello world"
OK
demon> GET mykey
hello world
demon> DELETE mykey
OK
demon> PING
PONG
demon> exit

Command-line Mode

Execute single commands directly:

# Health check
./zig-out/bin/demon PING

# Store a value
./zig-out/bin/demon SET user:123 "Alice Johnson"

# Retrieve a value
./zig-out/bin/demon GET user:123

# Delete a key
./zig-out/bin/demon DELETE user:123

# Pattern matching
./zig-out/bin/demon KEYS "user:*"

# Performance testing
./zig-out/bin/demon BENCHMARK 1000

Supported Commands

Command Description Example
SET key value Store a key-value pair SET name "John"
GET key Retrieve value for key GET name
DELETE key Remove a key DELETE name
KEYS pattern Find keys matching pattern KEYS "user:*"
PING Health check PING
BENCHMARK n Run performance test BENCHMARK 1000

Pattern Matching

The KEYS command supports pattern matching:

  • * matches any characters
  • user:* matches all keys starting with "user:"
  • *:profile matches all keys ending with ":profile"

Configuration

Demon connects to tcp://localhost:5555 by default. To connect to a different Phage server, modify the connection string in src/main.zig.

Examples

Batch Operations

# Store multiple users
./demon SET user:1 "Alice"
./demon SET user:2 "Bob" 
./demon SET user:3 "Charlie"

# Find all users
./demon KEYS "user:*"

# Performance test
./demon BENCHMARK 10000

Integration with Scripts

#!/bin/bash
# Health check script
if ./demon PING > /dev/null 2>&1; then
    echo "Phage server is healthy"
    exit 0
else
    echo "Phage server is down"
    exit 1
fi

Development

Project Structure

  • src/main.zig - Main application and CLI handling
  • src/root.zig - Core client library
  • build.zig - Build configuration
  • build.zig.zon - Dependencies

Dependencies

  • zimq - ZeroMQ bindings for Zig

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

  • Phage - The high-performance key-value database server

About

High-performance Zig client for Phage key-value database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •