redis

package module
v0.0.0-...-c0075a2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Redis Cache

cache data in redis implemented by go-redis

Usage

    redisCache := NewCache(addr, username, password)
    err := redisCache.SetString(context.TODO(), key, val, -1)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Client *redis.Client
}

Cache redis cache

func NewCache

func NewCache(conn, username, password string) *Cache

NewCache creates a new redis cache

func (*Cache) Decrease

func (r *Cache) Decrease(ctx context.Context, key string, value int64) (data int64, err error)

Decrease key by value

func (*Cache) Del

func (r *Cache) Del(ctx context.Context, key string) error

Del delete key from cache

func (*Cache) Flush

func (r *Cache) Flush(ctx context.Context) error

Flush delete all cache entries

func (*Cache) GetInt64

func (r *Cache) GetInt64(ctx context.Context, key string) (data int64, exist bool, err error)

GetInt64 get int64 value by key

func (*Cache) GetString

func (r *Cache) GetString(ctx context.Context, key string) (data string, exist bool, err error)

GetString get string value by key

func (*Cache) Increase

func (r *Cache) Increase(ctx context.Context, key string, value int64) (data int64, err error)

Increase key by value

func (*Cache) SetInt64

func (r *Cache) SetInt64(ctx context.Context, key string, value int64, ttl time.Duration) error

SetInt64 set int64 value with key and ttl

func (*Cache) SetString

func (r *Cache) SetString(ctx context.Context, key, value string, ttl time.Duration) error

SetString set string value with key and ttl

Jump to

Keyboard shortcuts

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