redis

package
v2.0.0-...-c87de9c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"
	"time"

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

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

	client := redis.New(&redis.Options{
		Addrs: []string{"127.0.0.1:6379"},
	})

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

	if val, err := client.Get(ctx, "key").Result(); err != nil {
		panic(err)
	} else if val != "value" {
		panic(err)
	} else {
		fmt.Println(val)
	}

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

}
Output:

value

Index

Examples

Constants

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

Variables

View Source
var (
	ErrClosed = redis.ErrClosed
)

Functions

This section is empty.

Types

type Options

type Options = redis.UniversalOptions

type Redis

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

func New

func New(opts *redis.UniversalOptions) *Redis

func (*Redis) Client

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

func (*Redis) Decr

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

func (*Redis) DecrBy

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

func (*Redis) Del

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

func (*Redis) Exists

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

func (*Redis) Expire

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

func (*Redis) ExpireAt

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

func (*Redis) Get

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

func (*Redis) HDel

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

func (*Redis) HExists

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

func (*Redis) HGet

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

func (*Redis) HGetAll

func (r *Redis) HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd

func (*Redis) HIncrBy

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

func (*Redis) HIncrByFloat

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

func (*Redis) HKeys

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

func (*Redis) HLen

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

func (*Redis) HMGet

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

func (*Redis) HMSet

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

func (*Redis) HSet

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

func (*Redis) HSetNX

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

func (*Redis) HVals

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

func (*Redis) Incr

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

func (*Redis) IncrBy

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

func (*Redis) IncrByFloat

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

func (*Redis) MGet

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

func (*Redis) MSet

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

func (*Redis) MSetNX

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

func (*Redis) Name

func (r *Redis) Name() string

func (*Redis) NewScript

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

import (
	"context"
	"fmt"

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

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

	client := redis.New(&redis.Options{
		Addrs: []string{"127.0.0.1:6379"},
	})

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

	defer client.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 := client.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) PExpire

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

func (*Redis) PExpireAt

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

func (*Redis) PTTL

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

func (*Redis) SCard

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

func (*Redis) SDiff

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

func (*Redis) SDiffStore

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

func (*Redis) SInter

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

func (*Redis) SInterStore

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

func (*Redis) SIsMember

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

func (*Redis) SMembers

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

func (*Redis) SMembersMap

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

func (*Redis) SMove

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

func (*Redis) SPop

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

func (*Redis) SPopN

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

func (*Redis) SRandMember

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

func (*Redis) SRandMemberN

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

func (*Redis) SRem

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

func (*Redis) SUnion

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

func (*Redis) SUnionStore

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

func (*Redis) Serve

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

func (*Redis) Set

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

func (*Redis) SetEX

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

func (*Redis) SetNX

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

func (*Redis) SetXX

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

func (*Redis) Shutdown

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

func (*Redis) TTL

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

func (*Redis) ZAdd

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

func (*Redis) ZAddNX

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

func (*Redis) ZAddXX

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

func (*Redis) ZCard

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

func (*Redis) ZCount

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

func (*Redis) ZIncrBy

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

func (*Redis) ZInterStore

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

func (*Redis) ZLexCount

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

func (*Redis) ZPopMax

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

func (*Redis) ZPopMin

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

func (*Redis) ZRange

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

func (*Redis) ZRangeByLex

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

func (*Redis) ZRangeByScore

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

func (*Redis) ZRangeByScoreWithScores

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

func (*Redis) ZRangeWithScores

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

func (*Redis) ZRank

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

func (*Redis) ZRem

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

func (*Redis) ZRemRangeByLex

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

func (*Redis) ZRemRangeByRank

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

func (*Redis) ZRemRangeByScore

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

func (*Redis) ZRevRange

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

func (*Redis) ZRevRangeByLex

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

func (*Redis) ZRevRangeByScore

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

func (*Redis) ZRevRangeByScoreWithScores

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

func (*Redis) ZRevRangeWithScores

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

func (*Redis) ZRevRank

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

func (*Redis) ZScore

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

func (*Redis) ZUnionStore

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

type Script

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

func (Script) Run

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