redislib

package
v0.0.0-...-aa4210d Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 2 * time.Second

Variables

This section is empty.

Functions

func Connect

func Connect(config ClientOptions) (err error)

func Get

func Get[T any](key Key) (res T, err error)

func GetOrSet

func GetOrSet[T any](key Key, ttl time.Duration, fn func() (T, error)) (res T, err error)

func IsNil

func IsNil(err error) bool

func Publisher

func Publisher[T any](channel string, config PublisherConfig) func(T) error

func Set

func Set(key Key, ttl time.Duration, value interface{}) (err error)

func SetNX

func SetNX(key Key, ttl time.Duration, value interface{}) (err error)

func Subscribe

func Subscribe[T any](channel string, receiver ReceiverFunc[T], onError ErrorFunc) func()

Types

type ClientOptions

type ClientOptions struct {
	Hostname string        `validation:"required,hostname"`
	Port     int           `validation:"required,numeric"`
	Password string        `validation:"required"`
	Timeout  time.Duration `validation:"required"`
	TLS      *tls.Config
}

func ClientOptionsFromEnvConfig

func ClientOptionsFromEnvConfig(cfg EnvClientConfig) ClientOptions

func (ClientOptions) FormatHost

func (o ClientOptions) FormatHost() string

func (ClientOptions) FormatUri

func (o ClientOptions) FormatUri() string

type EnvClientConfig

type EnvClientConfig struct {
	Hostname string        `env:"REDIS_HOST" validate:"required,hostname"`
	Port     int           `env:"REDIS_PORT" validate:"required,numeric"`
	Password string        `env:"REDIS_PASSWORD" validate:"required"`
	Timeout  time.Duration `env:"REDIS_TIMEOUT" validate:"numeric"`
}

type ErrorFunc

type ErrorFunc func(error)

type Key

type Key []string

func (*Key) String

func (k *Key) String() string

type Message

type Message[T any] struct {
	Timestamp time.Time `json:"tsp"`
	Id        string    `json:"idx"`
	Type      string    `json:"typ"`
	Origin    string    `json:"org"`
	Payload   T         `json:"pld"`
}

type PublisherConfig

type PublisherConfig struct {
	Type    string
	Origin  string
	Timeout time.Duration
}

type ReceiverFunc

type ReceiverFunc[T any] func(msg Message[T])

type StreamConsumer

type StreamConsumer[T any] struct {
	Emitter *eventlib.Emitter[*Message[T]]
	// contains filtered or unexported fields
}

func NewStreamConsumer

func NewStreamConsumer[T any](cfg StreamConsumerConfig) (res *StreamConsumer[T], err error)

func (*StreamConsumer[T]) Cancel

func (s *StreamConsumer[T]) Cancel()

func (*StreamConsumer[T]) Consume

func (s *StreamConsumer[T]) Consume() error

type StreamConsumerConfig

type StreamConsumerConfig struct {
	Stream   string
	Group    string
	Consumer string
	Size     int
}

type StreamPublisher

type StreamPublisher[T any] struct {
	// contains filtered or unexported fields
}

func NewStreamPublisher

func NewStreamPublisher[T any](cfg StreamPublisherConfig) (res *StreamPublisher[T], err error)

func (*StreamPublisher[T]) Publish

func (s *StreamPublisher[T]) Publish(payload T) (err error)

type StreamPublisherConfig

type StreamPublisherConfig struct {
	Stream  string
	Type    string
	Origin  string
	Timeout time.Duration
}

Jump to

Keyboard shortcuts

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