Skip to content

simple key value cache adapter for golang using redis

License

Notifications You must be signed in to change notification settings

morkid/gocache-redis

Repository files navigation

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.

About

simple key value cache adapter for golang using redis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages