Documentation
¶
Index ¶
- Constants
- Variables
- func ToString(v any, err error) (string, error)
- func ToStringSlice(values any, err error) ([]string, error)
- func ToStringStringMap(values any, err error) (map[string]string, error)
- func ToUint32(v any, err error) (uint32, error)
- func ToUint64(v any, err error) (uint64, error)
- func ToUint64Slice(values any, err error) ([]uint64, error)
- type DB
- func (db *DB) GetObject(ctx context.Context, key string, obj any) error
- func (db *DB) GetObjects(ctx context.Context, keys []string, objs any) error
- func (db *DB) HGetAllObjects(ctx context.Context, key string, fields *[]string, objs any) error
- func (db *DB) HGetObject(ctx context.Context, key string, field string, obj any) error
- func (db *DB) HMGetObjects(ctx context.Context, key string, fields []string, objs any) error
- func (db *DB) HSetObjects(ctx context.Context, key string, values ...any) error
- func (db *DB) IsErrNil(err error) bool
- func (db *DB) SetObject(ctx context.Context, key string, obj any) error
- func (db *DB) SetObjectEX(ctx context.Context, key string, obj any, expiration time.Duration) error
- func (db *DB) SetObjects(ctx context.Context, keys []string, objs any) error
- func (db *DB) SetObjectsEX(ctx context.Context, keys []string, objs any, expiration time.Duration) error
- func (db *DB) ZAddObjects(ctx context.Context, key string, values ...any) (int64, error)
- func (db *DB) ZRangeObjects(ctx context.Context, key string, start, stop int64, objs any) error
- func (db *DB) ZRangeObjectsByScore(ctx context.Context, key string, min, max string, objs any) error
- func (db *DB) ZRangeObjectsByScoreWithScores(ctx context.Context, key string, min, max string, objs any) (scores []float64, err error)
- func (db *DB) ZRangeObjectsWithScores(ctx context.Context, key string, start, stop int64, objs any) (scores []float64, err error)
- func (db *DB) ZRankObject(ctx context.Context, key string, member any) (int64, error)
- func (db *DB) ZRemObjects(ctx context.Context, key string, values ...any) (int64, error)
- func (db *DB) ZRevRangeObjects(ctx context.Context, key string, start, stop int64, objs any) error
- func (db *DB) ZRevRangeObjectsByScore(ctx context.Context, key string, min, max string, objs any) error
- func (db *DB) ZRevRangeObjectsByScoreWithScores(ctx context.Context, key string, min, max string, objs any) (scores []float64, err error)
- func (db *DB) ZRevRangeObjectsWithScores(ctx context.Context, key string, start, stop int64, objs any) (scores []float64, err error)
- func (db *DB) ZRevRankObject(ctx context.Context, key string, member any) (int64, error)
- func (db *DB) ZScoreObject(ctx context.Context, key string, member any) (float64, error)
- type Generic
- type Hash
- type JsonMarshaller
- type KOMapping
- type Marshaller
- type Mode
- type ObjectDB
- type Pipeliner
- type PipelinerObject
- type ProtoCompressMarshaller
- type ProtoMarshaller
- type RedisClient
- type RedisClientOption
- type SelfMarshaller
- type SortedSet
- type String
- type TraceHook
- func (h *TraceHook) AfterProcess(ctx context.Context, cmd redis.Cmder) (err error)
- func (h *TraceHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) (err error)
- func (h *TraceHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)
- func (h *TraceHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)
Constants ¶
View Source
const ( ProtoCompressLengthLimit = 1024 ProtoCompressFlagZstd = byte(1)<<6 | 7 // 01000111 )
Variables ¶
View Source
var ( ErrValue = errors.New("ERR_VALUE") ErrValueType = errors.New("ERR_VALUE_TYPE") )
View Source
var ( PanicKeyIsMissing = "db key missing" PanicKeyValueCountUnmatched = "key value count unmatched" PanicValueDstNeedBeSlice = "value dst need be slice" PanicValueNeedBeSlice = "value need be slice" PanicValueDstNeedBePointer = "value dst object need be pointer" PanicValueDstNeedBeAllocated = "value dst object need be pointer allocated" PanicFieldValueCountUnmatched = "field value count unmatched" PanicFieldsIsMissing = "field is missing" PanicScoreValueCountUnmatched = "score value count unmatched" PanicHSetUnsupportedValueType = "hset unsupported value type" PanicValueNotNum = "value is not number" )
View Source
var ( ErrCanNotMarshalAsProtobufMessage = errors.New("ErrCanNotMarshalAsProtobufMessage") ErrCanNotUnmarshalAsProtobufMessage = errors.New("ErrCanNotUnmarshalAsProtobufMessage") ErrCompressBytesFailed = errors.New("ErrCompressBytesFailed") ErrDecompressBytesFailed = errors.New("ErrDecompressBytesFailed") )
View Source
var ( // ErrConfigNotFound is returned when gredis config can not be found ErrConfigNotFound = errors.New("can not find gredis config") // ErrTTLKeyNotExpireSet is returned when ttl key exists but has no associated expire ErrTTLKeyNotExpireSet = errors.New("ttl key exists but has no associated expire") // ErrTTLKeyNotExist is returned when ttl key not exist ErrTTLKeyNotExist = errors.New("ttl key not exist") ErrRedisConfigNotFound = errors.New("can not find gredis config") )
Functions ¶
func ToStringSlice ¶
ToStringSlice convert []*redis.StringCmd, *redis.SliceCmd and *redis.StringSliceCmd to []string, when *redis.Slice, the value inside should be string.
func ToStringStringMap ¶
ToStringStringMap convert *redis.StringStringMapCmd to []string, when *redis.Slice, the value inside should be string.
Types ¶
type DB ¶
type DB struct { ObjectDB // support redis db or mongo db(TODO) RedisClient }
func NewDB ¶ added in v0.1.3
func NewDB(redisClient RedisClient, koMapping KOMapping) *DB
func (*DB) GetObjects ¶
func (*DB) HGetAllObjects ¶
func (*DB) HGetObject ¶
func (*DB) HMGetObjects ¶
func (*DB) HSetObjects ¶
func (*DB) SetObjectEX ¶
func (*DB) SetObjects ¶
func (*DB) SetObjectsEX ¶
func (*DB) ZAddObjects ¶
func (*DB) ZRangeObjects ¶
func (*DB) ZRangeObjectsByScore ¶
func (*DB) ZRangeObjectsByScoreWithScores ¶
func (*DB) ZRangeObjectsWithScores ¶
func (*DB) ZRankObject ¶
func (*DB) ZRemObjects ¶
func (*DB) ZRevRangeObjects ¶
func (*DB) ZRevRangeObjectsByScore ¶
func (*DB) ZRevRangeObjectsByScoreWithScores ¶
func (*DB) ZRevRangeObjectsWithScores ¶
func (*DB) ZRevRankObject ¶
type Generic ¶
type Generic interface { IsErrNil(err error) bool Exists(ctx context.Context, key string) (bool, error) TTL(ctx context.Context, key string) (time.Duration, error) Del(ctx context.Context, key string) (uint32, error) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error) ExpireAt(ctx context.Context, key string, t time.Time) (bool, error) ExpireAtTS(ctx context.Context, key string, ts int64) (bool, error) }
type Hash ¶
type Hash interface { HGet(ctx context.Context, key, field string) (string, error) HSet(ctx context.Context, key string, values ...any) error HMSet(ctx context.Context, key string, values ...any) (bool, error) HMGet(ctx context.Context, key string, fields ...string) ([]any, error) HGetAll(ctx context.Context, key string) (map[string]string, error) HDel(ctx context.Context, key string, fields ...string) (int64, error) HLen(ctx context.Context, key string) (int64, error) }
type JsonMarshaller ¶
type JsonMarshaller struct{}
func (*JsonMarshaller) Marshal ¶
func (jm *JsonMarshaller) Marshal(v interface{}) ([]byte, error)
func (*JsonMarshaller) Unmarshal ¶
func (jm *JsonMarshaller) Unmarshal(data []byte, v interface{}) error
type Marshaller ¶
type ObjectDB ¶
type ObjectDB interface { SetKOMapping(map[string]string) CheckKeyObjMatch(key string, obj any) // GetObject get data from db of the key, and unmarshal into obj. // obj should be a struct point, and should be memory allocated GetObject(ctx context.Context, key string, obj any) error // SetObject set data into db by the key, the data is unmarshalled from obj. // obj should be a struct point, and not nil. SetObject(ctx context.Context, key string, obj any) error // SetObjectEX set data into db by the key with expiration, the data is unmarshalled from obj. // obj should be a struct point, and not nil. SetObjectEX(ctx context.Context, key string, obj any, expiration time.Duration) error // GetObjects get datas from db of all keys, and unmarshal into objs. // objs should be a slice of struct points, and slice should be memory allocated. GetObjects(ctx context.Context, keys []string, objs any) error // SetObjects set datas into db by keys, the datas is marshalled from objs. // objs should be a slice. SetObjects(ctx context.Context, keys []string, objs any) error // SetObjectsEX set datas into db by keys with expiration, the datas is unmarshalled from objs. // objs should be a slice. SetObjectsEX(ctx context.Context, keys []string, objs any, expiration time.Duration) error // HSetObjects set filed value pairs into db by the key, value will be marshalled before set. HSetObjects(ctx context.Context, key string, values ...any) error // HGetObject get data from db with the key and the field, and unmarshal into obj. // obj should be a struct point, and should be memory allocated HGetObject(ctx context.Context, key string, field string, obj any) error // HMGetObjects get datas from db with the key and the fields, and unmarshall into objs. // objs should be a slice of struct points, and the slice should be memory allocated. HMGetObjects(ctx context.Context, key string, fields []string, objs any) error // HGetAllObjects get datas from db with the key and the fields, and unmarshall into objs, // field_name will be set into fields, objs should be a point of a slice of same struct or struct points. HGetAllObjects(ctx context.Context, key string, fields *[]string, objs any) error // ZAddObjects add score and member pairs into db by the key. score should be a number, // member will be marshalled before set. ZAddObjects(ctx context.Context, key string, values ...any) (int64, error) // ZRangeObjects ZRange members from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct points. ZRangeObjects(ctx context.Context, key string, start, stop int64, objs any) error // ZRangeObjectsByScore ZRange members from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct points. ZRangeObjectsByScore(ctx context.Context, key string, min, max string, objs any) error // ZRangeObjectsWithScores ZRange members with scores from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct or struct points. ZRangeObjectsWithScores(ctx context.Context, key string, start, stop int64, objs any) (scores []float64, err error) // ZRangeObjectsByScoreWithScores ZRange members with scores from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct or struct points. ZRangeObjectsByScoreWithScores(ctx context.Context, key string, min, max string, objs any) (scores []float64, err error) // ZRevRangeObjects ZRevRange members from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct points. ZRevRangeObjects(ctx context.Context, key string, start, stop int64, objs any) error // ZRevRangeObjectsByScore ZRevRangeByScore members from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct points. ZRevRangeObjectsByScore(ctx context.Context, key string, min, max string, objs any) error // ZRevRangeObjectsWithScores ZRevRange members with scores from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct or struct points. ZRevRangeObjectsWithScores(ctx context.Context, key string, start, stop int64, objs any) (scores []float64, err error) // ZRevRangeObjectsByScoreWithScores ZRevRangeByScore members with scores from zset of the key, and unmarshall members into objs. // objs should be a point of a slice of struct or struct points. ZRevRangeObjectsByScoreWithScores(ctx context.Context, key string, min, max string, objs any) (scores []float64, err error) ZRankObject(ctx context.Context, key string, member any) (int64, error) ZRevRankObject(ctx context.Context, key string, member any) (int64, error) ZScoreObject(ctx context.Context, key string, member any) (float64, error) ZRemObjects(ctx context.Context, key string, members ...any) (int64, error) }
type PipelinerObject ¶
type ProtoCompressMarshaller ¶
type ProtoCompressMarshaller struct{}
func (*ProtoCompressMarshaller) Marshal ¶
func (pcm *ProtoCompressMarshaller) Marshal(v interface{}) ([]byte, error)
func (*ProtoCompressMarshaller) Unmarshal ¶
func (pcm *ProtoCompressMarshaller) Unmarshal(data []byte, v interface{}) error
type ProtoMarshaller ¶
type ProtoMarshaller struct{}
func (*ProtoMarshaller) Marshal ¶
func (pm *ProtoMarshaller) Marshal(v interface{}) ([]byte, error)
func (*ProtoMarshaller) Unmarshal ¶
func (pm *ProtoMarshaller) Unmarshal(data []byte, v interface{}) error
type RedisClient ¶
type RedisClient interface { io.Closer Generic String Hash SortedSet ObjectDB Pipeline() Pipeliner TxPipeline() Pipeliner }
RedisClient introduce all the gredis method we need for gredis client and also with context support
func NewRedisClient ¶
func NewRedisClient(option *RedisClientOption) (RedisClient, error)
NewRedisClient create a redisClient object from config it will create client connect to single, ring or cluster based on the configuration currently we only support redisClient, may add more in the future (for example , v9Client?), so we return an interface
func NewRedisClientByConfig ¶
func NewRedisClientByConfig(cfg env.ModuleConfig, marshaller string, tracer opentracing.Tracer) (RedisClient, error)
type RedisClientOption ¶
type RedisClientOption struct { Mode Mode Addr string Password string Db int PoolSize int Addrs map[string]string ClusterAddrs []string ClusterMaxRedirects int ClusterReadOnly bool DialTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration Marshaller gmarshaller.Marshaller Hooks []redis.Hook }
RedisClientOption gredis client option
type SelfMarshaller ¶
type SortedSet ¶
type SortedSet interface { ZAdd(ctx context.Context, key string, values ...any) (int64, error) ZCard(ctx context.Context, key string) (int64, error) ZCount(ctx context.Context, key string, min, max string) (int64, error) ZIncrBy(ctx context.Context, key string, increment float64, member any) (float64, error) ZRange(ctx context.Context, key string, start, stop int64) ([]string, error) ZRangeByScore(ctx context.Context, key string, min, max string) ([]string, error) ZRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error) ZRangeByScoreWithScores(ctx context.Context, key string, min, max string) ([]redis.Z, error) ZRevRange(ctx context.Context, key string, start, stop int64) ([]string, error) ZRevRangeByScore(ctx context.Context, key string, min, max string) ([]string, error) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error) ZRevRangeByScoreWithScores(ctx context.Context, key string, min, max string) ([]redis.Z, error) ZRank(ctx context.Context, key string, member any) (int64, error) ZRevRank(ctx context.Context, key string, member any) (int64, error) ZRem(ctx context.Context, key string, members ...any) (int64, error) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error) ZRemRangeByScore(ctx context.Context, key string, min, max string) (int64, error) ZScore(ctx context.Context, key string, member any) (float64, error) }
type String ¶
type String interface { SetNX(ctx context.Context, key string, value any) (bool, error) SetEXNX(ctx context.Context, key string, value any, expiration time.Duration) (bool, error) Set(ctx context.Context, key string, value any) error SetEX(ctx context.Context, key string, value any, expiration time.Duration) error Get(ctx context.Context, key string) (string, error) Incr(ctx context.Context, key string) (int64, error) IncrBy(ctx context.Context, key string, value int64) (int64, error) BatchGet(ctx context.Context, keys []string) ([]*redis.StringCmd, error) BatchSet(ctx context.Context, keys []string, values []any, expiration time.Duration) error BatchDel(ctx context.Context, keys []string) error }
type TraceHook ¶
type TraceHook struct { Tracer opentracing.Tracer Instance string RedisMode string Marshaller string }
func (*TraceHook) AfterProcess ¶
func (*TraceHook) AfterProcessPipeline ¶
func (*TraceHook) BeforeProcess ¶
Click to show internal directories.
Click to hide internal directories.