# cluster-timewheel **Repository Path**: burybell/cluster-timewheel ## Basic Information - **Project Name**: cluster-timewheel - **Description**: go实现的时间轮,可单机可分布式 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-03-22 - **Last Updated**: 2025-01-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # cluster-timewheel ### 介绍 go实现的时间轮,可单机可分布式 ### 安装 ```cmd go get gitee.com/burybell/cluster-timewheel@v1.0.1 ``` ### 案例 #### 单机 ```go package main import ( "fmt" timewheel "gitee.com/burybell/cluster-timewheel" "time" ) const ( CallPrint timewheel.CallId = iota ) func init() { timewheel.AddCall(CallPrint, func(ctx *timewheel.Context) { fmt.Println("call1", ctx.Val()) }) } func main() { local := timewheel.NewLocal(time.Second, 60) local.Run() for i := 0; i < 1000; i++ { context := timewheel.NewContext("cl1") local.AddTimer(time.Second*time.Duration(i), fmt.Sprintf("id-%d", i), context, CallPrint) } select {} } ``` #### 分布式 ```go package main import ( "fmt" timewheel "gitee.com/burybell/cluster-timewheel" "github.com/go-redis/redis" "time" ) const ( CallPrint timewheel.CallId = iota ) func init() { timewheel.AddCall(CallPrint, func(ctx *timewheel.Context) { fmt.Println("call1", ctx.Val()) }) } func main() { client := redis.NewClient(&redis.Options{Addr: "127.0.0.1:6379"}) cluster := timewheel.NewCluster(client, "wheel-name", nil) cluster.Run() for i := 0; i < 1000; i++ { cluster.AddTimer(time.Second*time.Duration(i), fmt.Sprintf("id-%d", i), nil, CallPrint) } select {} } ```