Skip to main content
Anubis uses the store.Interface abstraction for all persistence operations. This allows you to implement custom storage backends for Redis, databases, cloud storage, or any key-value system.

Store Interface

The core storage interface defines four methods:
Source: lib/store/interface.go:31-45

Standard Errors

Implementations should return these sentinel errors:
Source: lib/store/interface.go:11-26

Implementation Example: In-Memory Store

The memory backend demonstrates a minimal implementation:
Source: lib/store/memory/memory.go:25-78

Implementation Example: Valkey/Redis

The Valkey backend shows integration with external systems:
Source: lib/store/valkey/valkey.go

Implementation Example: bbolt

The bbolt backend demonstrates persistent on-disk storage with expiry management:
Source: lib/store/bbolt/bbolt.go:60-122

Factory Pattern

Store backends use a factory pattern for registration:
Source: lib/store/registry.go:15-25

Example Factory

Source: lib/store/memory/memory.go:13-23

JSON Type Wrapper

Anubis provides a generic JSON wrapper for type-safe operations:
Source: lib/store/interface.go:49-95

Configuration

Reference your store backend in anubis.yaml:

Cleanup Threads

Implement background cleanup for expired keys:
Source: lib/store/bbolt/bbolt.go:156-170

Best Practices

  1. Return standard errors: Use store.ErrNotFound, store.ErrCantDecode, etc.
  2. Handle expiry: Implement automatic cleanup or lazy deletion of expired keys
  3. Context awareness: Honor context.Context for cancellation and timeouts
  4. IsPersistent accuracy: Return false for in-memory stores, true for persistent backends
  5. Thread safety: Ensure concurrent access is safe
  6. Configuration validation: Implement Factory.Valid() to catch config errors early

Available Backends

Query registered stores at runtime:
Source: lib/store/registry.go:34-42