dorm

package module
v1.0.60 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrExpr = "expr" // 过期时间
	AttrNx   = "nx"   // 设置Nx
)
View Source
const (
	SerializerJson   = "json"
	SerializerString = "string"
)
View Source
const Version = "1.0.60"

Version 版本

Variables

View Source
var (
	NoConfigDatabaseName   = errors.New("没有配置库名")
	NoConfigCollectionName = errors.New("没有配置集合名")
)
View Source
var (
	// GormNotFound 没有数据
	GormNotFound = gorm.ErrRecordNotFound
)
View Source
var (
	// RedisKeysNotFound keys没有数据
	RedisKeysNotFound = errors.New("ERR wrong number of arguments for 'mget' command")
)

Functions

func Any

func Any(a any) any

Any 复制 any 对象,并返回复制体

func Bool

func Bool(b bool) bool

Bool 复制 bool 对象,并返回复制体

func Float32

func Float32(f float32) float32

Float32 复制 float32 对象,并返回复制体

func Float64

func Float64(f float64) float64

Float64 复制 float64 对象,并返回复制体

func Int

func Int(i int) int

Int 复制 int 对象,并返回复制体

func Int16

func Int16(i int16) int16

Int16 复制 int16 对象,并返回复制体

func Int32

func Int32(i int32) int32

Int32 复制 int64 对象,并返回复制体

func Int64

func Int64(i int64) int64

Int64 复制 int64 对象,并返回复制体

func Int8

func Int8(i int8) int8

Int8 复制 int8 对象,并返回复制体

func String

func String(s string) string

String 复制 string 对象,并返回复制体

func Uint

func Uint(ui uint) uint

Uint 复制 uint 对象,并返回复制体

func Uint16

func Uint16(ui uint16) uint16

Uint16 复制 uint16 对象,并返回复制体

func Uint32

func Uint32(ui uint32) uint32

Uint32 复制 uint32 对象,并返回复制体

func Uint64

func Uint64(ui uint64) uint64

Uint64 复制 uint64 对象,并返回复制体

func Uint8

func Uint8(ui uint8) uint8

Uint8 复制 int8 对象,并返回复制体

Types

type BsonTime

type BsonTime time.Time

BsonTime 时间类型

func NewBsonTimeCurrent

func NewBsonTimeCurrent() BsonTime

NewBsonTimeCurrent 创建当前时间

func NewBsonTimeFromString

func NewBsonTimeFromString(t string) BsonTime

NewBsonTimeFromString 创建某个时间 字符串

func NewBsonTimeFromTime

func NewBsonTimeFromTime(t time.Time) BsonTime

NewBsonTimeFromTime 创建某个时间

func (BsonTime) Format

func (bt BsonTime) Format() string

Format 转时间字符串

func (BsonTime) MarshalBSONValue

func (bt BsonTime) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue 实现bson序列化

func (BsonTime) MarshalJSON

func (bt BsonTime) MarshalJSON() ([]byte, error)

MarshalJSON 实现json序列化

func (BsonTime) Time

func (bt BsonTime) Time() time.Time

Time 转时间

func (BsonTime) TimePro

func (bt BsonTime) TimePro() gotime.Pro

TimePro 转时间操作

func (*BsonTime) UnmarshalBSONValue

func (bt *BsonTime) UnmarshalBSONValue(t bsontype.Type, data []byte) error

UnmarshalBSONValue 实现bson反序列化

func (*BsonTime) UnmarshalJSON

func (bt *BsonTime) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON 实现json反序列化

func (BsonTime) Value

func (bt BsonTime) Value() string

Value 时间类型

type DBGttFunc

type DBGttFunc func() string

type DBGttInterfaceFunc

type DBGttInterfaceFunc func() interface{}

type DBGttJsonFunc

type DBGttJsonFunc func() interface{}

type DBGttStringFunc

type DBGttStringFunc func() string

type GormClient

type GormClient struct {
	// contains filtered or unexported fields
}

GormClient https://gorm.io/zh_CN/docs/index.html

func NewGormMysqlClient

func NewGormMysqlClient(ctx context.Context, config *GormClientConfig) (*GormClient, error)

NewGormMysqlClient 创建GormClient实例 mysql

func NewGormPostgresClient

func NewGormPostgresClient(ctx context.Context, config *GormClientConfig) (*GormClient, error)

NewGormPostgresClient 创建GormClient实例 postgres

