Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ Optional: `-gossip-secret <key>`.
### CLI (`sc`)

```bash
# With supercache-node running on defaults (-demo-keyspace: demo + tags + board + profile + doc + flags + embeddings):
# With supercache-node running on defaults (keyspace name = lowercase mode):
go run ./cmd/sc put greeting "hello"
go run ./cmd/sc get greeting
go run ./cmd/sc del greeting
go run ./cmd/sc -keyspace tags sadd features dark_mode
go run ./cmd/sc -keyspace tags sismember features dark_mode
go run ./cmd/sc -keyspace board zadd lb 100 alice
go run ./cmd/sc -keyspace board zrange lb 0 -1
go run ./cmd/sc -keyspace set sadd features dark_mode
go run ./cmd/sc -keyspace set sismember features dark_mode
go run ./cmd/sc -keyspace zset zadd lb 100 alice
go run ./cmd/sc -keyspace zset zrange lb 0 -1
go run ./cmd/sc -keyspace places geoadd city -74 40.7 shop
go run ./cmd/sc -keyspace places georadius city -74 40.7 20000 10
go run ./cmd/sc -keyspace inbox rpush q event1
go run ./cmd/sc -keyspace inbox lrange q 0 -1
go run ./cmd/sc -keyspace profile hset user email a@b
go run ./cmd/sc -keyspace profile hgetall user
go run ./cmd/sc -keyspace hash hset user email a@b
go run ./cmd/sc -keyspace hash hgetall user
# ModeCounter (register a ModeCounter keyspace; not in -demo-keyspace):
# go run ./cmd/sc -keyspace rl incr alice:1
go run ./cmd/sc -keyspace doc jsonset user $.name '"Ada"'
go run ./cmd/sc -keyspace doc jsonget user $.name
go run ./cmd/sc -keyspace flags bitset seen 0 1
go run ./cmd/sc -keyspace flags bitget seen 0
go run ./cmd/sc -keyspace embeddings vadd products east 1,0
go run ./cmd/sc -keyspace embeddings vadd products north 0,1
go run ./cmd/sc -keyspace embeddings vadd products ne 0.7,0.7
go run ./cmd/sc -keyspace embeddings vcard products
go run ./cmd/sc -keyspace embeddings vsim products 1,0.05 3
go run ./cmd/sc -keyspace json jsonset user $.name '"Ada"'
go run ./cmd/sc -keyspace json jsonget user $.name
go run ./cmd/sc -keyspace bitmap bitset seen 0 1
go run ./cmd/sc -keyspace bitmap bitget seen 0
go run ./cmd/sc -keyspace vectorset vadd products east 1,0
go run ./cmd/sc -keyspace vectorset vadd products north 0,1
go run ./cmd/sc -keyspace vectorset vadd products ne 0.7,0.7
go run ./cmd/sc -keyspace vectorset vcard products
go run ./cmd/sc -keyspace vectorset vsim products 1,0.05 3
go run ./cmd/sc -keyspace seen bloom add users alice # ModeBloom keyspace
# ModeTopK (register a ModeTopK keyspace, or use examples/billboard plays/hot):
# go run ./cmd/sc -keyspace plays topkadd hot t001
Expand Down Expand Up @@ -140,7 +140,7 @@ See [examples/billboard/README.md](./examples/billboard/README.md). Official cha
go run ./examples/hash # 3-node in-process walkthrough (HSet/HGet/HDel, concurrent fields)
```

See [examples/hash/README.md](./examples/hash/README.md). `sc -keyspace profile` talks to the node demo keyspace.
See [examples/hash/README.md](./examples/hash/README.md). `sc -keyspace hash` talks to the node demo keyspace.

### ModeCounter rate limiter

