presets API

presets

package

API reference for the presets package.

S
struct

RedisOptions

RedisOptions configures the connection to Redis.

v1/presets/presets.go:15-19
type RedisOptions struct

Fields

Name Type Description
Addr string
Password string
DB int
F
function

NewRedisEventual

NewRedisEventual creates a Warp instance configured for Eventual Consistency
using Redis as both the L2 Store and the Synchronization Bus.
This is suitable for high-performance caching where occasional staleness is acceptable.

Parameters

Returns

v1/presets/presets.go:24-44
func NewRedisEventual[T any](opts RedisOptions) *core.Warp[T]

{
	client := redis.NewClient(&redis.Options{
		Addr:     opts.Addr,
		Password: opts.Password,
		DB:       opts.DB,
	})

	// L1: InMemory with Merge capabilities
	c := cache.NewInMemory[merge.Value[T]]()

	// L2: Redis Store
	store := adapter.NewRedisStore[T](client)

	// Bus: Redis Pub/Sub
	bus := busredis.NewRedisBus(busredis.RedisBusOptions{Client: client})

	// Engine: Standard Last-Write-Wins (or Vector Clock if T is Versioned, but default Engine is simpler)
	engine := merge.NewEngine[T]()

	return core.New[T](c, store, bus, engine)
}
F
function

NewRedisStrong

NewRedisStrong creates a Warp instance configured for Strong Consistency
using Redis as the L2 Store and Bus.
Note: True strong consistency requires Quorum writes which are slower.

Parameters

Returns

v1/presets/presets.go:49-54
func NewRedisStrong[T any](opts RedisOptions) *core.Warp[T]

{
	// Re-use logic, the difference is mainly in how the user Registers keys (ModeStrong).
	// But we can enable optimization flags here if needed.
	// For now, it returns the same structure, but the naming guides the user intent.
	return NewRedisEventual[T](opts)
}
F
function

NewMeshEventual

NewMeshEventual creates a Warp instance configured for Eventual Consistency
using Warp Mesh (UDP P2P) for synchronization and an in-memory L2 store.
This provides zero-infrastructure clustering for Go backends.

Parameters

Returns

v1/presets/presets.go:59-65
func NewMeshEventual[T any](opts mesh.MeshOptions) *core.Warp[T]

{
	c := cache.NewInMemory[merge.Value[T]]()
	s := adapter.NewInMemoryStore[T]()
	bus, _ := mesh.NewMeshBus(opts)
	engine := merge.NewEngine[T]()
	return core.New[T](c, s, bus, engine)
}
F
function

NewInMemoryStandalone

NewInMemoryStandalone creates a Warp instance that runs entirely in-memory
with no external dependencies. Useful for local development or simple caching.

Returns

v1/presets/presets.go:69-75
func NewInMemoryStandalone[T any]() *core.Warp[T]

{
	c := cache.NewInMemory[merge.Value[T]]()
	s := adapter.NewInMemoryStore[T]()
	b := syncbus.NewInMemoryBus()
	engine := merge.NewEngine[T]()
	return core.New[T](c, s, b, engine)
}
F
function

TestNewInMemoryStandalone

Parameters

v1/presets/presets_test.go:12-27
func TestNewInMemoryStandalone(t *testing.T)

{
	w := NewInMemoryStandalone[string]()
	ctx := context.Background()

	w.Register("foo", core.ModeStrongLocal, time.Minute)
	if err := w.Set(ctx, "foo", "bar"); err != nil {
		t.Fatalf("Set failed: %v", err)
	}
	val, err := w.Get(ctx, "foo")
	if err != nil {
		t.Fatalf("Get failed: %v", err)
	}
	if val != "bar" {
		t.Fatalf("expected bar, got %s", val)
	}
}
F
function

TestNewRedisEventual

Parameters

v1/presets/presets_test.go:29-50
func TestNewRedisEventual(t *testing.T)

{
	mr, err := miniredis.Run()
	if err != nil {
		t.Fatalf("miniredis run: %v", err)
	}
	defer mr.Close()

	w := NewRedisEventual[string](RedisOptions{Addr: mr.Addr()})
	ctx := context.Background()

	w.Register("foo", core.ModeEventualDistributed, time.Minute)
	if err := w.Set(ctx, "foo", "bar"); err != nil {
		t.Fatalf("Set failed: %v", err)
	}
	val, err := w.Get(ctx, "foo")
	if err != nil {
		t.Fatalf("Get failed: %v", err)
	}
	if val != "bar" {
		t.Fatalf("expected bar, got %s", val)
	}
}