8000 GitHub - skyoo2003/acor: A Go library for Aho-Corasick multi-pattern matching, with a shared pattern dictionary stored in Redis or Valkey. · GitHub
[go: up one dir, main page]

Skip to content
skyoo2003Public

About

A Go library for Aho-Corasick multi-pattern matching, with a shared pattern dictionary stored in Redis or Valkey.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

249 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
< 8000 div class="react-directory-filename-cell">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ACOR

Aho-Corasick automaton working On Redis — distributed multi-pattern matching for Go.

Current Release CI Status Docs Go Reference License Sponsor

ACOR keeps one Aho-Corasick dictionary in Redis and reaches it from a Go library, a CLI, and an experimental server module. Every application instance shares that dictionary, updates it at runtime, and matches against a local copy with no Redis I/O on the hot path.

Typical uses: content filtering, keyword extraction, intrusion detection, search highlighting, real-time text classification.

Highlights

  • Shared state — every instance reads the same Redis-backed dictionary
  • < 8000 strong>Runtime updates — Pub/Sub invalidation, with optional polling for missed messages
  • Fast reads — preset engines match locally, 0 round trips
  • Topologies — standalone Redis, Sentinel, Cluster, Ring, and Valkey
  • Full matching API — occurrences, positions, sets, streams, batches, parallel scans

Install

Requires Go 1.25+ and Redis 3.0+ or Valkey 7.2+.

go get github.com/skyoo2003/acor/pkg/acor@latest

Quick start

Start Redis locally, then:

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/skyoo2003/acor/pkg/acor"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	ac, err := acor.CreateContext(ctx, &acor.AhoCorasickArgs{
		Addr:   "localhost:6379",
		Name:   "sample",
		Preset: acor.PresetBalanced,
	})
	if err != nil {
		return fmt.Errorf("create collection: %w", err)
	}
	defer func() { _ = ac.Close() }()

	if _, err := ac.AddManyContext(ctx, []string{"he", "her", "him"}, nil); err != nil {
		return fmt.Errorf("add keywords: %w", err)
	}

	matches, err := ac.FindMatchesContext(ctx, "he is him", nil)
	if err != nil {
		return fmt.Errorf("find matches: %w", err)
	}
	fmt.Println(matches)
	return nil
}

New collections use the optimized V2 Redis schema.

Choosing a preset

Goal Preset
General-purpose speed and memory PresetBalanced
Highest matching throughput PresetSpeed
Lowest memory usage PresetMemoryEfficient

Redis stays the source of truth for every preset. Trade-offs are in the preset guide; multi-instance invalidation is in the Redis-backed engine guide.

Large dictionaries (V3)

OpenVersioned opens a separate V3 collection with leased snapshots, expected-version writes, and background engine replacement. V1/V2 APIs are unaffected. See the V3 guide, its performance report, and bounded text processing for Scan, MaskText, and ReplaceText.

For a new V3 dictionary, VersionedOptions.ShardCount selects a fixed storage and engine shard count (powers of two, up to 256); zero or one preserves legacy V3. Existing dictionaries keep their stored layout until an explicit Reshard commit. Sharded storage uses separate Redis hash tags, while each serving replica still holds the complete searchable dictionary in RAM. Searches make no Redis calls. Plan for the previous engine and replacement shards to coexist during refresh; shard count alone does not establish a memory or latency improvement. The sharded release still requires controlled scale and live multi-node Cluster qualification.

Documentation

The documentation site covers Redis topologies, the matching and streaming API, batch and parallel guides, the V2 schema and benchmarks, deployment and troubleshooting, the acor CLI, the experimental server module, and what the v1 line promises. Package signatures are on pkg.go.dev.

Project

Contributing · Support · Security · Code of Conduct · Governance · Changelog

License

Apache License 2.0 — Copyright 2016-2026 Sungkyu Yoo

About

A Go library for Aho-Corasick multi-pattern matching, with a shared pattern dictionary stored in Redis or Valkey.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

0