redis

package module
v0.0.0-...-20b2a55 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

Redis Cacher for cache embedder

This directory contains the implementation of a Redis cacher for the cache embedder.

Installation

go get github.com/cloudwego/eino-ext/components/embedding/cache/redis

Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/redis/go-redis/v9"
	cacheredis "github.com/cloudwego/eino-ext/components/embedding/cache/redis"
)

func main() {
	ctx := context.Background()
	rdb := redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
	})

	cacher := cacheredis.NewCacher(rdb,
		cacheredis.WithPrefix("eino:embedding:"),
	)

	if err := cacher.Set(ctx, "example_key", []float64{1.0, 2.0, 3.0}, time.Second*10); err != nil {
		panic(err)
	}

	value, found, err := cacher.Get(ctx, "example_key")
	if err != nil {
		panic(err)
	}
	fmt.Println("value:", value, "found:", found)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher struct {
	// contains filtered or unexported fields
}

func NewCacher

func NewCacher(rdb redis.UniversalClient, opts ...Option) *Cacher

func (*Cacher) Get

func (c *Cacher) Get(ctx context.Context, key string) ([]float64, bool, error)

func (*Cacher) Set

func (c *Cacher) Set(ctx context.Context, key string, value []float64, expire time.Duration) error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithPrefix

func WithPrefix(prefix string) Option

Jump to

Keyboard shortcuts

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