func NewGormPostgresqlClient

func NewGormPostgresqlClient(ctx context.Context, config *GormClientConfig) (*GormClient, error)

NewGormPostgresqlClient 创建GormClient实例 postgresql

func (*GormClient) Begin

func (c *GormClient) Begin() *gorm.DB

Begin 开始事务,不需要创建 Session 对象

func (*GormClient) Close

func (c *GormClient) Close() error

Close 关闭

func (*GormClient) Commit

func (c *GormClient) Commit() *gorm.DB

Commit 提交事务

func (*GormClient) GetDb

func (c *GormClient) GetDb() *gorm.DB

GetDb 获取驱动

func (*GormClient) GetSqlDb

func (c *GormClient) GetSqlDb() *sql.DB

GetSqlDb 获取驱动

func (*GormClient) Ping

func (c *GormClient) Ping() error

Ping ping

func (*GormClient) Rollback

func (c *GormClient) Rollback() *gorm.DB

Rollback 回滚事务

func (*GormClient) Stats

func (c *GormClient) Stats() sql.DBStats

Stats 返回数据库统计信息

type GormClientConfig

type GormClientConfig struct {
	Dns                    string // 地址
	LogStatus              bool   // 日志 - 状态
	LogPath                string // 日志 - 路径
	LogSlow                int64  // 日志 - 慢SQL阈值
	LogLevel               string // 日志 - 级别
	ConnSetMaxIdle         int    // 连接 - 设置空闲连接池中连接的最大数量
	ConnSetMaxOpen         int    // 连接 - 设置打开数据库连接的最大数量
	ConnSetConnMaxLifetime int64  // 连接 - 设置了连接可复用的最大时间
}

GormClientConfig 配置

type GormClientFun

type GormClientFun func() *GormClient

GormClientFun *GormClient 驱动

type GormClientTableFun

type GormClientTableFun func() (*GormClient, string)

GormClientTableFun *GormClient 驱动 string 表名

type GormGenClient

type GormGenClient struct {
	// contains filtered or unexported fields
}

GormGenClient https://gorm.io/zh_CN/gen/index.html

func NewGormGenMysqlClient

func NewGormGenMysqlClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error)

NewGormGenMysqlClient 创建GormGenClient实例 mysql

func NewGormGenPostgresClient

func NewGormGenPostgresClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error)

NewGormGenPostgresClient 创建GormGenClient实例 postgres

func NewGormGenPostgresqlClient

func NewGormGenPostgresqlClient(ctx context.Context, config *GormGenClientConfig) (*GormGenClient, error)

NewGormGenPostgresqlClient 创建GormGenClient实例 postgresql

func (*GormGenClient) GetDb

func (c *GormGenClient) GetDb() *gorm.DB

GetDb 获取驱动

func (*GormGenClient) GetGenerator

func (c *GormGenClient) GetGenerator() *gen.Generator

GetGenerator 获取驱动

type GormGenClientConfig

type GormGenClientConfig struct {
	Dns    string     // dns地址
	Db     *gorm.DB   // db驱动
	Config gen.Config // gen配置
}

GormGenClientConfig 配置

type GormGenClientFun

type GormGenClientFun func() *GormGenClient

GormGenClientFun *GormClient 驱动

type GormGenClientTableFun

type GormGenClientTableFun func() (*GormGenClient, string)

GormGenClientTableFun *GormClient 驱动 string 表名

type GttInterfaceFunc

type GttInterfaceFunc func() interface{}

GttInterfaceFunc Interface缓存结构

type GttStringFunc

type GttStringFunc func() string

GttStringFunc String缓存结构

type HashOperation

type HashOperation struct {
	// contains filtered or unexported fields
}

HashOperation Hash类型数据操作

func NewHashOperation

func NewHashOperation(db *redis.Client) *HashOperation

NewHashOperation hash类型数据操作 https://www.tizi365.com/archives/296.html

func (*HashOperation) Get

func (cl *HashOperation) Get(ctx context.Context, key, field string) *redis.StringCmd

Get 根据key和field字段设置,field字段的值

func (*HashOperation) Set

func (cl *HashOperation) Set(ctx context.Context, key string, value interface{}) *redis.IntCmd

Set 根据key和field字段设置,field字段的值

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator(data []interface{}) *Iterator

NewIterator 构造函数

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

HasNext 是否有下一个

func (*Iterator) Next

func (i *Iterator) Next() (Ret interface{})

