redis

package module
v0.0.0-...-fe1705a Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	KeyServicePrefix = "service:" // Use a prefix for service keys
	KeySessionPrefix = "session:" // Use a prefix for session keys
)

Variables

This section is empty.

Functions

func Close

func Close(rdb *redis.Client) error

Close closes the Redis client connection pool. It's important to call this function during service shutdown to release resources.

func Delete

func Delete(ctx context.Context, rdb *redis.Client, key string) error

Delete deletes a key from Redis.

func Get

func Get(ctx context.Context, rdb *redis.Client, key string, target interface{}) error

Get retrieves a value from Redis. It takes the Redis client, context, key, and a target pointer to store the retrieved value (must be a pointer).

func Incr

func Incr(ctx context.Context, rdb *redis.Client, key string) (int64, error)

Incr increments a counter in Redis and returns the new value.

func NewRedisClient

func NewRedisClient(cfg *common.RedisConfig) (*redis.Client, error)

NewRedisClient creates a new Redis client instance with connection pooling.

func Set

func Set(ctx context.Context, rdb *redis.Client, key string, value interface{}, expiration time.Duration) error

It takes the Redis client, context, key, value (which can be any serializable type), and expiration duration.

Types

type ExternalService

type ExternalService struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user,omitempty"` // Optional fields for credentials
	Password string `json:"password,omitempty"`
	DBName   string `json:"dbname,omitempty"`
}

ExternalService represents configuration for an external service

type ExternalServicesConfig

type ExternalServicesConfig struct {
	Registry   ExternalService `json:"registry"`
	Redis      ExternalService `json:"redis"`
	PostgreSQL ExternalService `json:"postgresql"`
	RabbitMQ   ExternalService `json:"rabbitmq"`
}

ExternalServicesConfig holds configurations for external services

type HealthCheck

type HealthCheck struct {
	Endpoint string `json:"endpoint"`
	Interval string `json:"interval"`
	Timeout  string `json:"timeout"`
}

HealthCheck represents a service's health check configuration.

type MachineSession

type MachineSession struct {
	SessionID uuid.UUID `json:"session_id"`
	MachineID uuid.UUID `json:"machine_id"`
	UserID    uuid.UUID `json:"user_id"`
	URL       string    `json:"url"`
	Port      int       `json:"port"`
	StartedAt time.Time `json:"started_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

MachineSession represents an active machine session

type Service

type Service struct {
	ID          string      `json:"id"`
	Name        string      `json:"name"`
	Address     string      `json:"address"`
	Port        int         `json:"port"`
	HealthCheck HealthCheck `json:"healthCheck"`
}

Service represents a registered microservice

Jump to

Keyboard shortcuts

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