Documentation ¶
Index ¶
- Constants
- Variables
- func RedisValueMapToMap[V any](vMap RedisValueMap, filterFn func(*V) bool) (map[string]*V, error)
- func RedisValueMapToSlice[V any](vMap RedisValueMap, filterFn func(*V) bool) ([]*V, error)
- type IRedisHashService
- type IRedisKeyService
- type IRedisPipelineService
- type IRedisService
- type IRedisStringService
- type IRedisValue
- type MarshalFunc
- type RedisHashService
- func (s *RedisHashService) HashGet(key string, field string, opts ...RedisValueOption) IRedisValue
- func (s *RedisHashService) HashGetAll(key string, opts ...RedisValueOption) (RedisValueMap, error)
- func (s *RedisHashService) HashSet(key string, values map[string]interface{}, opts ...RedisValueOption) error
- type RedisKeyService
- func (s *RedisKeyService) DeleteKey(key string, opts ...RedisValueOption) error
- func (s *RedisKeyService) DeleteKeys(pattern string, opts ...RedisValueOption) error
- func (s *RedisKeyService) ExistKey(key string, opts ...RedisValueOption) (bool, error)
- func (s *RedisKeyService) GetRedisClient() *redis.Client
- func (s *RedisKeyService) KeyExpire(key string, duration time.Duration, opts ...RedisValueOption) error
- func (s *RedisKeyService) KeyTimeToLive(key string, opts ...RedisValueOption) *time.Duration
- func (s *RedisKeyService) Keys(keyPattern string, opts ...RedisValueOption) ([]string, error)
- type RedisLock
- type RedisOptions
- type RedisPipelineService
- type RedisStringService
- func (s *RedisStringService) GetDecr(key string, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) GetIncr(key string, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) KeyDecr(key string, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) KeyDecrBy(key string, decrement int64, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) KeyIncr(key string, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) KeyIncrBy(key string, value int64, opts ...RedisValueOption) (int64, error)
- func (s *RedisStringService) StringGet(key string, opts ...RedisValueOption) IRedisValue
- func (s *RedisStringService) StringMGet(opts []RedisValueOption, keys ...string) (map[string]IRedisValue, error)
- func (s *RedisStringService) StringSet(key string, value interface{}, opts ...RedisValueOption) error
- type RedisValueMap
- type RedisValueOption
- func SuppressedLoadIfEmpty() RedisValueOption
- func WithContext(ctx context.Context) RedisValueOption
- func WithExpiredTime(expiredTime time.Time) RedisValueOption
- func WithKeyPrefix(keyPrefix string) RedisValueOption
- func WithMarshalFunc(marshal MarshalFunc) RedisValueOption
- func WithTTL(ttl time.Duration) RedisValueOption
- func WithUnmarshalFunc(unmarshal UnmarshalFunc) RedisValueOption
- func WithoutPrefixKey() RedisValueOption
- type RedisValueOptions
- type UnmarshalFunc
Constants ¶
View Source
const ( //redis过期时间(30分钟) Redis_30M_TTL time.Duration = time.Duration(30) * time.Minute //redis过期时间(24小时) Redis_24Hour_TTL time.Duration = time.Duration(24) * time.Hour //1个月的有效期 Redis_Expiration_Month_TTL time.Duration = time.Duration(30) * time.Hour * 24 //无过期时间 Redis_NoExpiration_TTL time.Duration = time.Duration(-1) )
View Source
const (
RedisRandLen = 16
)
Variables ¶
View Source
var ( ErrKeyNotExist = errors.New("redis: key is missing") ErrValueIsNil = errors.New("redis: value is nil") )
Functions ¶
func RedisValueMapToMap ¶
func RedisValueMapToMap[V any](vMap RedisValueMap, filterFn func(*V) bool) (map[string]*V, error)
func RedisValueMapToSlice ¶
func RedisValueMapToSlice[V any](vMap RedisValueMap, filterFn func(*V) bool) ([]*V, error)
将map[string]IRedis转换为一个对象数组 filterFn: 转换时是否执行筛选,如果为nil,则不执行任何筛选
Types ¶
type IRedisHashService ¶
type IRedisHashService interface { HashGet(key string, field string, opts ...RedisValueOption) IRedisValue HashGetAll(key string, opts ...RedisValueOption) (RedisValueMap, error) HashSet(key string, values map[string]interface{}, opts ...RedisValueOption) error }
func NewRedisHashService ¶
func NewRedisHashService(options *RedisOptions) IRedisHashService
type IRedisKeyService ¶
type IRedisKeyService interface { GetRedisClient() *redis.Client //搜索符合pattern的key列表 Keys(keyPattern string, opts ...RedisValueOption) ([]string, error) ExistKey(key string, opts ...RedisValueOption) (bool, error) DeleteKey(key string, opts ...RedisValueOption) error //删除指定前缀的所有key DeleteKeys(pattern string, opts ...RedisValueOption) error //设置key的过期时间 KeyExpire(key string, duration time.Duration, opts ...RedisValueOption) error //获取key的过期时间 KeyTimeToLive(key string, opts ...RedisValueOption) *time.Duration }
对redis中的key进行操作的接口
type IRedisPipelineService ¶
type IRedisPipelineService interface { }
type IRedisService ¶
type IRedisService interface { IRedisKeyService IRedisStringService IRedisHashService }
访问redis
type IRedisStringService ¶
type IRedisStringService interface { //获取key值 StringGet(key string, opts ...RedisValueOption) IRedisValue //获取多个key值 StringMGet(opts []RedisValueOption, keys ...string) (map[string]IRedisValue, error) //设置值 StringSet(key string, value interface{}, opts ...RedisValueOption) error //自增id KeyIncr(key string, opts ...RedisValueOption) (int64, error) KeyIncrBy(key string, value int64, opts ...RedisValueOption) (int64, error) GetIncr(key string, opts ...RedisValueOption) (int64, error) //自减id KeyDecr(key string, opts ...RedisValueOption) (int64, error) KeyDecrBy(key string, decrement int64, opts ...RedisValueOption) (int64, error) GetDecr(key string, opts ...RedisValueOption) (int64, error) }
func NewRedisStringService ¶
func NewRedisStringService(options *RedisOptions) IRedisStringService
type IRedisValue ¶
type IRedisValue interface { //获取值是否存在 Exist() bool Bytes() []byte Err() error //转换为目标值 ToValue(val interface{}) error ValToString() string ValToInt() (int, error) ValToInt32() (int32, error) ValToInt64() (int64, error) ValToBool() (bool, error) ValToTime() (time.Time, error) }
redis值
type MarshalFunc ¶
type RedisHashService ¶
type RedisHashService struct {
*RedisKeyService
}
func (*RedisHashService) HashGet ¶
func (s *RedisHashService) HashGet(key string, field string, opts ...RedisValueOption) IRedisValue
get field from hash
func (*RedisHashService) HashGetAll ¶
func (s *RedisHashService) HashGetAll(key string, opts ...RedisValueOption) (RedisValueMap, error)
get all value from hash
func (*RedisHashService) HashSet ¶
func (s *RedisHashService) HashSet(key string, values map[string]interface{}, opts ...RedisValueOption) error
type RedisKeyService ¶
type RedisKeyService struct {
// contains filtered or unexported fields
}
默认的IRedisKeyService实现
func NewRedisKeyService ¶
func NewRedisKeyService(options *RedisOptions) *RedisKeyService
func (*RedisKeyService) DeleteKey ¶
func (s *RedisKeyService) DeleteKey(key string, opts ...RedisValueOption) error
func (*RedisKeyService) DeleteKeys ¶
func (s *RedisKeyService) DeleteKeys(pattern string, opts ...RedisValueOption) error
删除指定前缀的所有key
func (*RedisKeyService) ExistKey ¶
func (s *RedisKeyService) ExistKey(key string, opts ...RedisValueOption) (bool, error)
func (*RedisKeyService) GetRedisClient ¶
func (s *RedisKeyService) GetRedisClient() *redis.Client
func (*RedisKeyService) KeyExpire ¶
func (s *RedisKeyService) KeyExpire(key string, duration time.Duration, opts ...RedisValueOption) error
设置key的过期时间
func (*RedisKeyService) KeyTimeToLive ¶
func (s *RedisKeyService) KeyTimeToLive(key string, opts ...RedisValueOption) *time.Duration
获取key的过期时间
func (*RedisKeyService) Keys ¶
func (s *RedisKeyService) Keys(keyPattern string, opts ...RedisValueOption) ([]string, error)
搜索符合pattern的key列表
type RedisLock ¶
A RedisLock is a redis lock.
func NewRedisLock ¶
NewRedisLock returns a RedisLock.
func (*RedisLock) RedisAcquire ¶
RedisAcquire Lua script方式加锁
func (*RedisLock) RedisRelease ¶
RedisRelease releases the lock. @ return @ int64: Released number @ 0 - exist key but given a wrong token @ -1 - key is not exist @ -2 - other errors
type RedisOptions ¶
type RedisOptions struct { KeyPrefix string //默认的有效期时间,如果不设,则表示没有有效期 DefaultTTL *time.Duration Unmarshal UnmarshalFunc Marshal MarshalFunc // contains filtered or unexported fields }
模块参数配置
type RedisPipelineService ¶
type RedisPipelineService struct {
// contains filtered or unexported fields
}
默认的IRedisPipelineService实现
func NewRedisPipelineService ¶
func NewRedisPipelineService(options *RedisOptions) *RedisPipelineService
func (*RedisPipelineService) PipelineSetData ¶
func (s *RedisPipelineService) PipelineSetData(list map[string]interface{}, opts ...RedisValueOption) error
type RedisStringService ¶
type RedisStringService struct {
*RedisKeyService
}
func (*RedisStringService) GetDecr ¶
func (s *RedisStringService) GetDecr(key string, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) GetIncr ¶
func (s *RedisStringService) GetIncr(key string, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) KeyDecr ¶
func (s *RedisStringService) KeyDecr(key string, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) KeyDecrBy ¶
func (s *RedisStringService) KeyDecrBy(key string, decrement int64, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) KeyIncr ¶
func (s *RedisStringService) KeyIncr(key string, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) KeyIncrBy ¶
func (s *RedisStringService) KeyIncrBy(key string, value int64, opts ...RedisValueOption) (int64, error)
func (*RedisStringService) StringGet ¶
func (s *RedisStringService) StringGet(key string, opts ...RedisValueOption) IRedisValue
func (*RedisStringService) StringMGet ¶
func (s *RedisStringService) StringMGet(opts []RedisValueOption, keys ...string) (map[string]IRedisValue, error)
获取多个key值
func (*RedisStringService) StringSet ¶
func (s *RedisStringService) StringSet(key string, value interface{}, opts ...RedisValueOption) error
type RedisValueMap ¶
type RedisValueMap map[string]IRedisValue
type RedisValueOption ¶
type RedisValueOption func(*RedisValueOptions)
func WithContext ¶
func WithContext(ctx context.Context) RedisValueOption
func WithExpiredTime ¶
func WithExpiredTime(expiredTime time.Time) RedisValueOption
func WithMarshalFunc ¶
func WithMarshalFunc(marshal MarshalFunc) RedisValueOption
func WithUnmarshalFunc ¶
func WithUnmarshalFunc(unmarshal UnmarshalFunc) RedisValueOption
type RedisValueOptions ¶
type RedisValueOptions struct {
// contains filtered or unexported fields
}
type UnmarshalFunc ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.