Skip to content

Commit

Permalink
fix #135, fix #252
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Feb 22, 2019
1 parent 2141811 commit 5774bcc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import storage.cassandra.CassandraDataStores
import storage.inmemory.InMemoryDataStores
import storage.leveldb.LevelDbDataStores
import storage.mongo.MongoDataStores
import storage.redis.next._
import storage.redis.RedisDataStores
import utils.http._

Expand Down Expand Up @@ -353,6 +354,12 @@ class Env(val configuration: Configuration,
configuration.getOptional[String]("app.storage").getOrElse("redis") match {
case _ if clusterConfig.mode == ClusterMode.Worker =>
new SwappableInMemoryDataStores(configuration, environment, lifecycle, this)
case "redis-pool" if clusterConfig.mode == ClusterMode.Leader => new RedisCPDataStores(configuration, environment, lifecycle, this)
case "redis-mpool" if clusterConfig.mode == ClusterMode.Leader => new RedisMCPDataStores(configuration, environment, lifecycle, this)
case "redis-cluster" if clusterConfig.mode == ClusterMode.Leader => new RedisClusterDataStores(configuration, environment, lifecycle, this)
case "redis-lf" if clusterConfig.mode == ClusterMode.Leader => new RedisLFDataStores(configuration, environment, lifecycle, this)
case "redis-sentinel" if clusterConfig.mode == ClusterMode.Leader => new RedisSentinelDataStores(configuration, environment, lifecycle, this)
case "redis-sentinel-lf" if clusterConfig.mode == ClusterMode.Leader => new RedisSentinelLFDataStores(configuration, environment, lifecycle, this)
case "redis" if clusterConfig.mode == ClusterMode.Leader =>
new RedisDataStores(configuration, environment, lifecycle, this)
case "inmemory" if clusterConfig.mode == ClusterMode.Leader =>
Expand All @@ -368,6 +375,12 @@ class Env(val configuration: Configuration,
case "leveldb" => new LevelDbDataStores(configuration, environment, lifecycle, this)
case "cassandra" => new CassandraDataStores(configuration, environment, lifecycle, this)
case "mongo" => new MongoDataStores(configuration, environment, lifecycle, this)
case "redis-pool" => new RedisCPDataStores(configuration, environment, lifecycle, this)
case "redis-mpool" => new RedisMCPDataStores(configuration, environment, lifecycle, this)
case "redis-cluster" => new RedisClusterDataStores(configuration, environment, lifecycle, this)
case "redis-lf" => new RedisLFDataStores(configuration, environment, lifecycle, this)
case "redis-sentinel" => new RedisSentinelDataStores(configuration, environment, lifecycle, this)
case "redis-sentinel-lf" => new RedisSentinelLFDataStores(configuration, environment, lifecycle, this)
case e => throw new RuntimeException(s"Bad storage value from conf: $e")
}
}
Expand Down
11 changes: 6 additions & 5 deletions otoroshi/app/storage/redis/RedisDataStores.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import akka.http.scaladsl.util.FastFuture
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import auth.AuthConfigsDataStore
import cluster.{ClusterStateDataStore, RedisClusterStateDataStore}
import cluster.{ClusterStateDataStore, InMemoryClusterStateDataStore, RedisClusterStateDataStore}
import com.typesafe.config.ConfigFactory
import env.Env
import events.{AlertDataStore, AuditDataStore, HealthCheckDataStore}
import gateway.{InMemoryRequestsDataStore, RequestsDataStore}
import models._
import otoroshi.script.{RedisScriptDataStore, ScriptDataStore}
import otoroshi.script.{InMemoryScriptDataStore, RedisScriptDataStore, ScriptDataStore}
import play.api.inject.ApplicationLifecycle
import play.api.libs.json._
import play.api.{Configuration, Environment, Logger}
import redis.{RedisClientMasterSlaves, RedisServer}
import ssl.{CertificateDataStore, ClientCertificateValidationDataStore, RedisClientCertificateValidationDataStore}
import redis.{RedisClientMasterSlaves, RedisCluster, RedisServer}
import ssl.{CertificateDataStore, ClientCertificateValidationDataStore, InMemoryClientCertificateValidationDataStore, RedisClientCertificateValidationDataStore}
import storage.inmemory._
import storage.{DataStoreHealth, DataStores, Healthy, Unreachable}

import scala.concurrent.{ExecutionContext, Future}
Expand All @@ -39,7 +40,7 @@ class RedisDataStores(configuration: Configuration, environment: Environment, li
.getOrElse(ConfigFactory.empty)
)
lazy val redisDispatcher = redisActorSystem.dispatcher
lazy val redis = {
lazy val redis: RedisClientMasterSlaves = {
// import collection.JavaConverters._
implicit val ec = redisDispatcher
val master = RedisServer(
Expand Down
7 changes: 4 additions & 3 deletions otoroshi/app/storage/redis/RedisStore.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage.redis

import akka.NotUsed
import akka.actor.ActorSystem
import akka.http.scaladsl.util.FastFuture._
import akka.http.scaladsl.util.FastFuture
import akka.stream.Materializer
Expand All @@ -9,9 +10,8 @@ import akka.util.ByteString
import env.Env
import play.api.Logger
import play.api.libs.json._
import redis.RedisClientMasterSlaves
import storage.BasicStore
import utils.LocalCache
import redis.{RedisClientMasterSlaves, RedisCluster, RedisCommands}
import storage._

import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
Expand Down Expand Up @@ -213,3 +213,4 @@ object Redis {
s"$command can be very slow as it's performing in n calls to redis for n keys. You might not want to use $command for good performances"
)
}

0 comments on commit 5774bcc

Please sign in to comment.