redis

package
v1.0.2-0...-10d6d69 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 4 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 (
	"time"

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

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

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

	_, _ = i.Float64()
}

func (Redis) Add

func (c Redis) Add(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(key string, value uint64) (int64, error)

Dec decrements a key by the value.

func (Redis) Delete

func (c Redis) Delete(key string) error

Delete deletes the item with the given key.

func (Redis) Get

func (c Redis) Get(key string) cache.Item

Get gets the item for the given key.

func (Redis) GetMulti

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

GetMulti gets the items for the given keys.

func (Redis) Inc

func (c Redis) Inc(key string, value uint64) (int64, error)

Inc increments a key by the value.

func (Redis) Replace

func (c Redis) Replace(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(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