Documentation ¶
Index ¶
- Constants
- Variables
- func Init()
- func LeveldbBuildKey(key []byte) ([]byte, utils.ERROR)
- func LeveldbParseKey(key []byte) (uint16, []byte, utils.ERROR)
- func RegisterDbKey(id []byte) bool
- type DBItem
- type IndexLock
- type KVPair
- type LevelDB
- func (this *LevelDB) Close()
- func (this *LevelDB) Commit() error
- func (this *LevelDB) Discard()
- func (this *LevelDB) Find(key LeveldbKey) (*DBItem, error)
- func (this *LevelDB) FindListAll(dbkey LeveldbKey) ([]DBItem, error)
- func (this *LevelDB) FindListByIndex(dbkey LeveldbKey, index []byte) (*DBItem, utils.ERROR)
- func (this *LevelDB) FindListRange(dbkey LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
- func (this *LevelDB) FindListTotal(dbkey LeveldbKey) (uint64, []byte, []byte, utils.ERROR)
- func (this *LevelDB) FindMap(dbkey, key LeveldbKey) ([]byte, error)
- func (this *LevelDB) FindMapAllToList(dbkey LeveldbKey) ([]DBItem, error)
- func (this *LevelDB) FindMapByKeys(dbkey LeveldbKey, keys ...LeveldbKey) ([]DBItem, error)
- func (this *LevelDB) FindMapInListAll(dbkey LeveldbKey) ([]DBItem, utils.ERROR)
- func (this *LevelDB) FindMapInListAllByKey(dbkey, key LeveldbKey) ([]DBItem, error)
- func (this *LevelDB) FindMapInListByIndex(dbkey, key LeveldbKey, index []byte) (*DBItem, utils.ERROR)
- func (this *LevelDB) FindMapInListRangeByKeyIn(dbkey, key LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
- func (this *LevelDB) FindMapInListRangeByKeyOut(dbkey LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
- func (this *LevelDB) FindMapInListTotal(dbkey, key LeveldbKey) (uint64, []byte, []byte, utils.ERROR)
- func (this *LevelDB) FindMapInMapByKeyIn(dbkey, keyOut, keyIn LeveldbKey) (*[]byte, error)
- func (this *LevelDB) FindMapInMapByKeyOut(dbkey, keyOut LeveldbKey) ([]DBItem, utils.ERROR)
- func (this *LevelDB) FindMore(keys ...LeveldbKey) ([]DBItem, error)
- func (this *LevelDB) GetDB() *leveldb.DB
- func (this *LevelDB) GetPath() string
- func (this *LevelDB) Has(key LeveldbKey) (bool, error)
- func (this *LevelDB) InitDB() (err error)
- func (this *LevelDB) OpenTransaction() error
- func (this *LevelDB) PrintAll() ([][]byte, error)
- func (this *LevelDB) Remove(key LeveldbKey) error
- func (this *LevelDB) RemoveListAll(dbkey LeveldbKey, batch *leveldb.Batch) error
- func (this *LevelDB) RemoveListByIndex(dbkey LeveldbKey, index []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) RemoveListInterval(dbkey LeveldbKey, num uint64, interval time.Duration) error
- func (this *LevelDB) RemoveListMore(isTransaction bool, dbkey LeveldbKey, index ...[]byte) utils.ERROR
- func (this *LevelDB) RemoveMapByDbKey(dbkey LeveldbKey, num uint64, interval time.Duration) error
- func (this *LevelDB) RemoveMapByKey(dbkey, key LeveldbKey, batch *leveldb.Batch) error
- func (this *LevelDB) RemoveMapByKey_Transaction(dbkey, key LeveldbKey) error
- func (this *LevelDB) RemoveMapInListAll(dbkey, key LeveldbKey, batch *leveldb.Batch) error
- func (this *LevelDB) RemoveMapInListByIndex(dbkey, key LeveldbKey, index []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) RemoveMapInListByKeyInterval(dbkey, key LeveldbKey, num uint64, interval time.Duration) error
- func (this *LevelDB) RemoveMapInListMore(isTransaction bool, dbkey, key LeveldbKey, index ...[]byte) utils.ERROR
- func (this *LevelDB) RemoveMapInMapByKeyIn(dbkey, keyOut, keyIn LeveldbKey, batch *leveldb.Batch) error
- func (this *LevelDB) RemoveMapInMapByKeyIn_Transaction(dbkey, keyOut, keyIn LeveldbKey) error
- func (this *LevelDB) RemoveMapInMapByKeyOut(dbkey, keyOut LeveldbKey, batch *leveldb.Batch) error
- func (this *LevelDB) RemoveMapInMapByKeyOutInterval(dbkey, keyOut LeveldbKey, num uint64, interval time.Duration) error
- func (this *LevelDB) RemoveMore(kvps ...KVPair) error
- func (this *LevelDB) RemoveMore_Transaction(kvps ...KVPair) error
- func (this *LevelDB) Remove_Transaction(key LeveldbKey) error
- func (this *LevelDB) Save(key LeveldbKey, bs *[]byte) utils.ERROR
- func (this *LevelDB) SaveBatch(batch *leveldb.Batch) error
- func (this *LevelDB) SaveList(dbkey LeveldbKey, value []byte, batch *leveldb.Batch) ([]byte, utils.ERROR)
- func (this *LevelDB) SaveListMore(dbkey LeveldbKey, value [][]byte, batch *leveldb.Batch) ([][]byte, utils.ERROR)
- func (this *LevelDB) SaveMap(dbkey, key LeveldbKey, value []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) SaveMapInList(dbkey, key LeveldbKey, value []byte, batch *leveldb.Batch) ([]byte, utils.ERROR)
- func (this *LevelDB) SaveMapInListMore(dbkey, key LeveldbKey, value [][]byte, batch *leveldb.Batch) ([][]byte, utils.ERROR)
- func (this *LevelDB) SaveMapInMap(dbkey, keyOut, keyIn LeveldbKey, value []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) SaveMapInMap_Transaction(dbkey, keyOut, keyIn LeveldbKey, value []byte) utils.ERROR
- func (this *LevelDB) SaveMap_Transaction(dbkey, key LeveldbKey, value []byte) utils.ERROR
- func (this *LevelDB) SaveMore(kvps ...KVPair) error
- func (this *LevelDB) SaveMore_TransacTion(kvps ...KVPair) error
- func (this *LevelDB) SaveOrUpdateListByIndex(dbkey LeveldbKey, index, value []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) SaveOrUpdateMapInListByIndex(dbkey, key LeveldbKey, index, value []byte, batch *leveldb.Batch) utils.ERROR
- func (this *LevelDB) Save_Transaction(key LeveldbKey, bs *[]byte) utils.ERROR
- type LeveldbInfo
- type LeveldbKey
Constants ¶
const ( MaxKeySize = 65535 //max key size MaxValueSize int = 1024 * 1024 * 1024 //max value size DBRemoveNum = 100 //分批次删除map集合中的数据,每批次默认数量 DBRemoveInterval = time.Second //分批次删除map集合中的数据,每批次默认间隔时间 ERROR_CODE_key_size = 1101 //数据库key长度错误 ERROR_CODE_value_size = 1102 //数据库value长度错误 )
Variables ¶
var ( DataType_Index_bs []byte // DataType_Data_Map_start_bs []byte // DataType_Data_Map_bs []byte // DataType_Data_Map_end_bs []byte // DataType_Data_List_start_bs []byte // DataType_Data_List_bs []byte // DataType_Data_List_end_bs []byte // DataType_Map_In_Map_start_bs []byte // DataType_Map_In_Map_bs []byte // DataType_Map_In_Map_end_bs []byte // )
Functions ¶
func LeveldbBuildKey ¶
leveldb中,所有的key都带一个key长度前缀,用2字节保存。 2字节容量是65535,因此key长度不能大于65535。 避免不同长度的key前缀查询的时候混合。
func LeveldbParseKey ¶
leveldb中,所有的key都带一个key长度前缀,用2字节保存。 2字节容量是65535,因此key长度不能大于65535。 避免不同长度的key前缀查询的时候混合。 @return uint16 长度 @return []byte 解析出来的key
Types ¶
type IndexLock ¶
func NewIndexLock ¶
type LevelDB ¶
type LevelDB struct {
// contains filtered or unexported fields
}
func CreateLevelDB ¶
func (*LevelDB) FindListAll ¶
func (this *LevelDB) FindListAll(dbkey LeveldbKey) ([]DBItem, error)
查询List集合中的所有项目
func (*LevelDB) FindListByIndex ¶
修改List集合中的记录
func (*LevelDB) FindListRange ¶
func (this *LevelDB) FindListRange(dbkey LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
查询List集合中一个范围的记录 不包含startIndex @order bool 查询顺序。true=从前向后查询;false=从后向前查询;
func (*LevelDB) FindListTotal ¶
查询List集合中记录总条数 @return uint64 记录总条数 @return []byte 开始index @return []byte 结束index @return error 记录总条数
func (*LevelDB) FindMapAllToList ¶
func (this *LevelDB) FindMapAllToList(dbkey LeveldbKey) ([]DBItem, error)
查询Map中所有的key和value值
func (*LevelDB) FindMapByKeys ¶
func (this *LevelDB) FindMapByKeys(dbkey LeveldbKey, keys ...LeveldbKey) ([]DBItem, error)
查询Map中所有的key和value值
func (*LevelDB) FindMapInListAll ¶
func (this *LevelDB) FindMapInListAll(dbkey LeveldbKey) ([]DBItem, utils.ERROR)
查询MapInList集合中一个范围的记录 不包含startIndex
func (*LevelDB) FindMapInListAllByKey ¶
func (this *LevelDB) FindMapInListAllByKey(dbkey, key LeveldbKey) ([]DBItem, error)
查询MapInList集合中所有key
func (*LevelDB) FindMapInListByIndex ¶
func (this *LevelDB) FindMapInListByIndex(dbkey, key LeveldbKey, index []byte) (*DBItem, utils.ERROR)
查找MapInList集合中的一个key的value值
func (*LevelDB) FindMapInListRangeByKeyIn ¶
func (this *LevelDB) FindMapInListRangeByKeyIn(dbkey, key LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
查询MapInList集合中一个范围的记录 不包含startIndex @order bool 查询顺序。true=从前向后查询;false=从后向前查询;
func (*LevelDB) FindMapInListRangeByKeyOut ¶
func (this *LevelDB) FindMapInListRangeByKeyOut(dbkey LeveldbKey, startIndex []byte, limit uint64, order bool) ([]DBItem, utils.ERROR)
查询MapInList集合中一个范围的记录 不包含startIndex @order bool 查询顺序。true=从前向后查询;false=从后向前查询;
func (*LevelDB) FindMapInListTotal ¶
func (this *LevelDB) FindMapInListTotal(dbkey, key LeveldbKey) (uint64, []byte, []byte, utils.ERROR)
查询MapInList集合中一个key下的列表记录总数 @return uint64 记录总条数 @return []byte 开始index @return []byte 结束index @return error 记录总条数
func (*LevelDB) FindMapInMapByKeyIn ¶
func (this *LevelDB) FindMapInMapByKeyIn(dbkey, keyOut, keyIn LeveldbKey) (*[]byte, error)
查询 Map中有Map 集合中内层key对应的值 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @keyIn LeveldbKey 内层map索引 @return []byte 内层map索引对应的值
func (*LevelDB) FindMapInMapByKeyOut ¶
func (this *LevelDB) FindMapInMapByKeyOut(dbkey, keyOut LeveldbKey) ([]DBItem, utils.ERROR)
查询 Map中有Map 集合中内层key对应的值 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @return []DBItem 内层map索引对应的值
func (*LevelDB) FindMore ¶
func (this *LevelDB) FindMore(keys ...LeveldbKey) ([]DBItem, error)
查找多条记录
func (*LevelDB) Has ¶
func (this *LevelDB) Has(key LeveldbKey) (bool, error)
检查key是否存在 @return bool true:存在;false:不存在;
func (*LevelDB) RemoveListAll ¶
func (this *LevelDB) RemoveListAll(dbkey LeveldbKey, batch *leveldb.Batch) error
删除List集合中的所有记录 @dbkey []byte 数据库ID
func (*LevelDB) RemoveListByIndex ¶
func (this *LevelDB) RemoveListByIndex(dbkey LeveldbKey, index []byte, batch *leveldb.Batch) utils.ERROR
删除List集合中1条数据 @isTransaction bool 是否是事务操作
func (*LevelDB) RemoveListInterval ¶
间隔删除List集合中的所有记录 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @dbkey []byte 数据库ID @num uint64 一次删除条数 @interval time.Duration 删除间隔时间
func (*LevelDB) RemoveListMore ¶
func (this *LevelDB) RemoveListMore(isTransaction bool, dbkey LeveldbKey, index ...[]byte) utils.ERROR
删除List集合中多条数据 @isTransaction bool 是否是事务操作
func (*LevelDB) RemoveMapByDbKey ¶
删除Map 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间
func (*LevelDB) RemoveMapByKey ¶
func (this *LevelDB) RemoveMapByKey(dbkey, key LeveldbKey, batch *leveldb.Batch) error
删除Map中的一个key
func (*LevelDB) RemoveMapByKey_Transaction ¶
func (this *LevelDB) RemoveMapByKey_Transaction(dbkey, key LeveldbKey) error
删除Map中的一个key 事务处理
func (*LevelDB) RemoveMapInListAll ¶
func (this *LevelDB) RemoveMapInListAll(dbkey, key LeveldbKey, batch *leveldb.Batch) error
删除MapInList集合中的所有记录
func (*LevelDB) RemoveMapInListByIndex ¶
func (this *LevelDB) RemoveMapInListByIndex(dbkey, key LeveldbKey, index []byte, batch *leveldb.Batch) utils.ERROR
删除MapInList集合中的一个key @isTransaction bool 是否是事务操作
func (*LevelDB) RemoveMapInListByKeyInterval ¶
func (this *LevelDB) RemoveMapInListByKeyInterval(dbkey, key LeveldbKey, num uint64, interval time.Duration) error
间隔删除MapInList集合中的一个key 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间
func (*LevelDB) RemoveMapInListMore ¶
func (this *LevelDB) RemoveMapInListMore(isTransaction bool, dbkey, key LeveldbKey, index ...[]byte) utils.ERROR
删除MapInList集合中的一个key @isTransaction bool 是否是事务操作
func (*LevelDB) RemoveMapInMapByKeyIn ¶
func (this *LevelDB) RemoveMapInMapByKeyIn(dbkey, keyOut, keyIn LeveldbKey, batch *leveldb.Batch) error
查询 Map中有Map 集合中内层key对应的值 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @keyIn LeveldbKey 内层map索引 @return []byte 内层map索引对应的值
func (*LevelDB) RemoveMapInMapByKeyIn_Transaction ¶
func (this *LevelDB) RemoveMapInMapByKeyIn_Transaction(dbkey, keyOut, keyIn LeveldbKey) error
查询 Map中有Map 集合中内层key对应的值 事务处理 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @keyIn LeveldbKey 内层map索引 @return []byte 内层map索引对应的值
func (*LevelDB) RemoveMapInMapByKeyOut ¶
func (this *LevelDB) RemoveMapInMapByKeyOut(dbkey, keyOut LeveldbKey, batch *leveldb.Batch) error
删除 Map中有Map 集合中外层key对应的值 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引
func (*LevelDB) RemoveMapInMapByKeyOutInterval ¶
func (this *LevelDB) RemoveMapInMapByKeyOutInterval(dbkey, keyOut LeveldbKey, num uint64, interval time.Duration) error
间隔删除 Map中有Map 集合中外层key对应的值 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间
func (*LevelDB) RemoveMore_Transaction ¶
删除多个操作 事务处理
func (*LevelDB) Remove_Transaction ¶
func (this *LevelDB) Remove_Transaction(key LeveldbKey) error
删除 事务处理
func (*LevelDB) SaveList ¶
func (this *LevelDB) SaveList(dbkey LeveldbKey, value []byte, batch *leveldb.Batch) ([]byte, utils.ERROR)
保存1条记录到List集合中 @return []byte 返回本记录索引。big.Int类型的byte字节序
func (*LevelDB) SaveListMore ¶
func (this *LevelDB) SaveListMore(dbkey LeveldbKey, value [][]byte, batch *leveldb.Batch) ([][]byte, utils.ERROR)
保存多条记录到List集合中 @isTransaction bool 是否是事务操作 @return []byte 返回本记录索引。big.Int类型的byte字节序
func (*LevelDB) SaveMapInList ¶
func (this *LevelDB) SaveMapInList(dbkey, key LeveldbKey, value []byte, batch *leveldb.Batch) ([]byte, utils.ERROR)
保存到MapInList集合中 @isTransaction bool 是否是事务操作 @return []byte index索引字节 @return error 错误
func (*LevelDB) SaveMapInListMore ¶
func (this *LevelDB) SaveMapInListMore(dbkey, key LeveldbKey, value [][]byte, batch *leveldb.Batch) ([][]byte, utils.ERROR)
保存多条记录到MapInList集合中 @isTransaction bool 是否是事务操作 @return []byte 索引字节 @return error 错误
func (*LevelDB) SaveMapInMap ¶
func (this *LevelDB) SaveMapInMap(dbkey, keyOut, keyIn LeveldbKey, value []byte, batch *leveldb.Batch) utils.ERROR
保存到 Map中有Map 集合中 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @keyIn LeveldbKey 内层map索引 @value []byte 内层map索引对应的值
func (*LevelDB) SaveMapInMap_Transaction ¶
func (this *LevelDB) SaveMapInMap_Transaction(dbkey, keyOut, keyIn LeveldbKey, value []byte) utils.ERROR
保存到 Map中有Map 集合中 事务处理 @dbkey LeveldbKey 数据库ID @keyOut LeveldbKey 外层map索引 @keyIn LeveldbKey 内层map索引 @value []byte 内层map索引对应的值
func (*LevelDB) SaveMap_Transaction ¶
func (this *LevelDB) SaveMap_Transaction(dbkey, key LeveldbKey, value []byte) utils.ERROR
保存到Map 事务处理
func (*LevelDB) SaveMore_TransacTion ¶
保存多条数据 事务处理
func (*LevelDB) SaveOrUpdateListByIndex ¶
func (this *LevelDB) SaveOrUpdateListByIndex(dbkey LeveldbKey, index, value []byte, batch *leveldb.Batch) utils.ERROR
修改List集合中的记录 @isTransaction bool 是否是事务操作
func (*LevelDB) SaveOrUpdateMapInListByIndex ¶
func (this *LevelDB) SaveOrUpdateMapInListByIndex(dbkey, key LeveldbKey, index, value []byte, batch *leveldb.Batch) utils.ERROR
修改MapInList集合中的一个key的value值 @isTransaction bool 是否是事务操作
func (*LevelDB) Save_Transaction ¶
func (this *LevelDB) Save_Transaction(key LeveldbKey, bs *[]byte) utils.ERROR
保存 事务处理
type LeveldbKey ¶
type LeveldbKey struct {
// contains filtered or unexported fields
}
func LeveldbParseKeyMore ¶
func LeveldbParseKeyMore(key []byte) ([]LeveldbKey, utils.ERROR)
多个长度+[]byte拼接,通过长度解析出来多个数据。不能有不符合规范的数据,有则报错