Expand All @@ -156,15 +156,15 @@ See [examples/ratelimit/README.md](./examples/ratelimit/README.md).
go run ./examples/json # 3-node in-process walkthrough (path set/get/del)
```

See [examples/json/README.md](./examples/json/README.md). `sc -keyspace doc` talks to the node demo keyspace.
See [examples/json/README.md](./examples/json/README.md). `sc -keyspace json` talks to the node demo keyspace.

### ModeBitmap packed bits

```bash
go run ./examples/bitmap # 3-node in-process walkthrough (BitSet/BitGet/BitCount/BitPos)
```

See [examples/bitmap/README.md](./examples/bitmap/README.md). `sc -keyspace flags` talks to the node demo keyspace.
See [examples/bitmap/README.md](./examples/bitmap/README.md). `sc -keyspace bitmap` talks to the node demo keyspace.

### ModeHLL approximate distinct count

Expand Down Expand Up @@ -213,7 +213,7 @@ Apps: `client.DialTLS` with `pkg/tlsconfig.ClientFiles`. See [docs/OPERATIONS.md
| `pkg/warmup` | Hot keys, topology handoff (hot then rest), refresh-ahead |
| `pkg/client` | Application gRPC client (KV + Bloom + Set + ZSet + Geo + List + Hash + Counter + JSON + Bitmap + HLL + TopK) |
| `pkg/tlsconfig` | TLS/mTLS config from PEM files |
| `cmd/supercache-node` | Node binary (`-demo-keyspace`: demo / tags / board / profile / doc / flags / embeddings) |
| `cmd/supercache-node` | Node binary (`-demo-keyspace`: cacheonly / set / zset / hash / json / bitmap / vectorset) |
| `cmd/sc` | CLI: get/put/del, bloom, sadd*, z*, geo*, l*, h*, incr/cget, json*, bit*, hlladd/hllcount, topkadd/topklist, admin diagnostics |
| `cmd/scbench` | SuperCache vs Redis load harness + in-process matrix |

Expand Down
12 changes: 6 additions & 6 deletions cmd/sc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func run(args []string) int {
var (
addr = fs.String("addr", envOr("SC_ADDR", "127.0.0.1:9000"), "cache gRPC seed(s), comma-separated (app port, not peer)")
admin = fs.String("admin", envOr("SC_ADMIN", "127.0.0.1:8080"), "admin HTTP seed(s), comma-separated")
keyspace = fs.String("keyspace", envOr("SC_KEYSPACE", "demo"), "default keyspace")
keyspace = fs.String("keyspace", envOr("SC_KEYSPACE", "cacheonly"), "default keyspace")
timeout = fs.Duration("timeout", 5*time.Second, "per-request timeout")
ttl = fs.Duration("ttl", 0, "TTL for put (0 + -no-expiry = never expire)")
noExpiry = fs.Bool("no-expiry", false, "put with TTL=0 (no expiry)")
Expand Down Expand Up @@ -382,16 +382,16 @@ Environment: SC_ADDR, SC_ADMIN, SC_KEYSPACE, SC_TLS_CA, SC_TLS_CERT, SC_TLS_KEY,
Examples:
sc put greeting "hello world"
sc get greeting
sc -keyspace tags sadd features dark_mode
sc -keyspace tags sismember features dark_mode
sc -keyspace board zadd lb 100 alice
sc -keyspace board zrange lb 0 -1
sc -keyspace set sadd features dark_mode
sc -keyspace set sismember features dark_mode
sc -keyspace zset zadd lb 100 alice
sc -keyspace zset zrange lb 0 -1
sc -addr 127.0.0.1:9000,127.0.0.1:9010,127.0.0.1:9020 ping
sc -admin 127.0.0.1:8081,127.0.0.1:8082 peers
sc # REPL
sc> put k v
sc> get k
sc> keyspace demo
sc> keyspace cacheonly
sc> quit
`)
}
2 changes: 1 addition & 1 deletion cmd/scbench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Do **not** compare 3-node SuperCache to 1 Redis and call it “faster.”
# Prefer native Redis for fairness
redis-server --port 6379 --save "" --appendonly no

