Nothing Special   »   [go: up one dir, main page]

Skip to content
/ go-cache Public

use tag with redis/go-redis

License

Notifications You must be signed in to change notification settings

isfk/go-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cache

cache based on go-redis

Installation

Install:

go get -u github.com/isfk/go-cache/v3

Import:

import "github.com/isfk/go-cache/v3"

QuickStart

Init with cache.New()

rdb := redisV9.NewClient(&redisV9.Options{
    Addr:     "127.0.0.1:6379",
})

c := cache.New(
    context.Background(),
    rdb,
    cache.WithPrefix("test"),
    cache.WithExpired(600*time.Second),
)

Command

  • use Tag & Set & Get

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

Get without Tag.

c.Tag([]string{"tag:user:all", "tag:user:1"}...).Set(ctx, "key:user:1", &proto.User{Id: 1, Nickname: "111"})
c.Tag([]string{"tag:user:all", "tag:user:2"}...).Set(ctx, "key:user:2", &proto.User{Id: 2, Nickname: "222"})

info := &proto.User{}
c.Get(ctx, "key:user:1", info)
c.Get(ctx, "key:user:2", info)
c.Tag([]string{"tag:user:all"}...).Flush(ctx)
  • use redis

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

c.redis.Set("key", "value", time.Hour).Err()
c.redis.Get("key").Result()
c.redis.command()...