redis

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 3 Imported by: 4

README

Cachego - Redis driver

The drivers uses go-redis to store the cache data.

Usage

package main

import (
	"log"
	"time"

	rd "gopkg.in/redis.v4"

	"github.com/faabiosr/cachego/redis"
)

func main() {
	cache := redis.New(
		rd.NewClient(&rd.Options{
			Addr: ":6379",
		}),
	)

	if err := cache.Save("user_id", "1", 10*time.Second); err != nil {
		log.Fatal(err)
	}

	id, err := cache.Fetch("user_id")
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("user id: %s \n", id)
}

Documentation

Overview

Package redis providers a cache driver that stores the cache in Redis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(driver Cmdable) cachego.Cache

New creates an instance of Redis cache driver

Types

type Cmdable added in v0.18.0

type Cmdable interface {
	Exists(key string) *rd.BoolCmd
	Del(keys ...string) *rd.IntCmd
	Get(key string) *rd.StringCmd
	MGet(keys ...string) *rd.SliceCmd
	FlushAll() *rd.StatusCmd
	Set(key string, value interface{}, expiration time.Duration) *rd.StatusCmd
}

Cmdable defines the base commands used by redis driver.

Jump to

Keyboard shortcuts

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