# SuperCache (demo keyspace = CacheOnly "demo")
# SuperCache (demo keyspace = CacheOnly "cacheonly")
go run ./cmd/supercache-node \
-cache 127.0.0.1:9000 -peer 127.0.0.1:9001 -admin 127.0.0.1:8080
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/scbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
warmup = flag.Duration("warmup", 5*time.Second, "warmup before each trial (discarded)")
trials = flag.Int("trials", 5, "independent measure trials; report median")
readRatio = flag.Float64("read-ratio", 0.95, "GET fraction in mixed mode")
keyspace = flag.String("keyspace", "demo", "SuperCache keyspace")
keyspace = flag.String("keyspace", "cacheonly", "SuperCache keyspace")
prefix = flag.String("prefix", "scbench:", "key prefix")
prefill = flag.Bool("prefill", true, "prefill before get/mixed")
dist = flag.String("dist", "uniform", "uniform | zipf")
Expand Down
45 changes: 30 additions & 15 deletions cmd/supercache-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
gossipAdv = flag.String("gossip-advertise", "127.0.0.1", "gossip advertise address")
seeds = flag.String("seeds", "", "comma-separated gossip seeds host:port")
gossipSecret = flag.String("gossip-secret", "", "optional gossip shared secret")
demoKS = flag.Bool("demo-keyspace", true, "register stock demo keyspaces (demo/tags/board/profile/doc/flags/embeddings)")
demoKS = flag.Bool("demo-keyspace", true, "register stock demo keyspaces named after the mode (cacheonly/set/zset/hash/json/bitmap/vectorset)")
globalRPS = flag.Float64("global-rps", 0, "global DataSource rate limit (0=off)")
cluster = flag.Bool("cluster", false, "enable gossip membership + peer fan-out")
showVersion = flag.Bool("version", false, "print version and exit")
Expand Down Expand Up @@ -90,7 +90,7 @@ func main() {
if err := registerDemoKeyspaces(eng); err != nil {
log.Fatal(err)
}
log.Printf("demo keyspaces: demo=CacheOnly tags=ModeSet board=ModeZSet profile=ModeHash doc=ModeJSON flags=ModeBitmap embeddings=ModeVectorSet")
log.Printf("demo keyspaces: %s", strings.Join(demoKeyspaceNames(), " "))
}

cacheSrvOpts, peerSrvOpts, peerDialTLS, err := buildTLS(
Expand Down Expand Up @@ -285,21 +285,36 @@ func buildTLS(
return cacheOpts, peerOpts, peerDial, nil
}

// demoKeyspaceName is lowercase Mode.String() so sc -keyspace <mode> is guessable.
func demoKeyspaceName(m keyspace.Mode) string {
return strings.ToLower(m.String())
}

func demoKeyspaceNames() []string {
var out []string
for _, cfg := range demoKeyspaceConfigs() {
out = append(out, cfg.Name+"="+cfg.Mode.String())
}
return out
}

func demoKeyspaceConfigs() []keyspace.Config {
ttl := 30 * time.Minute
return []keyspace.Config{
{Name: demoKeyspaceName(keyspace.ModeCacheOnly), Mode: keyspace.ModeCacheOnly, MaxBytes: 64 << 20, TTL: 5 * time.Minute},
{Name: demoKeyspaceName(keyspace.ModeSet), Mode: keyspace.ModeSet, MaxBytes: 16 << 20, TTL: ttl},
{Name: demoKeyspaceName(keyspace.ModeZSet), Mode: keyspace.ModeZSet, MaxBytes: 16 << 20, TTL: ttl},
{Name: demoKeyspaceName(keyspace.ModeHash), Mode: keyspace.ModeHash, MaxBytes: 16 << 20, TTL: ttl},
{Name: demoKeyspaceName(keyspace.ModeJSON), Mode: keyspace.ModeJSON, MaxBytes: 16 << 20, TTL: ttl},
{Name: demoKeyspaceName(keyspace.ModeBitmap), Mode: keyspace.ModeBitmap, MaxBytes: 16 << 20, TTL: ttl},
{Name: demoKeyspaceName(keyspace.ModeVectorSet), Mode: keyspace.ModeVectorSet, MaxBytes: 16 << 20, TTL: ttl},
}
}

// registerDemoKeyspaces installs the stock -demo-keyspace set.
func registerDemoKeyspaces(eng *engine.Engine) error {
type ks struct {
cfg keyspace.Config
}
for _, item := range []ks{
{keyspace.Config{Name: "demo", Mode: keyspace.ModeCacheOnly, MaxBytes: 64 << 20, TTL: 5 * time.Minute}},
{keyspace.Config{Name: "tags", Mode: keyspace.ModeSet, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
{keyspace.Config{Name: "board", Mode: keyspace.ModeZSet, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
{keyspace.Config{Name: "profile", Mode: keyspace.ModeHash, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
{keyspace.Config{Name: "doc", Mode: keyspace.ModeJSON, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
{keyspace.Config{Name: "flags", Mode: keyspace.ModeBitmap, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
{keyspace.Config{Name: "embeddings", Mode: keyspace.ModeVectorSet, MaxBytes: 16 << 20, TTL: 30 * time.Minute}},
} {
if err := eng.UpdateKeySpace(item.cfg); err != nil {
for _, cfg := range demoKeyspaceConfigs() {
if err := eng.UpdateKeySpace(cfg); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Peer mesh with mTLS: every node uses the same CA; each node presents a cert sign

Wrong verb for the mode → invalid argument. Configure the same modes on every node (see rollout above).

Demo node (`-demo-keyspace`): registers `demo` (CacheOnly), `tags` (ModeSet), `board` (ModeZSet), `profile` (ModeHash), `doc` (ModeJSON), `flags` (ModeBitmap), `embeddings` (ModeVectorSet). Geo/List/Counter/HLL/TopK/CMS keyspaces are configured by the app. Live plays billboard: [examples/billboard](../examples/billboard/README.md). Hash walkthrough: [examples/hash](../examples/hash/README.md). Rate limiter: [examples/ratelimit](../examples/ratelimit/README.md). JSON document: [examples/json](../examples/json/README.md). Bitmap flags: [examples/bitmap](../examples/bitmap/README.md). HLL sketch: [examples/hll](../examples/hll/README.md).
Demo node (`-demo-keyspace`): one keyspace per shipped demo mode, **name = lowercase `Mode.String()`** — `cacheonly`, `set`, `zset`, `hash`, `json`, `bitmap`, `vectorset`. Geo/List/Counter/HLL/TopK/CMS are not on the stock node (register them in the app). Live plays billboard: [examples/billboard](../examples/billboard/README.md). Hash walkthrough: [examples/hash](../examples/hash/README.md). Rate limiter: [examples/ratelimit](../examples/ratelimit/README.md). JSON document: [examples/json](../examples/json/README.md). Bitmap flags: [examples/bitmap](../examples/bitmap/README.md). HLL sketch: [examples/hll](../examples/hll/README.md).

## Consistency cheatsheet

Expand Down
22 changes: 11 additions & 11 deletions examples/bitmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CI covers the same path: `go test ./examples/bitmap`.
## Manual `sc` against a node

`supercache-node -demo-keyspace` (the default) now also registers
**`flags`** (`ModeBitmap`).
**`bitmap`** (`ModeBitmap`).

`sc bitset` / `bitget` take a numeric offset. The bit token must be `0` or `1`.

Expand All @@ -43,16 +43,16 @@ go run ./cmd/supercache-node \
-cache 127.0.0.1:9000 -peer 127.0.0.1:9001 -admin 127.0.0.1:8080

# terminal 2
go run ./cmd/sc -keyspace flags bitset seen 0 1
go run ./cmd/sc -keyspace flags bitset seen 8 1
go run ./cmd/sc -keyspace flags bitget seen 0
go run ./cmd/sc -keyspace flags bitget seen 3
go run ./cmd/sc -keyspace flags bitcount seen
go run ./cmd/sc -keyspace flags bitcount seen 0 0
go run ./cmd/sc -keyspace flags bitpos seen 1
go run ./cmd/sc -keyspace flags bitset seen 0 0
go run ./cmd/sc -keyspace flags bitcount seen
go run ./cmd/sc -keyspace flags del seen # tombstone whole bitmap
go run ./cmd/sc -keyspace bitmap bitset seen 0 1
go run ./cmd/sc -keyspace bitmap bitset seen 8 1
go run ./cmd/sc -keyspace bitmap bitget seen 0
go run ./cmd/sc -keyspace bitmap bitget seen 3
go run ./cmd/sc -keyspace bitmap bitcount seen
go run ./cmd/sc -keyspace bitmap bitcount seen 0 0
go run ./cmd/sc -keyspace bitmap bitpos seen 1
go run ./cmd/sc -keyspace bitmap bitset seen 0 0
go run ./cmd/sc -keyspace bitmap bitcount seen
go run ./cmd/sc -keyspace bitmap del seen # tombstone whole bitmap
```

`bitget` of a missing name prints `(nil)` and exits 1.
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Exercises **CacheOnly** (`demo`: sessions / KV), **ModeSet** (`tags`: feature flags), and **ModeZSet** (`board`: leaderboard via `ZAdd` / `ZScore` / `ZRange` / `ZRem`).

Requires `supercache-node` with `-demo-keyspace` (default), which registers `demo`, `tags`, `board`, `profile`, `doc`, `flags`, and `embeddings` (this example uses the first three).
Requires `supercache-node` with `-demo-keyspace` (default), which registers keyspaces named after the mode (`cacheonly`, `set`, `zset`, `hash`, `json`, `bitmap`, `vectorset`). This example uses `cacheonly`, `set`, and `zset`.

Start three nodes (separate terminals), then run this example.

Expand Down
Loading
Loading