xsession

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: GPL-2.0, GPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

提供了数据模型(xorm)、内存沙箱(Cache > Redis > DB)、日志输出(GLog...)等功能.

Index

Constants

View Source
const (
	PIPE_CHAN_MAX = 100000 // 推送队列最大长度
)

Variables

This section is empty.

Functions

func GClear

func GClear(model xorm.ITable, _cond ...*xorm.Condition)

清除数据(会话内同步,远端异步)

model: 数据模型
_cond: 条件对象

func GCount added in v1.2.2

func GCount(model xorm.ITable, _cond ...*xorm.Condition) int

数据数量

priority: 会话内存 > 全局缓存(LCache == true) > Redis(LRedis == true) > DB(LDB == true)
notice: 远端列举(LCache == false、该会话首次列举、条件查找),会触发数据同步锁,可能会严重影响效率(等待GDelete操作完成),可预加载(GList)该模型优化之
model: 数据模型
_cond: 条件对象

func GDelete

func GDelete(model xorm.ITable)

删除数据(会话内同步,远端异步)

notice: 该操作会维护数据同步锁,条件删除请使用GClear
model: 数据模型

func GDump

func GDump(reset bool) string

Dump内存

reset: 是否清除

func GFinish

func GFinish(id int64)

完成会话(写入/更新/删除内存,性能分析等)

id: 会话ID

func GID

func GID() int

获取当前线程的ID

func GIncrease

func GIncrease(model xorm.ITable, columnAndDelta ...interface{}) int

获取DB指定Column(列)的最大值,并且自增(指定delta值或+1),若未指定Column则自增主键

model: 数据模型
columnAndDelta(1): column/delta(column需为int类型)
columnAndDelta(2): column&delta(column需为int类型)

func GList

func GList(model xorm.ITable, _cond ...*xorm.Condition) interface{}

列举数据

priority: 会话内存 > 全局缓存(LCache == true) > Redis(LRedis == true) > DB(LDB == true)
notice: 远端列举(LCache == false、该会话首次列举、条件查找),会触发数据同步锁,可能会严重影响效率(等待GDelete操作完成),可预加载(GList)该模型优化之
model: 数据模型
_cond: 条件对象

func GLogAlert

func GLogAlert(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogCritical

func GLogCritical(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogDebug

func GLogDebug(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogEmergency

func GLogEmergency(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogError

func GLogError(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogInfo

func GLogInfo(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogNotice

func GLogNotice(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GLogWarn

func GLogWarn(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func GMaxIndex

func GMaxIndex(model xorm.ITable, column ...string) int

获取DB指定Column(列)的最大值,若未指定Column则获取主键的最大值

notice: 异步写入可能会导致该值不同步
column: 列名(column需为int类型)

func GMinIndex

func GMinIndex(model xorm.ITable, column ...string) int

获取DB指定Column(列)的最小值,若未指定Column则获取主键的最小值

notice: 异步写入可能会导致该值不同步
column: 列名(column需为int类型)

func GRead

func GRead(model xorm.ITable, _cond ...*xorm.Condition) xorm.ITable

读取数据

priority: 会话内存 > 全局缓存(LCache == true) > Redis(LRedis == true) > DB(LDB == true)
notice: 远端读取(LCache == false、该会话首次读取、条件查找),会触发数据同步锁,可能会严重影响效率(等待GDelete操作完成),可预加载(GList)该模型优化之
model: 数据模型
_cond: 条件对象

func GStart

func GStart(tag interface{}, log int, rw bool) int64

开始会话

tag: 会话标签
log: 日志层级(参考xlog的LogLevel)
rw: 是否读写
return: 返回会话id,使用该id结束会话

func GWrite

func GWrite(model xorm.ITable)

写入数据(会话内同步,远端异步)

model: 数据模型

func MGMax

func MGMax(model xorm.ITable) *sync.Map

获取全局的最大表ID

model: 数据模型

func MGMem

func MGMem(prefix string, model xorm.ITable) *sync.Map

获取全局内存map

prefix: 前缀
model: 数据模型

func MPCount

func MPCount() int64

Pipe队列等待个数

func MPipe

func MPipe() chan *PipeRecord

获取会话的pipe

func MSMem

func MSMem(prefix string, model xorm.ITable) *sync.Map

获取会话内存map

prefix: 前缀
model: 数据模型

Types

type DeferFun

type DeferFun func()

Defer函数类型

type DeleteRecord

type DeleteRecord struct {
	Chan  chan bool // 通道
	Count int32     // 数量
}

删除对象记录

type GlobalObject

type GlobalObject struct {
	Ptr     xorm.ITable // 原始对象
	SDelete bool        // 删除标识
}

全局对象维护

type PipeObject

type PipeObject struct {
	Raw     xorm.ITable     // 原始对象
	SWrite  bool            // 写入标识
	SDelete bool            // 删除标识
	SClear  bool            // 清除标识
	SDB     bool            // 推送至DB
	SRedis  bool            // 推送至Redis
	Cond    *xorm.Condition // 条件对象
}

管道对象维护

type PipeRecord

type PipeRecord struct {
	ID       int64           // 批次ID
	Tag      interface{}     // 批次标签
	Time     int             // 开始时间
	Objects  []*PipeObject   // 管道对象列表
	Profiler *ProfilerRecord // 性能分析器
}

管道推送批次

type ProfilerRecord

type ProfilerRecord struct {
	Tag  interface{} // 会话标签
	Time int         // 开始时间
	RW   bool        // 是否读写
	Log  int         // 日志层级
	TID  int64       // 线程ID
	SID  int64       // 会话ID

}

性能分析器

func MProfiler

func MProfiler(id int64) *ProfilerRecord

获取会话的profiler

id: 会话ID

func (*ProfilerRecord) GLogAlert

func (this *ProfilerRecord) GLogAlert(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogCritical

func (this *ProfilerRecord) GLogCritical(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogDebug

func (this *ProfilerRecord) GLogDebug(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogEmergency

func (this *ProfilerRecord) GLogEmergency(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogError

func (this *ProfilerRecord) GLogError(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogInfo

func (this *ProfilerRecord) GLogInfo(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogNotice

func (this *ProfilerRecord) GLogNotice(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) GLogWarn

func (this *ProfilerRecord) GLogWarn(f interface{}, v ...interface{})

输出会话日志

priority: Debug(7) > Info(6) > Notice(5) > Warn(4) > Error(3) > Critical(2) > Alert(1) > Emergency(0)

func (*ProfilerRecord) LogPrefix

func (this *ProfilerRecord) LogPrefix() string

日志前缀

func (*ProfilerRecord) Reset

func (this *ProfilerRecord) Reset()

重置对象

type SessionObject

type SessionObject struct {
	Raw     xorm.ITable     // 原始对象
	Ptr     xorm.ITable     // 工作对象
	SWrite  bool            // 写入标识
	SDelete bool            // 删除标识
	SClear  bool            // 清除标识
	Cond    *xorm.Condition // 条件对象
}

map[string]map[string]*GlobalObject map[string]bool map[string]map[string]int map[int]map[string]map[string]*SessionObject map[int]map[string]bool map[string]*DeleteRecord map[int64]int64 map[int64]*ProfilerRecord map[int64]*PipeRecord 会话自增ID 管道推送计数 会话对象维护

Jump to

Keyboard shortcuts

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