Categorygithub.com/morkid/gocache-redis/v8
modulepackage
8.0.2
Repository: https://github.com/morkid/gocache-redis.git
Documentation: pkg.go.dev

# 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.

# Functions

NewRedisCache func.

# Structs

RedisCacheConfig base config for redis cache adapter.