Next 循环下一个

type JsonGttFunc

type JsonGttFunc func() interface{}

type ListOperation

type ListOperation struct {
	// contains filtered or unexported fields
}

ListOperation 列表(list)类型数据操作

func (*ListOperation) Index

func (cl *ListOperation) Index(key string, index int64) *redis.StringCmd

Index 根据索引坐标,查询key中的数据

func (*ListOperation) Insert

func (cl *ListOperation) Insert(key, op string, pivot, value interface{}) *redis.IntCmd

Insert 在指定位置插入数据

func (*ListOperation) LPop

func (cl *ListOperation) LPop(key string) *redis.StringCmd

LPop 从列表左边删除第一个数据,并返回删除的数据

func (*ListOperation) LPush

func (cl *ListOperation) LPush(key string, value interface{}) *redis.IntCmd

LPush 从列表左边插入数据

func (*ListOperation) LPushX

func (cl *ListOperation) LPushX(key string, value interface{}) *redis.IntCmd

LPushX 跟LPush的区别是,仅当列表存在的时候才插入数据

func (*ListOperation) Len

func (cl *ListOperation) Len(key string) *redis.IntCmd

Len 返回列表的大小

func (*ListOperation) RPop

func (cl *ListOperation) RPop(key string) *redis.StringCmd

RPop 从列表的右边删除第一个数据,并返回删除的数据

func (*ListOperation) RPush

func (cl *ListOperation) RPush(key string, value interface{}) *redis.IntCmd

RPush 从列表右边插入数据

func (*ListOperation) RPushX

func (cl *ListOperation) RPushX(key string, value interface{}) *redis.IntCmd

RPushX 跟RPush的区别是,仅当列表存在的时候才插入数据

func (*ListOperation) Range

func (cl *ListOperation) Range(key string, start, stop int64) *redis.StringSliceCmd

Range 返回列表的一个范围内的数据,也可以返回全部数据

func (*ListOperation) RangeAli

func (cl *ListOperation) RangeAli(key string) *redis.StringSliceCmd

RangeAli 返回key全部数据

func (*ListOperation) Rem

func (cl *ListOperation) Rem(key string, count int64, value interface{}) *redis.IntCmd

Rem 删除key中的数据

type MongoClient

type MongoClient struct {
	// contains filtered or unexported fields
}

MongoClient 实例

func NewMongoClient

func NewMongoClient(ctx context.Context, config *MongoClientConfig) (*MongoClient, error)

NewMongoClient 创建实例

func (*MongoClient) Begin

func (c *MongoClient) Begin() *MongoSessionOptions

Begin 开始事务,会同时创建开始会话需要在退出时关闭会话

func (*MongoClient) Close

func (c *MongoClient) Close(ctx context.Context) error

Close 关闭

func (*MongoClient) Database

func (c *MongoClient) Database(name string, opts ...*options.DatabaseOptions) *MongoDatabaseOptions

Database 选择数据库

func (*MongoClient) GetDb

func (c *MongoClient) GetDb() *mongo.Client

GetDb 获取驱动

func (*MongoClient) Model

func (c *MongoClient) Model(value interface{}) *MongoCollectionOptions

Model 传入模型自动获取库名和表名 https://studygolang.com/articles/896 DatabaseName 库名 CollectionName 集合名

type MongoClientCollectionFun

type MongoClientCollectionFun func() (*MongoClient, string, string)

MongoClientCollectionFun *MongoClient 驱动 string 库名 string 集合

type MongoClientConfig

type MongoClientConfig struct {
	Dns          string // 地址
	Opts         *options.ClientOptions
	DatabaseName string // 库名
}

MongoClientConfig 实例配置

type MongoClientFun

type MongoClientFun func() (*MongoClient, string)

MongoClientFun *MongoClient 驱动 string 库名

type MongoCollectionOptions

type MongoCollectionOptions struct {
	// contains filtered or unexported fields
}

func (*MongoCollectionOptions) Aggregate

func (cc *MongoCollectionOptions) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)

Aggregate 统计分析

func (*MongoCollectionOptions) CountDocuments

func (cc *MongoCollectionOptions) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)

CountDocuments 计数文档

func (*MongoCollectionOptions) CreateManyIndexes

func (cc *MongoCollectionOptions) CreateManyIndexes(ctx context.Context, models []mongo.IndexModel) ([]string, error)

CreateManyIndexes 创建多个索引

