redis

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package redis implements a redis adapter for github.com/hamba/pkg/cache.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OptsFunc

type OptsFunc func(*redis.Options)

OptsFunc represents an configuration function for Redis.

func WithPoolSize

func WithPoolSize(size int) OptsFunc

WithPoolSize configures the Redis pool size.

func WithPoolTimeout

func WithPoolTimeout(timeout time.Duration) OptsFunc

WithPoolTimeout configures the Redis pool timeout.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) OptsFunc

WithReadTimeout configures the Redis read timeout.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) OptsFunc

WithWriteTimeout configures the Redis write timeout.

type Redis

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

Redis is a redis adapter.

func New

func New(uri string, opts ...OptsFunc) (*Redis, error)

New create a new Redis instance.

Example
package main

import (
	"context"
	"time"

	"github.com/hamba/cache/v2/redis"
)

func main() {
	c, err := redis.New("redis://localhost:6379", redis.WithReadTimeout(10*time.Millisecond))
	if err != nil {
		// Handle error
	}

	i := c.Get(context.Background(), "foobar")
	if i.Err != nil {
		// Handle error
	}

	_, _ = i.Float64()
}

func (Redis) Add

func (c Redis) Add(ctx context.Context, key string, value interface{}, expire time.Duration) error

Add sets the item in the cache, but only if the key does not already exist.

func (Redis) Dec

func (c Redis) Dec(ctx context.Context, key string, value uint64) (int64, error)

Dec decrements a key by the value.

func (Redis) Delete

func (c Redis) Delete(ctx context.Context, key string) error

Delete deletes the item with the given key.

func (Redis) Get

func (c Redis) Get(ctx context.Context, key string) cache.Item

Get gets the item for the given key.

func (Redis) GetMulti

func (c Redis) GetMulti(ctx context.Context, keys ...string) ([]cache.Item, error)

GetMulti gets the items for the given keys.

func (Redis) Inc

func (c Redis) Inc(ctx context.Context, key string, value uint64) (int64, error)

Inc increments a key by the value.

func (Redis) Replace

func (c Redis) Replace(ctx context.Context, key string, value interface{}, expire time.Duration) error

Replace sets the item in the cache, but only if the key already exists.

func (Redis) Set

func (c Redis) Set(ctx context.Context, key string, value interface{}, expire time.Duration) error

Set sets the item in the cache.

Jump to

Keyboard shortcuts

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