Skip to content

Commit

Permalink
Use seconds instead of millis (#27)
Browse files Browse the repository at this point in the history
* Use seconds instead of millis
  • Loading branch information
nryanov committed May 12, 2021
1 parent a1f8ff9 commit 88c4454
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: genkai CI

on:
pull_request:
branches:
- master
branches: ['*']
push:
branches:
- master
branches: ['*']

jobs:
scalafmt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object RedisStrategy {
private val argsPart = List(
underlying.tokens.toString,
underlying.refillAmount.toString,
underlying.refillDelay.toMillis.toString
underlying.refillDelay.toSeconds.toString
)

override val acquireLuaScript: String = LuaScript.tokenBucketAcquire
Expand All @@ -80,10 +80,10 @@ object RedisStrategy {
List(s"token_bucket:${Key[A].convert(value)}")

override def permissionsArgs(instant: Instant): List[String] =
instant.toEpochMilli.toString :: argsPart
instant.getEpochSecond.toString :: argsPart

override def acquireArgs(instant: Instant, cost: Long): List[String] =
instant.toEpochMilli.toString :: cost.toString :: argsPart
instant.getEpochSecond.toString :: cost.toString :: argsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand All @@ -105,7 +105,7 @@ object RedisStrategy {

override def keys[A: Key](value: A, instant: Instant): List[String] = {

val ts = instant.truncatedTo(underlying.window.unit).toEpochMilli
val ts = instant.truncatedTo(underlying.window.unit).getEpochSecond
List(s"fixed_window:${Key[A].convert(value)}:$ts")
}

Expand Down Expand Up @@ -141,10 +141,10 @@ object RedisStrategy {
)

override def permissionsArgs(instant: Instant): List[String] =
instant.toEpochMilli.toString :: permissionArgsPart
instant.getEpochSecond.toString :: permissionArgsPart

override def acquireArgs(instant: Instant, cost: Long): List[String] =
instant.toEpochMilli.toString :: cost.toString :: acquireArgsPart
instant.getEpochSecond.toString :: cost.toString :: acquireArgsPart

override def isAllowed(value: Long): Boolean = value != 0

Expand Down

0 comments on commit 88c4454

Please sign in to comment.