func (*MongoCollectionOptions) CreateOneIndexes

func (cc *MongoCollectionOptions) CreateOneIndexes(ctx context.Context, key string, value string) (string, error)

CreateOneIndexes 创建一个索引

func (*MongoCollectionOptions) CreateOneUniqueIndexes

func (cc *MongoCollectionOptions) CreateOneUniqueIndexes(ctx context.Context, key string, value string) (string, error)

CreateOneUniqueIndexes 创建一个唯一索引

func (*MongoCollectionOptions) CreateOneUniqueIndexesOpts

func (cc *MongoCollectionOptions) CreateOneUniqueIndexesOpts(ctx context.Context, key string, value string, opts *options.IndexOptions) (string, error)

CreateOneUniqueIndexesOpts 创建一个索引

func (*MongoCollectionOptions) DeleteMany

func (cc *MongoCollectionOptions) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteMany 删除多个文档

func (*MongoCollectionOptions) DeleteOne

func (cc *MongoCollectionOptions) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOne 删除一个文档

func (*MongoCollectionOptions) Distinct

func (cc *MongoCollectionOptions) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error)

func (*MongoCollectionOptions) Drop

func (*MongoCollectionOptions) EstimatedDocumentCount

func (cc *MongoCollectionOptions) EstimatedDocumentCount(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error)

EstimatedDocumentCount 估计文档计数

func (*MongoCollectionOptions) Find

func (cc *MongoCollectionOptions) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)

Find 查询多个文档

func (*MongoCollectionOptions) FindOne

func (cc *MongoCollectionOptions) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult

FindOne 查询一个文档

func (*MongoCollectionOptions) FindOneAndDelete

func (cc *MongoCollectionOptions) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult

func (*MongoCollectionOptions) FindOneAndReplace

func (cc *MongoCollectionOptions) FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult

func (*MongoCollectionOptions) FindOneAndUpdate

