mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-06 15:55:48 +08:00
使用KV数据库来管理IP名单
This commit is contained in:
@@ -37,7 +37,24 @@ func (this *Tx[T]) Set(key string, value T) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.table.set(this, key, valueBytes, value, false)
|
||||
return this.table.set(this, key, valueBytes, value, false, false)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) SetSync(key string, value T) error {
|
||||
if this.readOnly {
|
||||
return errors.New("can not set value in readonly transaction")
|
||||
}
|
||||
|
||||
if len(key) > KeyMaxLength {
|
||||
return ErrKeyTooLong
|
||||
}
|
||||
|
||||
valueBytes, err := this.table.encoder.Encode(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.table.set(this, key, valueBytes, value, false, true)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) Insert(key string, value T) error {
|
||||
@@ -54,7 +71,7 @@ func (this *Tx[T]) Insert(key string, value T) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.table.set(this, key, valueBytes, value, true)
|
||||
return this.table.set(this, key, valueBytes, value, true, false)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) Get(key string) (value T, err error) {
|
||||
@@ -78,6 +95,20 @@ func (this *Tx[T]) Close() error {
|
||||
}
|
||||
|
||||
func (this *Tx[T]) Commit() (err error) {
|
||||
return this.commit(DefaultWriteOptions)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) CommitSync() (err error) {
|
||||
return this.commit(DefaultWriteSyncOptions)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) Query() *Query[T] {
|
||||
var query = NewQuery[T]()
|
||||
query.SetTx(this)
|
||||
return query
|
||||
}
|
||||
|
||||
func (this *Tx[T]) commit(opt *pebble.WriteOptions) (err error) {
|
||||
defer func() {
|
||||
var panicErr = recover()
|
||||
if panicErr != nil {
|
||||
@@ -88,11 +119,5 @@ func (this *Tx[T]) Commit() (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
return this.batch.Commit(DefaultWriteOptions)
|
||||
}
|
||||
|
||||
func (this *Tx[T]) Query() *Query[T] {
|
||||
var query = NewQuery[T]()
|
||||
query.SetTx(this)
|
||||
return query
|
||||
return this.batch.Commit(opt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user