gredis

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNil                  = redis.Nil
	ErrZAddKVLengthNotMatch = errors.New("ERR_ZADD_KV_LENGTH_NOT_MATCH")
)
View Source
var (
	ErrCanNotMarshalAsProtobufMessage   = errors.New("ErrCanNotMarshalAsProtobufMessage")
	ErrCanNotUnmarshalAsProtobufMessage = errors.New("ErrCanNotUnmarshalAsProtobufMessage")
)
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 Uint64

func Uint64(v int64, err error) (uint64, error)

Types

type Generic

type Generic interface {
	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)
}

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 Mode

type Mode uint8
const (
	Single Mode = iota
	Cluster
)

type ObjMarshaller

type ObjMarshaller interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

type Object

type Object interface {
	GetObject(ctx context.Context, key string, obj interface{}) error
	SetObject(ctx context.Context, key string, obj interface{}) error
	SetObjectEx(ctx context.Context, key string, obj interface{}, expiration time.Duration) 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
	Object
}

RedisClient introduce all the gredis method we need for gredis bot and also with context support

func NewRedisClient

func NewRedisClient(option *RedisClientOption) (RedisClient, error)

NewRedisClient create a redisClient object from config it will create bot 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, redisDBKey string) (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          ObjMarshaller
}

RedisClientOption gredis bot option

type SelfMarshaller

type SelfMarshaller interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
}

type SortedSet

type SortedSet interface {
	ZAdd(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
}

type String

type String interface {
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
	Set(ctx context.Context, key string, value interface{}) error
	SetEx(ctx context.Context, key string, value interface{}, 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)
}

Jump to

Keyboard shortcuts

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