easyredis

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

easyredis

Wrapper around redis lib to make usage easier

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRedisKeyNotFound = errors.New("redis key not found")

ErrRedisKeyNotFound indicates that the cached element does not exist.

Functions

func ConnectToRedis

func ConnectToRedis(host, port, db, password string) (*redis.Client, error)

ConnectToRedis instantiates a new go-redis client.

Types

type Service

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

Service is a wrapper around go-redis for easy read and write

func New

func New(client *redis.Client) *Service

New instantiates a new service.

func (*Service) Exists added in v0.2.0

func (s *Service) Exists(ctx context.Context, key string) (bool, error)

Exists returns true if the given key exists in redis.

ctx should have a timeout

key is the key that is being used to store the data

func (*Service) Get

func (s *Service) Get(ctx context.Context, key string) ([]byte, error)

Get returns a value for given key from redis.

ctx should have a timeout key

func (*Service) Set

func (s *Service) Set(ctx context.Context, ttl time.Duration, key string, val interface{}) error

Set writes the given value to redis as json with the given TTL.

ctx should have a timeout

ttl is the time until the data should expire

key is the key that is being used to store the data

value can be any value

func (*Service) SetJSON added in v0.3.0

func (s *Service) SetJSON(ctx context.Context, ttl time.Duration, key string, val []byte) error

SetJSON the given value to redis as json with the given TTL.

ctx should have a timeout

ttl is the time until the data should expire

key is the key that is being used to store the data

value must be a json object ([]byte)

Jump to

Keyboard shortcuts

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