redis

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 8 Imported by: 1

README

A companion library for expx-cache

Go GoDoc

Right now this project is under constraction.

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"
	"log"
	"slices"
	"time"

	"github.com/dsh2dsh/expx-cache/model"

	cacheRedis "github.com/dsh2dsh/expx-cache-redis"
)

func main() {
	redisCache, _ := cacheRedis.MustNew()
	ctx := context.Background()

	err := redisCache.Set(ctx, 2, slices.Values([]model.RedisItem{
		model.NewRedisItem("key1", []byte("value1"), time.Minute),
		model.NewRedisItem("key2", []byte("value2"), 2*time.Minute),
	}))
	if err != nil {
		log.Fatal(err)
	}

	iterBytes := redisCache.Get(ctx, 2, slices.Values([]string{"key1", "key2"}))
	for b, err := range iterBytes {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(string(b))
	}

	err = redisCache.Del(ctx, []string{"key1", "key2"})
	if err != nil {
		log.Fatal(err)
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(rdb Cmdable) *Cache

func (*Cache) Del

func (self *Cache) Del(ctx context.Context, keys []string) error

func (*Cache) Expire

func (self *Cache) Expire(ctx context.Context, key string, ttl time.Duration,
) (bool, error)

func (*Cache) Get

func (self *Cache) Get(ctx context.Context, maxItems int,
	keys iter.Seq[string],
) iter.Seq2[[]byte, error]

func (*Cache) Listen

func (self *Cache) Listen(ctx context.Context, key string,
	ready ...func() error,
) (string, error)

func (*Cache) LockGet

func (self *Cache) LockGet(ctx context.Context, keySet, value string,
	ttl time.Duration, keyGet string,
) (ok bool, b []byte, err error)

func (*Cache) Set

func (self *Cache) Set(ctx context.Context, maxItems int,
	items iter.Seq[model.RedisItem],
) error

func (*Cache) Unlock

func (self *Cache) Unlock(ctx context.Context, key, value string,
) (bool, error)

func (*Cache) WithBatchSize

func (self *Cache) WithBatchSize(size int) *Cache

func (*Cache) WithGetRefreshTTL

func (self *Cache) WithGetRefreshTTL(ttl time.Duration) *Cache

type Cmdable

type Cmdable interface {
	redis.Cmdable

	Subscribe(ctx context.Context, channels ...string) *redis.PubSub
}

Jump to

Keyboard shortcuts

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