func (cc *MongoCollectionOptions) FindOneAndUpdate(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult

func (*MongoCollectionOptions) Indexes

func (*MongoCollectionOptions) InsertMany

func (cc *MongoCollectionOptions) InsertMany(ctx context.Context, document []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertMany 插入多个文档

func (*MongoCollectionOptions) InsertOne

func (cc *MongoCollectionOptions) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertOne 插入一个文档

func (*MongoCollectionOptions) ReplaceOne

func (cc *MongoCollectionOptions) ReplaceOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)

ReplaceOne 替换一个文档

func (*MongoCollectionOptions) UpdateByID

func (cc *MongoCollectionOptions) UpdateByID(ctx context.Context, id interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateByID 按ID更新

func (*MongoCollectionOptions) UpdateMany

func (cc *MongoCollectionOptions) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany 更新多个文档

func (*MongoCollectionOptions) UpdateOne

func (cc *MongoCollectionOptions) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne 更新一个文档

func (*MongoCollectionOptions) Watch

func (cc *MongoCollectionOptions) Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

type MongoDatabaseOptions

type MongoDatabaseOptions struct {
	// contains filtered or unexported fields
}

func (*MongoDatabaseOptions) Collection

Collection 选择集合

func (*MongoDatabaseOptions) CreateCollection

func (cd *MongoDatabaseOptions) CreateCollection(ctx context.Context, name string, opts ...*options.CreateCollectionOptions) error

CreateCollection 创建集合

func (*MongoDatabaseOptions) CreateTimeSeriesCollection

func (cd *MongoDatabaseOptions) CreateTimeSeriesCollection(ctx context.Context, name string, timeField string) error

CreateTimeSeriesCollection 创建时间序列集合

type MongoSessionCollectionOptions

type MongoSessionCollectionOptions struct {
	// contains filtered or unexported fields
}

func (*MongoSessionCollectionOptions) Aggregate

func (csc *MongoSessionCollectionOptions) Aggregate(pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)

Aggregate 统计分析

func (*MongoSessionCollectionOptions) CountDocuments

func (csc *MongoSessionCollectionOptions) CountDocuments(filter interface{}, opts ...*options.CountOptions) (int64, error)

CountDocuments 计数文档

func (*MongoSessionCollectionOptions) DeleteMany

func (csc *MongoSessionCollectionOptions) DeleteMany(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteMany 删除多个文档

func (*MongoSessionCollectionOptions) DeleteOne

func (csc *MongoSessionCollectionOptions) DeleteOne(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOne 删除一个文档

func (*MongoSessionCollectionOptions) Distinct

func (csc *MongoSessionCollectionOptions) Distinct(fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error)

func (*MongoSessionCollectionOptions) Drop

func (*MongoSessionCollectionOptions) EstimatedDocumentCount

func (csc *MongoSessionCollectionOptions) EstimatedDocumentCount(opts ...*options.EstimatedDocumentCountOptions) (int64, error)

EstimatedDocumentCount 估计文档计数

func (*MongoSessionCollectionOptions) Find

func (csc *MongoSessionCollectionOptions) Find(filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)

Find 查询多个文档

func (*MongoSessionCollectionOptions) FindOne

func (csc *MongoSessionCollectionOptions) FindOne(filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult

FindOne 查询一个文档

func (*MongoSessionCollectionOptions) FindOneAndDelete

func (csc *MongoSessionCollectionOptions) FindOneAndDelete(filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult

func (*MongoSessionCollectionOptions) FindOneAndReplace

func (csc *MongoSessionCollectionOptions) FindOneAndReplace(filter interface{}, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult

func (*MongoSessionCollectionOptions) FindOneAndUpdate

func (csc *MongoSessionCollectionOptions) FindOneAndUpdate(filter interface{}, replacement interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult

func (*MongoSessionCollectionOptions) Indexes

func (*MongoSessionCollectionOptions) InsertMany

func (csc *MongoSessionCollectionOptions) InsertMany(document []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertMany 插入多个文档

func (*MongoSessionCollectionOptions) InsertOne

func (csc *MongoSessionCollectionOptions) InsertOne(document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertOne 插入一个文档

func (*MongoSessionCollectionOptions) ReplaceOne

func (csc *MongoSessionCollectionOptions) ReplaceOne(filter interface{}, update interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)

ReplaceOne 替换一个文档

func (*MongoSessionCollectionOptions) UpdateByID

func (csc *MongoSessionCollectionOptions) UpdateByID(id interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateByID 按ID更新

func (*MongoSessionCollectionOptions) UpdateMany

func (csc *MongoSessionCollectionOptions) UpdateMany(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany 更新多个文档

func (*MongoSessionCollectionOptions) UpdateOne

func (csc *MongoSessionCollectionOptions) UpdateOne(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne 更新一个文档

func (*MongoSessionCollectionOptions) Watch

func (csc *MongoSessionCollectionOptions) Watch(pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

type MongoSessionDatabaseOptions

type MongoSessionDatabaseOptions struct {
	// contains filtered or unexported fields
}

func (*MongoSessionDatabaseOptions) Collection

Collection 选择集合

type MongoSessionOptions

type MongoSessionOptions struct {
	// contains filtered or unexported fields
}

func (*MongoSessionOptions) Commit

func (cs *MongoSessionOptions) Commit()

Commit 提交事务

func (*MongoSessionOptions) Database

Database 选择数据库

func (*MongoSessionOptions) GetDb

func (cs *MongoSessionOptions) GetDb() *mongo.Client

GetDb 获取驱动

func (*MongoSessionOptions) GetSession

func (cs *MongoSessionOptions) GetSession() mongo.Session

GetSession 获取会话

func (*MongoSessionOptions) GetSessionContext

func (cs *MongoSessionOptions) GetSessionContext() mongo.SessionContext

GetSessionContext 获取会话上下文

func (*MongoSessionOptions) Model

func (cs *MongoSessionOptions) Model(value interface{}) *MongoSessionCollectionOptions

Model 传入模型自动获取库名和表名 https://studygolang.com/articles/896 DatabaseName 库名 CollectionName 集合名

func (*MongoSessionOptions) Rollback

func (cs *MongoSessionOptions) Rollback()

Rollback 回滚事务

type OperationAttr

type OperationAttr struct {
	Name  string
	Value interface{}
}

func WithExpire

func WithExpire(t time.Duration) *OperationAttr

WithExpire 过期时间

func WithNX

func WithNX() *OperationAttr

type OperationAttrs

type OperationAttrs []*OperationAttr

func (OperationAttrs) Find

func (a OperationAttrs) Find(name string) interface{}

type RedisCacheConfig

type RedisCacheConfig struct {
	Expiration time.Duration // 过期时间
}

RedisCacheConfig 配置

type RedisClient

type RedisClient struct {
	// contains filtered or unexported fields
}

RedisClient https://redis.uptrace.dev/

func NewRedisClient

func NewRedisClient(config *RedisClientConfig) (*RedisClient, error)

NewRedisClient 创建实例

func NewRedisClientURL

func NewRedisClientURL(redisURL string) (*RedisClient, error)

NewRedisClientURL 创建实例

func (*RedisClient) AddKeyToSet

func (r *RedisClient) AddKeyToSet(ctx context.Context, setKey string, value interface{}) error

AddKeyToSet 将值添加到集合

func (*RedisClient) Decr

func (r *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd

Decr 针对一个key的数值进行递减操作

func (*RedisClient) DecrBy

func (r *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd

DecrBy 针对一个key的数值进行递减操作,指定每次递减多少

func (*RedisClient) Del

func (r *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del 删除key操作,支持批量删除

func (*RedisClient) DeleteKeysWithPrefix

func (r *RedisClient) DeleteKeysWithPrefix(ctx context.Context, prefix string) error

DeleteKeysWithPrefix 根据前缀删除key

func (*RedisClient) DeleteScanWithPrefix

func (r *RedisClient) DeleteScanWithPrefix(ctx context.Context, prefix string) error

DeleteScanWithPrefix 根据前缀删除key

func (*RedisClient) DoesKeyExistInSet

func (r *RedisClient) DoesKeyExistInSet(ctx context.Context, setKey string, targetKey interface{}) (bool, error)

DoesKeyExistInSet 检查值是否存在于集合中

func (*RedisClient) Get

func (r *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd

Get 查询key的值

func (*RedisClient) GetAllKeysInSet

func (r *RedisClient) GetAllKeysInSet(ctx context.Context, setKey string) ([]string, error)

GetAllKeysInSet 获取集合的所有元素

func (*RedisClient) GetDb

func (r *RedisClient) GetDb() *redis.Client

GetDb 获取驱动

func (*RedisClient) GetSet

func (r *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd

GetSet 设置一个key的值,并返回这个key的旧值

func (*RedisClient) Incr

func (r *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd

Incr 针对一个key的数值进行递增操作

func (*RedisClient) IncrBy

func (r *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd

IncrBy 针对一个key的数值进行递增操作,指定每次递增多少

func (*RedisClient) Keys

func (r *RedisClient) Keys(ctx context.Context, prefix string) []string

Keys 按前缀获取所有key名

func (*RedisClient) KeysValue

func (r *RedisClient) KeysValue(ctx context.Context, prefix string) *redis.SliceCmd

KeysValue 按前缀获取所有key值

func (*RedisClient) MGet

func (r *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd

MGet 批量查询key的值

func (*RedisClient) MSet

func (r *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd

MSet 批量设置key的值 MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (*RedisClient) NewCache

func (r *RedisClient) NewCache(config *RedisCacheConfig) *RedisClientCache

NewCache 实例化

func (*RedisClient) NewCacheDefaultExpiration

func (r *RedisClient) NewCacheDefaultExpiration() *RedisClientCache

NewCacheDefaultExpiration 实例化

func (*RedisClient) NewListOperation

func (r *RedisClient) NewListOperation() *ListOperation

NewListOperation 列表(list)类型数据操作 https://www.tizi365.com/archives/299.html

func (*RedisClient) NewLock

func (r *RedisClient) NewLock() *RedisClientLock

NewLock 实例化锁

func (*RedisClient) NewSimpleCache

func (r *RedisClient) NewSimpleCache(operation *StringOperation, expire time.Duration, serializer string) *SimpleCache

NewSimpleCache 构造函数

func (*RedisClient) NewSimpleInterfaceCache

func (r *RedisClient) NewSimpleInterfaceCache(operation *SimpleOperation, expire time.Duration) *SimpleInterfaceCache

NewSimpleInterfaceCache 构造函数

func (*RedisClient) NewSimpleJsonCache

func (r *RedisClient) NewSimpleJsonCache(operation *StringOperation, expire time.Duration) *SimpleJsonCache

NewSimpleJsonCache 构造函数

func (*RedisClient) NewSimpleOperation

func (r *RedisClient) NewSimpleOperation() *SimpleOperation

func (*RedisClient) NewSimpleStringCache

func (r *RedisClient) NewSimpleStringCache(operation *StringOperation, expire time.Duration) *SimpleStringCache

NewSimpleStringCache 构造函数

func (*RedisClient) NewStringOperation

func (r *RedisClient) NewStringOperation() *StringOperation

func (*RedisClient) PSubscribe

func (r *RedisClient) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub

PSubscribe 订阅channel支持通配符匹配

func (*RedisClient) PubSubChannels

func (r *RedisClient) PubSubChannels(ctx context.Context, pattern string) *redis.StringSliceCmd

PubSubChannels 查询活跃的channel

func (*RedisClient) PubSubNumSub

func (r *RedisClient) PubSubNumSub(ctx context.Context, channels ...string) *redis.MapStringIntCmd

PubSubNumSub 查询指定的channel有多少个订阅者

func (*RedisClient) Publish

func (r *RedisClient) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd

Publish 将信息发送到指定的channel

func (*RedisClient) RemoveKeyFromSet

func (r *RedisClient) RemoveKeyFromSet(ctx context.Context, setKey string, targetKey interface{}) error

RemoveKeyFromSet 从集合中删除指定的元素

func (*RedisClient) Set

func (r *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Set 设置一个key的值

func (*RedisClient) SetNX

func (r *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd

SetNX 如果key不存在,则设置这个key的值

func (*RedisClient) Subscribe

func (r *RedisClient) Subscribe(ctx context.Context, channels ...string) *redis.PubSub

Subscribe 订阅channel

type RedisClientCache

type RedisClientCache struct {
	GetterString    GttStringFunc    // 不存在的操作
	GetterInterface GttInterfaceFunc // 不存在的操作
	// contains filtered or unexported fields
}

RedisClientCache https://github.com/go-redis/redis

func (*RedisClientCache) GetInterface

func (rc *RedisClientCache) GetInterface(ctx context.Context, key string, result interface{})

GetInterface 缓存操作

func (*RedisClientCache) GetInterfaceKey

func (rc *RedisClientCache) GetInterfaceKey(ctx context.Context, key string, result interface{}) error

GetInterfaceKey 获取key值

func (*RedisClientCache) GetString

func (rc *RedisClientCache) GetString(ctx context.Context, key string) (ret string)

GetString 缓存操作

func (*RedisClientCache) SetInterfaceKey

func (rc *RedisClientCache) SetInterfaceKey(ctx context.Context, key string, value interface{}) (string, error)

SetInterfaceKey 设置key值

type RedisClientConfig

type RedisClientConfig struct {
	Addr        string        // 地址
	Password    string        // 密码
	DB          int           // 数据库
	PoolSize    int           // 连接池大小
	ReadTimeout time.Duration // 读取超时
}

type RedisClientFun

type RedisClientFun func() *RedisClient

RedisClientFun *RedisClient 驱动

type RedisClientLock

type RedisClientLock struct {
	// contains filtered or unexported fields
}

RedisClientLock https://github.com/go-redis/redis

func (*RedisClientLock) Lock

func (rl *RedisClientLock) Lock(ctx context.Context, key string, val string, ttl time.Duration) (resp string, err error)

Lock 上锁 key 锁名 val 锁内容 ttl 锁过期时间

func (*RedisClientLock) LockForever

func (rl *RedisClientLock) LockForever(ctx context.Context, key string, val string) (resp string, err error)

LockForever 永远上锁 key 锁名 val 锁内容

func (*RedisClientLock) Unlock

func (rl *RedisClientLock) Unlock(ctx context.Context, key string) error

Unlock 解锁 key 锁名

type SimpleCache

type SimpleCache struct {
	Operation  *StringOperation // 操作类
	Expire     time.Duration    // 过去时间
	DBGetter   DBGttFunc        // 缓存不存在的操作 DB
	JsonGetter JsonGttFunc      // 缓存不存在的操作 JSON
	Serializer string           // 序列化方式
}

SimpleCache 缓存

func (*SimpleCache) GetCache

func (c *SimpleCache) GetCache(ctx context.Context, key string) (ret interface{})

GetCache 获取缓存

func (*SimpleCache) SetCache

func (c *SimpleCache) SetCache(ctx context.Context, key string, value interface{})

SetCache 设置缓存

type SimpleInterfaceCache

type SimpleInterfaceCache struct {
	Operation *SimpleOperation   // 操作类
	Expire    time.Duration      // 过期时间
	DBGetter  DBGttInterfaceFunc // 缓存不存在的操作 DB
}

SimpleInterfaceCache 缓存

func (*SimpleInterfaceCache) GetCache

func (c *SimpleInterfaceCache) GetCache(ctx context.Context, key string) (ret interface{})

GetCache 获取缓存

func (*SimpleInterfaceCache) SetCache

func (c *SimpleInterfaceCache) SetCache(ctx context.Context, key string, value interface{})

SetCache 设置缓存

type SimpleJsonCache

type SimpleJsonCache struct {
	Operation *StringOperation // 操作类
	Expire    time.Duration    // 过期时间
	DBGetter  DBGttJsonFunc    // 缓存不存在的操作 DB
}

SimpleJsonCache 缓存

func (*SimpleJsonCache) GetCache

func (c *SimpleJsonCache) GetCache(ctx context.Context, key string) (ret interface{})

GetCache 获取缓存

func (*SimpleJsonCache) SetCache

func (c *SimpleJsonCache) SetCache(ctx context.Context, key string, value interface{})

SetCache 设置缓存

type SimpleOperation

type SimpleOperation struct {
	// contains filtered or unexported fields
}

func (*SimpleOperation) Del

func (o *SimpleOperation) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del 删除key操作,支持批量删除

func (*SimpleOperation) Get

Get 获取单个

func (*SimpleOperation) Set

func (o *SimpleOperation) Set(ctx context.Context, key string, value interface{}, attrs ...*OperationAttr) *SimpleResult

Set 设置

type SimpleResult

type SimpleResult struct {
	Result interface{}
	Err    error
}

func NewSimpleResult

func NewSimpleResult(result interface{}, err error) *SimpleResult

NewSimpleResult 构造函数

func (*SimpleResult) Unwrap

func (r *SimpleResult) Unwrap() interface{}

Unwrap 空值情况下返回错误

func (*SimpleResult) UnwrapOr

func (r *SimpleResult) UnwrapOr(defaults interface{}) interface{}

UnwrapOr 空值情况下设置返回默认值

func (*SimpleResult) UnwrapOrElse

func (r *SimpleResult) UnwrapOrElse(f func() interface{}) interface{}

UnwrapOrElse 空值情况下设置返回其他

type SimpleStringCache

type SimpleStringCache struct {
	Operation *StringOperation // 操作类
	Expire    time.Duration    // 过期时间
	DBGetter  DBGttStringFunc  // 缓存不存在的操作 DB
}

SimpleStringCache 缓存

func (*SimpleStringCache) GetCache

func (c *SimpleStringCache) GetCache(ctx context.Context, key string) (ret string)

GetCache 获取缓存

func (*SimpleStringCache) SetCache

func (c *SimpleStringCache) SetCache(ctx context.Context, key string, value string)

SetCache 设置缓存

type SliceResult

type SliceResult struct {
	Result []interface{}
	Err    error
}

func NewSliceResult

func NewSliceResult(result []interface{}, err error) *SliceResult

NewSliceResult 构造函数

func (*SliceResult) Iter

func (r *SliceResult) Iter() *Iterator

func (*SliceResult) Unwrap

func (r *SliceResult) Unwrap() []interface{}

Unwrap 空值情况下返回错误

func (*SliceResult) UnwrapOr

func (r *SliceResult) UnwrapOr(defaults []interface{}) []interface{}

UnwrapOr 空值情况下设置返回默认值

type StringOperation

type StringOperation struct {
	// contains filtered or unexported fields
}

func (*StringOperation) Del

func (o *StringOperation) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del 删除key操作,支持批量删除

func (*StringOperation) Get

Get 获取单个

func (*StringOperation) MGet

func (o *StringOperation) MGet(ctx context.Context, keys ...string) *SliceResult

MGet 获取多个

func (*StringOperation) Set

func (o *StringOperation) Set(ctx context.Context, key string, value interface{}, attrs ...*OperationAttr) *StringResult

Set 设置

type StringResult

type StringResult struct {
	Result string // 结果
	Err    error  // 错误
}

func NewStringResult

func NewStringResult(result string, err error) *StringResult

NewStringResult 构造函数

func (*StringResult) Unwrap

func (r *StringResult) Unwrap() string

Unwrap 空值情况下返回错误

func (*StringResult) UnwrapOr

func (r *StringResult) UnwrapOr(defaults string) string

UnwrapOr 空值情况下设置返回默认值

func (*StringResult) UnwrapOrElse

func (r *StringResult) UnwrapOrElse(f func() string) string

UnwrapOrElse 空值情况下设置返回其他

Jump to

Keyboard shortcuts

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