通道的增删接口实现,数据表和目录结构调整

This commit is contained in:
2025-03-26 14:57:44 +08:00
parent 727297f4ee
commit 1ac87f79c6
36 changed files with 6753 additions and 153 deletions

68
cmd/tasks/main.go Normal file
View File

@@ -0,0 +1,68 @@
package main
import (
"context"
"errors"
"log/slog"
"platform/pkg/env"
"platform/pkg/logs"
"platform/pkg/orm"
"platform/pkg/rds"
"time"
"github.com/redis/go-redis/v9"
)
func main() {
Start()
}
func Start() {
ctx := context.Background()
env.Init()
logs.Init()
rds.Init()
orm.Init()
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for curr := range ticker.C {
err := process(ctx, curr)
if err != nil {
panic(err)
}
}
}
func process(ctx context.Context, curr time.Time) error {
// 获取并删除
script := redis.NewScript(`
local result = redis.call('ZRANGEBYSCORE', KEYS[1], 0, ARGV[1])
if #result > 0 then
redis.call('ZREMRANGEBYSCORE', KEYS[1], 0, ARGV[1])
end
return result
`)
// 计算时间范围
// 执行脚本
result, err := script.Run(ctx, rds.Client, []string{"tasks:session"}, curr.Unix()).Result()
if err != nil {
return err
}
// 处理结果
list, ok := result.([]string)
if !ok {
return errors.New("failed to convert result to []string")
}
for _, item := range list {
// 从数据库删除授权信息
slog.Debug(item)
}
return nil
}