redis

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InMemProvider

func InMemProvider(ctx context.Context, config *viper.Viper) (providers.Cache, error)

InMemProvider returns a new in-memory redis provider(used for testing)

func InMemStreamProvider

func InMemStreamProvider(ctx context.Context, config *viper.Viper) (providers.Stream, error)

InMemProvider returns a new in-memory redis stream provider(used for testing)

func Provider

func Provider(ctx context.Context, config *viper.Viper) (providers.Cache, error)

Provider returns a new Redis cache provider(cache.addr, cache.password, cache.db)

func StreamProvider

func StreamProvider(ctx context.Context, config *viper.Viper) (providers.Stream, error)

StreamProvider returns a new Redis stream provider(stream.addr, stream.password, stream.db)

Types

type Redis

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

func NewRedis

func NewRedis(client *redis.Client) *Redis

NewRedis returns a new redis cache/stream provider

func (Redis) AsyncSubscribe

func (r Redis) AsyncSubscribe(ctx context.Context, topic, consumer string, handler providers.MessageHandler) error

AsyncSubscribe subscribes to a topic and calls the handler in a goroutine

func (Redis) Delete

func (r Redis) Delete(ctx context.Context, key string) error

Delete deletes a key

func (Redis) Get

func (r Redis) Get(ctx context.Context, key string) (string, error)

Get gets a key

func (Redis) Lock

func (r Redis) Lock(ctx context.Context, key string, ttl time.Duration) (bool, error)

Lock locks a key

func (Redis) Once

func (r Redis) Once(ctx context.Context, key string, ttl time.Duration, fn func(ctx context.Context) error) (bool, error)

Once runs a function once for a given key

func (Redis) Publish

func (r Redis) Publish(ctx context.Context, topic string, message map[string]any) error

Publish publishes a message to a topic

func (Redis) Set

func (r Redis) Set(ctx context.Context, key string, value string, ttl time.Duration) error

Set sets a key

func (Redis) Subscribe

func (r Redis) Subscribe(ctx context.Context, topic, consumer string, handler providers.MessageHandler) error

Subscribe subscribes to a topic

func (Redis) Unlock

func (r Redis) Unlock(ctx context.Context, key string, ttl time.Duration) error

Unlock unlocks a key

Jump to

Keyboard shortcuts

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