redis

package
v0.0.0-...-df5b3c9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example
package main

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

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

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

	err := redisCache.Set(redis.MakeSetIter3(ctx, []string{"key1", "key2"},
		[][]byte{[]byte("value1"), []byte("value2")},
		[]time.Duration{time.Minute, 2 * time.Minute}))
	if err != nil {
		log.Fatal(err)
	}

	iterBytes, err := redisCache.Get(redis.MakeGetIter3(
		ctx, []string{"key1", "key2"}))
	if err != nil {
		log.Fatal(err)
	}
	for b, ok := iterBytes(); ok; b, ok = iterBytes() {
		fmt.Println(string(b))
	}

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeGetIter3

func MakeGetIter3(
	ctx context.Context, keys []string,
) (context.Context, int, func(itemIdx int) string)

func MakeSetIter3

func MakeSetIter3(
	ctx context.Context, keys []string, blobs [][]byte, times []time.Duration,
) (context.Context, int, func(itemIdx int) (key string, b []byte, ttl time.Duration))

Types

type Cmdable

type Cmdable interface {
	redis.Cmdable

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

type RedisCache

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

func New

func New(rdb Cmdable) *RedisCache

func (*RedisCache) Del

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

func (*RedisCache) Expire

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

func (*RedisCache) Get

func (self *RedisCache) Get(ctx context.Context, maxItems int,
	keyIter func(itemIdx int) (key string),
) (func() ([]byte, bool), error)

func (*RedisCache) Listen

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

func (*RedisCache) LockGet

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

func (*RedisCache) Set

func (self *RedisCache) Set(
	ctx context.Context, maxItems int,
	iter func(itemIdx int) (key string, b []byte, ttl time.Duration),
) error

func (*RedisCache) Unlock

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

func (*RedisCache) WithBatchSize

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

func (*RedisCache) WithGetRefreshTTL

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

Jump to

Keyboard shortcuts

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