goredis

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package goredis is a simple redis cache implement. base on the package: github.com/go-redis/redis

Example
package main

import (
	"fmt"

	"github.com/gookit/cache/goredis"
)

func main() {
	// init driver
	c := goredis.Connect("127.0.0.1:6379", "", 0)

	// set
	_ = c.Set("name", "cache value", 60)

	// get
	val := c.Get("name")

	// del
	_ = c.Del("name")

	// get: "cache value"
	fmt.Print(val)
}
Output:

Index

Examples

Constants

View Source
const Name = "goredis"

Name driver name

Variables

View Source
var CtxForExec = context.Background()

CtxForExec default ctx for exec command

Functions

This section is empty.

Types

type GoRedis

type GoRedis struct {
	cache.BaseDriver
	// contains filtered or unexported fields
}

GoRedis struct

func Connect

func Connect(url, pwd string, dbNum int) *GoRedis

Connect create and connect to redis server

func New

func New(url, pwd string, dbNum int) *GoRedis

New redis cache

func (*GoRedis) Clear

func (c *GoRedis) Clear() error

Clear all caches

func (*GoRedis) Close

func (c *GoRedis) Close() error

Close connection

func (*GoRedis) Connect

func (c *GoRedis) Connect() *GoRedis

Connect to redis server

func (*GoRedis) Del

func (c *GoRedis) Del(key string) error

Del caches by key

func (*GoRedis) DelMulti

func (c *GoRedis) DelMulti(keys []string) error

DelMulti cache by keys

func (*GoRedis) Get

func (c *GoRedis) Get(key string) interface{}

Get cache by key

func (*GoRedis) GetAs

func (c *GoRedis) GetAs(key string, ptr interface{}) error

GetAs get cache and unmarshal to ptr

func (*GoRedis) GetMulti

func (c *GoRedis) GetMulti(keys []string) map[string]interface{}

GetMulti cache by keys

func (*GoRedis) Has

func (c *GoRedis) Has(key string) bool

Has cache key

func (*GoRedis) Set

func (c *GoRedis) Set(key string, val interface{}, ttl time.Duration) (err error)

Set cache by key

func (*GoRedis) SetMulti

func (c *GoRedis) SetMulti(values map[string]interface{}, ttl time.Duration) (err error)

SetMulti cache by keys

func (*GoRedis) String

func (c *GoRedis) String() string

String get

func (*GoRedis) WithContext added in v0.3.1

func (c *GoRedis) WithContext(ctx context.Context) gsr.ContextCacher

WithContext for operate

Jump to

Keyboard shortcuts

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