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