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)
}
}
Index ¶
- Constants
- Variables
- func Client() redis.UniversalClient
- func Decr(ctx context.Context, key string) *redis.IntCmd
- func DecrBy(ctx context.Context, key string, decrement int64) *redis.IntCmd
- func Del(ctx context.Context, keys ...string) *redis.IntCmd
- func Exists(ctx context.Context, keys ...string) *redis.IntCmd
- func Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
- func ExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd
- func Get(ctx context.Context, key string) *redis.StringCmd
- func HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
- func HExists(ctx context.Context, key, field string) *redis.BoolCmd
- func HGet(ctx context.Context, key, field string) *redis.StringCmd
- func HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
- func HIncrBy(ctx context.Context, key, field string, incr int64) *redis.IntCmd
- func HIncrByFloat(ctx context.Context, key, field string, incr float64) *redis.FloatCmd
- func HKeys(ctx context.Context, key string) *redis.StringSliceCmd
- func HLen(ctx context.Context, key string) *redis.IntCmd
- func HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd
- func HMSet(ctx context.Context, key string, values ...interface{}) *redis.BoolCmd
- func HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
- func HSetNX(ctx context.Context, key, field string, value interface{}) *redis.BoolCmd
- func HVals(ctx context.Context, key string) *redis.StringSliceCmd
- func Incr(ctx context.Context, key string) *redis.IntCmd
- func IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd
- func IncrByFloat(ctx context.Context, key string, value float64) *redis.FloatCmd
- func MGet(ctx context.Context, keys ...string) *redis.SliceCmd
- func MSet(ctx context.Context, values ...interface{}) *redis.StatusCmd
- func MSetNX(ctx context.Context, values ...interface{}) *redis.BoolCmd
- func PExpire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
- func PExpireAt(ctx context.Context, key string, tm time.Time) *redis.BoolCmd
- func PTTL(ctx context.Context, key string) *redis.DurationCmd
- func SCard(ctx context.Context, key string) *redis.IntCmd
- func SDiff(ctx context.Context, keys ...string) *redis.StringSliceCmd
- func SDiffStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd
- func SInter(ctx context.Context, keys ...string) *redis.StringSliceCmd
- func SInterStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd
- func SIsMember(ctx context.Context, key string, member interface{}) *redis.BoolCmd
- func SMembers(ctx context.Context, key string) *redis.StringSliceCmd
- func SMembersMap(ctx context.Context, key string) *redis.StringStructMapCmd
- func SMove(ctx context.Context, source, destination string, member interface{}) *redis.BoolCmd
- func SPop(ctx context.Context, key string) *redis.StringCmd
- func SPopN(ctx context.Context, key string, count int64) *redis.StringSliceCmd
- func SRandMember(ctx context.Context, key string) *redis.StringCmd
- func SRandMemberN(ctx context.Context, key string, count int64) *redis.StringSliceCmd
- func SRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
- func SUnion(ctx context.Context, keys ...string) *redis.StringSliceCmd
- func SUnionStore(ctx context.Context, destination string, keys ...string) *redis.IntCmd
- func Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- func SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- func SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
- func SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
- func TTL(ctx context.Context, key string) *redis.DurationCmd
- func ZAdd(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZAddCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZAddNX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZAddNXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZAddXX(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZAddXXCh(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd
- func ZCard(ctx context.Context, key string) *redis.IntCmd
- func ZCount(ctx context.Context, key, min, max string) *redis.IntCmd
- func ZIncr(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd
- func ZIncrBy(ctx context.Context, key string, increment float64, member string) *redis.FloatCmd
- func ZIncrNX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd
- func ZIncrXX(ctx context.Context, key string, member *redis.Z) *redis.FloatCmd
- func ZInterStore(ctx context.Context, destination string, store *redis.ZStore) *redis.IntCmd
- func ZLexCount(ctx context.Context, key, min, max string) *redis.IntCmd
- func ZPopMax(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd
- func ZPopMin(ctx context.Context, key string, count ...int64) *redis.ZSliceCmd
- func ZRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd
- func ZRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd
- func ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd
- func ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd
- func ZRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd
- func ZRank(ctx context.Context, key, member string) *redis.IntCmd
- func ZRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
- func ZRemRangeByLex(ctx context.Context, key, min, max string) *redis.IntCmd
- func ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *redis.IntCmd
- func ZRemRangeByScore(ctx context.Context, key, min, max string) *redis.IntCmd
- func ZRevRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd
- func ZRevRangeByLex(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd
- func ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.StringSliceCmd
- func ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd
- func ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *redis.ZSliceCmd
- func ZRevRank(ctx context.Context, key, member string) *redis.IntCmd
- func ZScore(ctx context.Context, key, member string) *redis.FloatCmd
- func ZUnionStore(ctx context.Context, dest string, store *redis.ZStore) *redis.IntCmd
- type Config
- type Metric
- func (m *Metric) AfterProcess(ctx context.Context, cmd redis.Cmder) error
- func (m *Metric) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error
- func (m *Metric) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)
- func (m *Metric) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)
- type Redis
- type Script
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 HGetAll ¶ added in v1.0.0
func HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
func HIncrByFloat ¶ added in v1.0.0
func IncrByFloat ¶ added in v1.0.0
func SDiffStore ¶ added in v1.0.0
func SInter ¶ added in v1.0.0
func SInter(ctx context.Context, keys ...string) *redis.StringSliceCmd
func SInterStore ¶ added in v1.0.0
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 SRandMember ¶ added in v1.0.0
func SRandMemberN ¶ added in v1.0.0
func SUnion ¶ added in v1.0.0
func SUnion(ctx context.Context, keys ...string) *redis.StringSliceCmd
func SUnionStore ¶ added in v1.0.0
func ZInterStore ¶ added in v1.0.0
func ZRangeByLex ¶ added in v1.0.0
func ZRangeByScore ¶ added in v1.0.0
func ZRangeByScoreWithScores ¶ added in v1.0.0
func ZRangeWithScores ¶ added in v1.0.0
func ZRemRangeByLex ¶ added in v1.0.0
func ZRemRangeByRank ¶ added in v1.0.0
func ZRemRangeByScore ¶ added in v1.0.0
func ZRevRangeByLex ¶ added in v1.0.0
func ZRevRangeByScore ¶ added in v1.0.0
func ZRevRangeByScoreWithScores ¶ added in v1.0.0
func ZRevRangeWithScores ¶ added in v1.0.0
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
type Metric ¶
type Metric struct {
// contains filtered or unexported fields
}
func (*Metric) AfterProcess ¶
func (*Metric) AfterProcessPipeline ¶
func (*Metric) BeforeProcess ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
func (*Redis) Client ¶
func (r *Redis) Client() redis.UniversalClient
func (*Redis) NewScript ¶ added in v1.0.0
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
Click to show internal directories.
Click to hide internal directories.