增加网站每日独立IP统计

This commit is contained in:
GoEdgeLab
2024-04-12 20:12:09 +08:00
parent f1e368f85d
commit ca43d119e4
5 changed files with 442 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ package kvstore
import (
"errors"
"github.com/cockroachdb/pebble"
"sync"
)
@@ -52,6 +53,29 @@ func (this *DB) Store() *Store {
return this.store
}
func (this *DB) Inspect(fn func(key []byte, value []byte)) error {
it, err := this.store.rawDB.NewIter(&pebble.IterOptions{
LowerBound: []byte(this.namespace),
UpperBound: append([]byte(this.namespace), 0xFF, 0xFF),
})
if err != nil {
return err
}
defer func() {
_ = it.Close()
}()
for it.First(); it.Valid(); it.Next() {
value, valueErr := it.ValueAndErr()
if valueErr != nil {
return valueErr
}
fn(it.Key(), value)
}
return nil
}
// Truncate the database
func (this *DB) Truncate() error {
this.mu.Lock()