storage.stores.KvAlertDataStore.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otoroshi_2.12 Show documentation
Show all versions of otoroshi_2.12 Show documentation
Lightweight api management on top of a modern http reverse proxy
The newest version!
package otoroshi.storage.stores
import akka.util.ByteString
import otoroshi.env.Env
import otoroshi.events.{AlertDataStore, AlertEvent}
import play.api.libs.json.{JsValue, Json}
import otoroshi.storage.RedisLike
import scala.concurrent.{ExecutionContext, Future}
class KvAlertDataStore(redisCli: RedisLike) extends AlertDataStore {
override def count()(implicit ec: ExecutionContext, env: Env): Future[Long] =
redisCli.llen(s"${env.storageRoot}:events:alerts")
override def findAllRaw(from: Long = 0, to: Long = 1000)(implicit
ec: ExecutionContext,
env: Env
): Future[Seq[ByteString]] =
redisCli.lrange(s"${env.storageRoot}:events:alerts", from, to)
override def push(event: JsValue)(implicit ec: ExecutionContext, env: Env): Future[Long] =
for {
config <- env.datastores.globalConfigDataStore.singleton()
n <- redisCli.lpush(s"${env.storageRoot}:events:alerts", Json.stringify(event))
- <- redisCli.ltrim(s"${env.storageRoot}:events:alerts", 0, config.maxLogsSize)
} yield n
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy