cache

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 5 Imported by: 0

README

cache

go cache based on go-redis

Installation

Install:

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

Import:

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

QuickStart

Init with cache.NewClient(conf)
package model

import (
	"github.com/go-cache/cache"
	"github.com/go-redis/redis/v7"
)

// CacheDriver CacheDriver
var CacheDriver *cache.Client

// InitCache InitCache
func InitCache() {
	conf := redis.Options{
		Addr: "redis:6379",
		Password: "sdfsdf",
	}
	CacheDriver = cache.NewClient(conf)
}
InitCache()
Command

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

CacheDriver.RedisClient.Set("key", "value", time.Hour).Err()
CacheDriver.RedisClient.Get("key").Result()
CacheDriver.RedisClient.command()...
use Tag & Put

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

CacheDriver.Tag("user_all", "user_list").Put("user_id:1", &proto.User{Id: 1, Nickname: "111"}, time.Hour)
CacheDriver.Tag("user_all").Put("user_id:2", &proto.User{Id: 2, Nickname: "222"}, time.Hour)
CacheDriver.Tag("user_list").Clear()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RedisDriver *redis.Client

RedisDriver RedisDriver

Functions

This section is empty.

Types

type Client

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

Client Client

func NewClient

func NewClient(conf redis.Options) *Client

NewClient NewClient

func (*Client) Clear

func (c *Client) Clear() error

Clear .Tag().Clear()

func (*Client) Put

func (c *Client) Put(key string, val interface{}, expire time.Duration) error

Put .Tag().Put()

func (*Client) Tag

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

Tag .Tag()

Jump to

Keyboard shortcuts

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