cache

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TTL1Minute  int = 60
	TTL5Minute  int = 300
	TTL15Minute int = 900
	TTL30Minute int = 1800
	TTL1Hour    int = 3600
	TTL1Day     int = 86400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func (Cache) Close

func (c Cache) Close(ctx context.Context) error

func (Cache) Del

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

Del delete key

func (Cache) Exist

func (c Cache) Exist(ctx context.Context, key string) (bool, error)

Exist check if key exist

func (Cache) Get

func (c Cache) Get(ctx context.Context, key string) (string, error)

Get get value by key

func (Cache) Incr

func (c Cache) Incr(ctx context.Context, key string) (int64, error)

Incr increment the value for key by 1, return new value and error

func (Cache) Set

func (c Cache) Set(ctx context.Context, key string, val string, ttlInSecond int) error

Set set key value with ttl in second

type CacheMethod

type CacheMethod interface {
	Set(ctx context.Context, key string, val string, ttlInSecond int) error
	Get(ctx context.Context, key string) (string, error)
	Del(ctx context.Context, key string) error
	Exist(ctx context.Context, key string) (bool, error)
	Incr(ctx context.Context, key string) (int64, error)

	Close(ctx context.Context) error
}

func New

func New(ctx context.Context, cfg Config) (CacheMethod, error)

type Config

type Config struct {
	URL      string `json:"url"`      // host or ip address
	Port     string `json:"port"`     // default 6379
	Password string `json:"password"` // default not using password
	DB       int    `json:"db"`       // 0 = use default DB
}

Jump to

Keyboard shortcuts

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