cache

package module
v8.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 5 Imported by: 1

README

cache redis adapter

Go Reference Go Build Status Go Report Card GitHub release (latest SemVer)

This library is created by implementing gocache and require redis v8.

Installation

go get -d github.com/morkid/gocache-redis/v8

Available versions:

Example usage

package main

import (
    "time"
    "fmt"
    cache "github.com/morkid/gocache-redis/v8"
    "github.com/go-redis/redis/v8"
)

func main() {
    client := redis.NewClient(&redis.Options{
        Addr:     "localhost:6379",
        Password: "",
        DB:       0,
    })

    config := cache.RedisCacheConfig{
        Client:    client,
        ExpiresIn: 10 * time.Second,
    }

    adapter := *cache.NewRedisCache(config)
    adapter.Set("foo", "bar")

    if adapter.IsValid("foo") {
        value, err := adapter.Get("foo")
        if nil != err {
            fmt.Println(err)
        } else if value != "bar" {
            fmt.Println("value not equals to bar")
        } else {
            fmt.Println(value)
        }
        adapter.Clear("foo")
        if adapter.IsValid("foo") {
            fmt.Println("Failed to remove key foo")
        }
    }
}

License

Published under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisCache

func NewRedisCache(config RedisCacheConfig) *gocache.AdapterInterface

NewRedisCache func

Types

type RedisCacheConfig

type RedisCacheConfig struct {
	Client        *redis.Client
	ClusterClient *redis.ClusterClient
	ExpiresIn     time.Duration
}

RedisCacheConfig base config for redis cache adapter

Jump to

Keyboard shortcuts

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