redis

package
v1.0.0-beta.28 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"time"

	"github.com/boxgo/box/pkg/client/redis"
)

func main() {
	ctx := context.TODO()

	if err := redis.Set(ctx, "key", "value", time.Minute).Err(); err != nil {
		panic(err)
	}

	if err := redis.Del(ctx, "key").Err(); err != nil {
		panic(err)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	Nil         = redis.Nil
	TxFailedErr = redis.TxFailedErr
)

Variables

View Source
var (
	Default = StdConfig("default").Build()
)
View Source
var (
	ErrClosed = redis.ErrClosed
)

Functions

func Client

func Client() redis.UniversalClient

func Decr added in v1.0.0

func Decr(ctx context.Context, key string) *redis.IntCmd

func DecrBy added in v1.0.0

func DecrBy(ctx context.Context, key string, decrement int64) *redis.IntCmd

func Del added in v1.0.0

func Del(ctx context.Context, keys ...string) *redis.IntCmd

func Exists added in v1.0.0

func Exists(ctx context.Context, keys ...string) *redis.IntCmd

func Expire added in v1.0.0

func Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd

func ExpireAt added in v1.0.0

func ExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd

func Get added in v1.0.0

func Get(ctx context.Context, key string) *redis.StringCmd

func HDel added in v1.0.0

func HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

func HExists added in v1.0.0

func HExists(ctx context.Context, key, field string) *redis.BoolCmd

func HGet added in v1.0.0

func HGet(ctx context.Context, key, field string) *redis.StringCmd

func HGetAll added in v1.0.0

func HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd

func HIncrBy added in v1.0.0

func HIncrBy(ctx context.Context, key, field string, incr int64) *redis.IntCmd

func HIncrByFloat added in v1.0.0

func HIncrByFloat(ctx context.Context, key, field string, incr float64) *redis.FloatCmd

func HKeys added in v1.0.0

func HKeys(ctx context.Context, key string) *redis.StringSliceCmd

func HLen added in v1.0.0

func HLen(ctx context.Context, key string) *redis.IntCmd

func HMGet added in v1.0.0

func HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd

func HMSet added in v1.0.0

func HMSet(ctx context.Context, key string, values ...interface{}) *redis.BoolCmd

func HSet added in v1.0.0

func HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

func HSetNX added in v1.0.0

func HSetNX(ctx context.Context, key, field string, value interface{}) *redis.BoolCmd

func HVals added in v1.0.0

func HVals(ctx context.Context, key string) *redis.StringSliceCmd

func Incr added in v1.0.0

func Incr(ctx context.Context, key string) *redis.IntCmd

func IncrBy added in v1.0.0

func IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd

func IncrByFloat added in v1.0.0

func IncrByFloat(ctx context.Context, key string, value float64) *redis.FloatCmd

func MGet added in v1.0.0

func MGet(ctx context.Context, keys ...string) *redis.SliceCmd

func MSet added in v1.0.0

func MSet(ctx context.Context, values ...interface{}) *redis.StatusCmd

func MSetNX added in v1.0.0

func MSetNX(ctx context.Context, values ...interface{}) *redis.BoolCmd

func PExpire added in v1.0.0

func PExpire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd

func PExpireAt added in v1.0.0

func PExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd

func PTTL added in v1.0.0

func PTTL(ctx context.Context, key string) *redis.DurationCmd

func SCard added in v1.0.0

func SCard(ctx context.Context, key string) *redis.IntCmd

func SDiff added in v1.0.0

func SDiff(ctx context.Context, keys ...string) *redis.StringSliceCmd

func SDiffStore added in v1.0.0

func SDiffStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

func SInter added in v1.0.0

func SInter(ctx context.Context, keys ...string) *redis.StringSliceCmd

func SInterStore added in v1.0.0

func SInterStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

func SIsMember added in v1.0.0

func SIsMember(ctx context.Context, key string, member interface{}) *redis.BoolCmd

func SMembers added in v1.0.0

func SMembers(ctx context.Context, key string) *redis.StringSliceCmd

func SMembersMap added in v1.0.0

func SMembersMap(ctx context.Context, key string) *redis.StringStructMapCmd

func SMove added in v1.0.0

func SMove(ctx context.Context, source, destination string, member interface{}) *redis.BoolCmd

func SPop added in v1.0.0

func SPop(ctx context.Context, key string) *redis.StringCmd

func SPopN added in v1.0.0

func SPopN(ctx context.Context, key string, count int64) *redis.StringSliceCmd

func SRandMember added in v1.0.0

func SRandMember(ctx context.Context, key string) *redis.StringCmd

func SRandMemberN added in v1.0.0

func SRandMemberN(ctx context.Context, key string, count int64) *redis.StringSliceCmd

func SRem added in v1.0.0

func SRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

func SUnion added in v1.0.0

func SUnion(ctx context.Context, keys ...string) *redis.StringSliceCmd

func SUnionStore added in v1.0.0

func SUnionStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd

func Set added in v1.0.0

func Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

func SetEX added in v1.0.0

func SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

func SetNX added in v1.0.0

func SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd

func SetXX added in v1.0.0

func SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd

func TTL added in v1.0.0

func TTL(ctx context.Context, key string) *redis.DurationCmd

func ZAdd added in v1.0.0

func ZAdd(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZAddCh added in v1.0.0

func ZAddCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZAddNX added in v1.0.0

func ZAddNX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZAddNXCh added in v1.0.0

func ZAddNXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZAddXX added in v1.0.0

func ZAddXX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZAddXXCh added in v1.0.0

func ZAddXXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd

func ZCard added in v1.0.0

func ZCard(ctx context.Context, key string) *redis.IntCmd

func ZCount added in v1.0.0

func ZCount(ctx context.Context, key, min, max string) *redis.IntCmd

func ZIncr added in v1.0.0

func ZIncr(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

func ZIncrBy added in v1.0.0

func ZIncrBy(ctx context.Context, key string, increment float64, member string) *redis.FloatCmd

func ZIncrNX added in v1.0.0

func ZIncrNX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

func ZIncrXX added in v1.0.0

func ZIncrXX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd

func ZInterStore added in v1.0.0

func ZInterStore(ctx context.Context, destination string, store *redis.ZStore) *redis.IntCmd

func ZLexCount added in v1.0.0

func ZLexCount(ctx context.Context, key, min, max string) *redis.IntCmd

func ZPopMax added in v1.0.0

func ZPopMax(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd

func ZPopMin added in v1.0.0

func ZPopMin(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd

func ZRange added in v1.0.0

func ZRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd

func ZRangeByLex added in v1.0.0

func ZRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

func ZRangeByScore added in v1.0.0

func ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

func ZRangeByScoreWithScores added in v1.0.0

func ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd

func ZRangeWithScores added in v1.0.0

func ZRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd

func ZRank added in v1.0.0

func ZRank(ctx context.Context, key, member string) *redis.IntCmd

func ZRem added in v1.0.0

func ZRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

func ZRemRangeByLex added in v1.0.0

func ZRemRangeByLex(ctx context.Context, key, min, max string) *redis.IntCmd

func ZRemRangeByRank added in v1.0.0

func ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *redis.IntCmd

func ZRemRangeByScore added in v1.0.0

func ZRemRangeByScore(ctx context.Context, key, min, max string) *redis.IntCmd

func ZRevRange added in v1.0.0

func ZRevRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd

func ZRevRangeByLex added in v1.0.0

func ZRevRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

func ZRevRangeByScore added in v1.0.0

func ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd

func ZRevRangeByScoreWithScores added in v1.0.0

func ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd

func ZRevRangeWithScores added in v1.0.0

func ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd

func ZRevRank added in v1.0.0

func ZRevRank(ctx context.Context, key, member string) *redis.IntCmd

func ZScore added in v1.0.0

func ZScore(ctx context.Context, key, member string) *redis.FloatCmd

func ZUnionStore added in v1.0.0

func ZUnionStore(ctx context.Context, dest string, store *redis.ZStore) *redis.IntCmd

Types

type Config added in v1.0.0

type Config struct {
	MasterName     string   `config:"masterName" desc:"The sentinel master name. Only failover clients."`
	Address        []string `config:"address" desc:"Either a single address or a seed list of host:port addresses of cluster/sentinel nodes."`
	Password       string   `config:"password" desc:"Redis password"`
	DB             int      `config:"db" desc:"Database to be selected after connecting to the server. Only single-node and failover clients."`
	PoolSize       int      `config:"poolSize" desc:"Connection pool size"`
	MinIdleConnCnt int      `config:"minIdleConnCnt" desc:"Min idle connections."`
	// contains filtered or unexported fields
}

func DefaultConfig added in v1.0.0

func DefaultConfig(key string) *Config

func StdConfig added in v1.0.0

func StdConfig(key string) *Config

func (*Config) Build added in v1.0.0

func (c *Config) Build() *Redis

func (*Config) Path added in v1.0.0

func (c *Config) Path() string

type Metric

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

func (*Metric) AfterProcess

func (m *Metric) AfterProcess(ctx context.Context, cmd redis.Cmder) error

func (*Metric) AfterProcessPipeline

func (m *Metric) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

func (*Metric) BeforeProcess

func (m *Metric) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)

func (*Metric) BeforeProcessPipeline

func (m *Metric) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)

type Redis

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

func (*Redis) Client

func (r *Redis) Client() redis.UniversalClient

func (*Redis) Name

func (r *Redis) Name() string

func (*Redis) NewScript added in v1.0.0

func (r *Redis) NewScript(script string) *Script
Example
package main

import (
	"context"
	"fmt"

	"github.com/boxgo/box/pkg/client/redis"
)

func main() {
	ctx := context.TODO()

	IncrByXX := redis.Default.NewScript(`
		return redis.call("INCRBY", KEYS[1], ARGV[1])
	`)

	defer redis.Del(ctx, "xx_counter")

	if n, err := IncrByXX.Run(ctx, []string{"xx_counter"}, 100).Result(); err != nil {
		panic(err)
	} else {
		fmt.Println(n)
	}

	if err := redis.Set(ctx, "xx_counter", "40", 0).Err(); err != nil {
		panic(err)
	}

	if n, err := IncrByXX.Run(ctx, []string{"xx_counter"}, 2).Result(); err != nil {
		panic(err)
	} else {
		fmt.Println(n)
	}

}
Output:

100
42

func (*Redis) Serve

func (r *Redis) Serve(ctx context.Context) error

func (*Redis) Shutdown

func (r *Redis) Shutdown(ctx context.Context) error

type Script added in v1.0.0

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

func NewScript added in v1.0.0

func NewScript(src string) *Script

func (Script) Run added in v1.0.0

func (script Script) Run(ctx context.Context, keys []string, args ...interface{}) *redis.Cmd

Jump to

Keyboard shortcuts

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