redis

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 7 Imported by: 0

README

Redis

Helpers for Go projects.

Connection

You can make redis connection and get client to work with. It works for Single and cluster Redis.

// Single connection
client := GetNormalConnection(ctx , host, password , database, timeout, poolSize)

// Cluster connection
client := GetClusterConnection(ctx, host, timeout)
Shared Redis

For a Redis server that is shared with same instances of a code to cache data that has high fetch time or high load, you can use sharedFetch.

data, err := SharedFetch(ctx, client, key, duration, retryDuration, dataFetchRetry, dataFetchFunc)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch added in v0.0.4

func Fetch[K any](ctx context.Context, client redis.Cmdable, key string, t, retryT time.Duration, retry int, f dataFetcher[K]) error

func GetClusterConnection

func GetClusterConnection(ctx context.Context, host string, timeout int) (*redis.ClusterClient, error)

func GetNormalConnection

func GetNormalConnection(ctx context.Context, host, password string, database, timeout, poolSize int) (*redis.Client, error)

func HealthCheck

func HealthCheck(ctx context.Context, client redis.Cmdable) error

func SharedFetch

func SharedFetch[K any](ctx context.Context, client redis.Cmdable, key string, t, retryT time.Duration, retry int, f dataFetcher[K]) (K, error)

this is used when multi instances of a code try to use shared cache on redis and result fetch function has too much load expensive it will return the same result for all of them it will checks if the value exists it will return it if not it will check if any one else is trying to fetch value if it was the case it will not try to fetch but if no one of instances has tried to fetch the result it start to fetch and set a waitKey too inform others

Types

This section is empty.

Jump to

Keyboard shortcuts

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