forked from coaidev/coai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistic.go
36 lines (28 loc) · 982 Bytes
/
statistic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package admin
import (
"chat/connection"
"chat/utils"
"github.com/go-redis/redis/v8"
"time"
)
func IncrErrorRequest(cache *redis.Client) {
utils.IncrOnce(cache, getErrorFormat(getDay()), time.Hour*24*7*2)
}
func IncrBillingRequest(cache *redis.Client, amount int64) {
utils.IncrWithExpire(cache, getBillingFormat(getDay()), amount, time.Hour*24*30*2)
utils.IncrWithExpire(cache, getMonthBillingFormat(getMonth()), amount, time.Hour*24*30*2)
}
func IncrRequest(cache *redis.Client) {
utils.IncrOnce(cache, getRequestFormat(getDay()), time.Hour*24*7*2)
}
func IncrModelRequest(cache *redis.Client, model string, tokens int64) {
utils.IncrWithExpire(cache, getModelFormat(getDay(), model), tokens, time.Hour*24*7*2)
}
func AnalysisRequest(model string, buffer *utils.Buffer, err error) {
instance := connection.Cache
if err != nil && err.Error() != "signal" {
IncrErrorRequest(instance)
return
}
IncrModelRequest(instance, model, int64(buffer.CountToken()))
}