redis

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Client *redis.Client
	Cache  *cache.Cache
}

func Connect

func Connect(opts *Options) (ctx Connection, err error)

Connect to redis via config

func (Connection) Close

func (conn Connection) Close() error

Close closes the redis connection

func (Connection) DeleteCache

func (conn Connection) DeleteCache(key string) error

DeleteCache deletes a redis item

func (Connection) DeleteCacheContext

func (conn Connection) DeleteCacheContext(c context.Context, key string) error

DeleteCacheContext deletes a redis item with context

func (Connection) Exists

func (conn Connection) Exists(key string) bool

Exists checks if a key exists

func (Connection) ExistsContext

func (conn Connection) ExistsContext(c context.Context, key string) bool

ExistsContext checks if a key exists with context

func (Connection) GetCache

func (conn Connection) GetCache(key string, val interface{}) error

GetCache gets a redis item

func (Connection) GetCacheContext

func (conn Connection) GetCacheContext(c context.Context, key string, val interface{}) error

GetCacheContext gets a redis item with context

func (Connection) Publish

func (conn Connection) Publish(channel string, message interface{}) error

Publish publishes a message to a channel

func (Connection) PublishContext

func (conn Connection) PublishContext(c context.Context, channel string, message interface{}) error

PublishContext publishes a message to a channel with context

func (Connection) SetCache

func (conn Connection) SetCache(key string, val interface{}, override bool) error

SetCache sets a redis with one hour TTL

func (Connection) SetCacheContext

func (conn Connection) SetCacheContext(c context.Context, key string, val interface{}, override bool) error

SetCacheContext sets a redis with one hour TTL with context

func (Connection) SetCacheTTLContext

func (conn Connection) SetCacheTTLContext(c context.Context, key string, val interface{}, override bool, ttl time.Duration) error

SetCacheTTLContext sets a redis with a TTL

func (Connection) Subscribe

func (conn Connection) Subscribe(channels ...string) *redis.PubSub

Subscribe subscribes to a channel

Example 1:

for {
	msg, err := pubsub.ReceiveMessage(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Println(msg.Channel, msg.Payload)
}

Example 2: ch := pubsub.Channel()

for msg := range ch {
	fmt.Println(msg.Channel, msg.Payload)
}

func (Connection) SubscribeContext

func (conn Connection) SubscribeContext(c context.Context, channels ...string) *redis.PubSub

SubscribeContext subscribes to a channel with context

type Options

type Options struct {
	Addr         string
	Username     string
	Password     string
	DB           int
	MaxRetries   int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	PoolTimeout  time.Duration
	IdleTimeout  time.Duration
	PoolFIFO     bool
	TLSConfig    *tls.Config
}

func NewOptions

func NewOptions() *Options

func (*Options) SetAddr

func (o *Options) SetAddr(addr string) *Options

func (*Options) SetDB

func (o *Options) SetDB(db int) *Options

func (*Options) SetDialTimeout

func (o *Options) SetDialTimeout(dialTimeout time.Duration) *Options

func (*Options) SetIdleTimeout

func (o *Options) SetIdleTimeout(idleTimeout time.Duration) *Options

func (*Options) SetMaxRetries

func (o *Options) SetMaxRetries(maxRetries int) *Options

func (*Options) SetPassword

func (o *Options) SetPassword(password string) *Options

func (*Options) SetPoolFIFO

func (o *Options) SetPoolFIFO(poolFIFO bool) *Options

func (*Options) SetPoolTimeout

func (o *Options) SetPoolTimeout(poolTimeout time.Duration) *Options

func (*Options) SetReadTimeout

func (o *Options) SetReadTimeout(readTimeout time.Duration) *Options

func (*Options) SetTLSConfig

func (o *Options) SetTLSConfig(tlsConfig *tls.Config) *Options

func (*Options) SetUsername

func (o *Options) SetUsername(username string) *Options

func (*Options) SetWriteTimeout

func (o *Options) SetWriteTimeout(writeTimeout time.Duration) *Options

Jump to

Keyboard shortcuts

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