MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getCounterTimeStamp

Function getCounterTimeStamp

internal/storage/redis/cache.go:122–138  ·  view source on GitHub ↗
(rateLimitUnit key.TimeUnit)

Source from the content-addressed store, hash-verified

120}
121
122func getCounterTimeStamp(rateLimitUnit key.TimeUnit) (int64, error) {
123 now := time.Now().UTC()
124 switch rateLimitUnit {
125 case key.SecondTimeUnit:
126 return now.UnixMilli() * 10, nil
127 case key.MinuteTimeUnit:
128 return now.Unix(), nil
129 case key.HourTimeUnit:
130 return int64(now.Minute()), nil
131 case key.DayTimeUnit:
132 return int64(now.Hour()), nil
133 case key.MonthTimeUnit:
134 return int64(now.Day()), nil
135 }
136
137 return 0, fmt.Errorf("cannot recognize rate limit time unit %v", rateLimitUnit)
138}
139
140func (c *Cache) GetCounter(keyId string, rateLimitUnit key.TimeUnit) (int64, error) {
141 ctxTimeout, cancel := context.WithTimeout(context.Background(), c.rt)

Callers 1

IncrementCounterMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected