cache

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 5 Imported by: 0

README

cache

cache based on go-redis

Installation

Install:

go get -u github.com/go-cache/cache/v2

Import:

import "github.com/go-cache/cache/v2"

QuickStart

Init with cache.NewClient(conf)
rdb := redisV8.NewClient(&redisV8.Options{
    Addr:     redis.StdRedisConfig("main").Addr,
    Password: redis.StdRedisConfig("main").Password, // no password set
    DB:       redis.StdRedisConfig("main").DB,
})

CacheModel = cache.NewClient(context.Background(), rdb)
Command
  • use Tag & Set & Get

Set is the same as Set, but just with Tag together.

CacheModel.Tag("user_all", "user_list").Set("user_id:1", &proto.User{Id: 1, Nickname: "111"}, time.Hour)
CacheModel.Tag("user_all").Set("user_id:2", &proto.User{Id: 2, Nickname: "222"}, time.Hour)
CacheModel.Get("user_id:2")
CacheModel.Tag("user_list").Flush()
  • use redis

All redis command check: https://godoc.org/github.com/go-redis/redis

CacheModel.RedisClient.Set("key", "value", time.Hour).Err()
CacheModel.RedisClient.Get("key").Result()
CacheModel.RedisClient.command()...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RedisClusterDriver *redis.ClusterClient

RedisClusterDriver RedisClusterDriver

View Source
var RedisDriver *redis.Client

RedisDriver RedisDriver

Functions

This section is empty.

Types

type Cache added in v2.2.0

type Cache struct {
	RedisClient        *redis.Client
	RedisClusterClient *redis.ClusterClient
	// contains filtered or unexported fields
}

Cache Cache

func New added in v2.2.0

func New(ctx context.Context, client *redis.Client) *Cache

New New

func NewClusterClient

func NewClusterClient(ctx context.Context, client *redis.ClusterClient) *Cache

NewClusterClient NewClusterClient

func (*Cache) Flush added in v2.2.0

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

Flush .Tag().Flush()

func (*Cache) Get added in v2.2.0

func (c *Cache) Get(ctx context.Context, key string, val interface{}) error

Get .Get()

func (*Cache) Set added in v2.2.0

func (c *Cache) Set(ctx context.Context, key string, val interface{}, expire time.Duration) error

Set .Tag().Set()

func (*Cache) Tag added in v2.2.0

func (c *Cache) Tag(tag ...string) *Cache

Tag .Tag()

Jump to

Keyboard shortcuts

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