redis

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package redis provides a Redis- or Valkey-backed gateway.CertStore, so that every process in a deployment shares one persistent certificate store: a node that cold-starts fetches already-issued certificates back from the server instead of depending on the issuer being reachable/willing to re-issue. It is a separate package specifically so that importing the root gateway package never pulls in github.com/redis/go-redis/v9 for applications that use the default gateway.MemoryCertStore or gateway.FileCertStore.

go-redis speaks the same RESP protocol to Redis and to Valkey (a BSD-licensed fork of Redis 7.2.4), so the constructor takes a goredis.UniversalClient pointed at either one and the code below carries no Redis-versus-Valkey branch. Only core string commands are used, which both servers implement identically.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures a Store created with New.

func WithKeyPrefix

func WithKeyPrefix(prefix string) Option

WithKeyPrefix namespaces every key this Store reads or writes, so multiple gateway deployments (or unrelated applications) can share one Redis instance/database without colliding. Defaults to no prefix.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a gateway.CertStore backed by a Redis or Valkey client: each certificate is stored under its own key with no TTL, so a certificate survives until it is overwritten by Put or removed by Delete. Server-side persistence (Redis RDB/AOF, or the Valkey equivalent) is what makes the store survive a full deployment restart, which is the reason to plug it in over MemoryCertStore. Only core string commands (GET/SET/DEL) are used, all present and identical on Redis 7.2 and Valkey 8, so one client pointed at either server works with no code change.

func New

func New(client goredis.UniversalClient, opts ...Option) *Store

New creates a Store backed by client. client may be a *redis.Client, *redis.ClusterClient, *redis.Ring, or any other goredis.UniversalClient implementation, pointed at either a Redis or a Valkey server.

Example

ExampleNew persists issued certificates so a cold-starting node fetches them back from the server instead of depending on the issuer to re-issue. Get reports gateway.ErrCertificateNotFound for a domain that was never stored.

package main

import (
	"context"
	"errors"
	"log"

	goredis "github.com/redis/go-redis/v9"

	gateway "github.com/StringKe/goakt-gateway"
	storeredis "github.com/StringKe/goakt-gateway/store/redis"
)

func main() {
	client := goredis.NewClient(&goredis.Options{Addr: "localhost:6379"})
	defer func() { _ = client.Close() }()

	store := storeredis.New(client, storeredis.WithKeyPrefix("myapp:"))

	ctx := context.Background()
	_, err := store.Get(ctx, "example.com")
	if errors.Is(err, gateway.ErrCertificateNotFound) {
		log.Println("no certificate yet; issue and Put one")
	}
}

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, domain string) error

Delete implements gateway.CertStore. It is idempotent: deleting a domain with no stored certificate is not an error.

func (*Store) Get

func (s *Store) Get(ctx context.Context, domain string) (*gateway.Certificate, error)

Get implements gateway.CertStore. It returns gateway.ErrCertificateNotFound when no certificate is stored for domain.

func (*Store) Put

func (s *Store) Put(ctx context.Context, cert *gateway.Certificate) error

Put implements gateway.CertStore, overwriting any previous certificate for the same domain. The key is written without a TTL: a certificate lives until Put replaces it or Delete removes it, since expiry is governed by the certificate's own NotAfter rather than by Redis eviction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL