mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
better naming of redis keys
This commit is contained in:
@@ -40,6 +40,8 @@ func Recorder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case <-timer:
|
case <-timer:
|
||||||
|
// at the beginning of the next day (midnight), finalize
|
||||||
|
// the statistics of the previous day
|
||||||
yesterday := time.Now().UTC().AddDate(0, 0, -1).Format("2006-01-02")
|
yesterday := time.Now().UTC().AddDate(0, 0, -1).Format("2006-01-02")
|
||||||
|
|
||||||
if err := finalizeStats(db, yesterday); err != nil {
|
if err := finalizeStats(db, yesterday); err != nil {
|
||||||
@@ -53,14 +55,16 @@ func Recorder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KeyStatsPrefix = "stats:"
|
separator = ":"
|
||||||
KeyKindPrefix = "kind:"
|
KeyStats = "stats"
|
||||||
KeyActivePubkeysPrefix = "active_pubkeys:"
|
KeyKind = "kind"
|
||||||
|
KeyActivePubkeys = "active_pubkeys"
|
||||||
|
KeyTotalPubkeys = "total_pubkeys"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stats(day string) string { return KeyStatsPrefix + day }
|
func stats(day string) string { return KeyStats + separator + day }
|
||||||
func kind(kind int) string { return KeyKindPrefix + strconv.Itoa(kind) }
|
func kind(kind int) string { return KeyKind + separator + strconv.Itoa(kind) }
|
||||||
func activePubkeys(day string) string { return KeyActivePubkeysPrefix + day }
|
func activePubkeys(day string) string { return KeyActivePubkeys + separator + day }
|
||||||
|
|
||||||
func recordEvent(db redb.RedisDB, event *nostr.Event) error {
|
func recordEvent(db redb.RedisDB, event *nostr.Event) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
@@ -93,8 +97,8 @@ func finalizeStats(db redb.RedisDB, day string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = db.Client.HSet(ctx, stats(day),
|
err = db.Client.HSet(ctx, stats(day),
|
||||||
"active_pubkeys", activePubkeys,
|
KeyActivePubkeys, activePubkeys,
|
||||||
"total_pubkeys", totalPubkeys,
|
KeyTotalPubkeys, totalPubkeys,
|
||||||
).Err()
|
).Err()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user