`
sillycat
  • 浏览: 2552014 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

AMAZON ElastiCache(1)Redis Basic Operation and Testing

 
阅读更多
AMAZON ElastiCache(1)Redis Basic Operation and Testing

We are using AMAZON Server which is not Redis 3.0 yet, the latest is 2.8.x. So it is not really Redis Cluster, it is master and slave. And we can only balance the read operation on the slaves.

Finally, my colleague who is a really smart people find one scala driver for me.

build.sbt
"com.etaty.rediscala" %% "rediscala" % "1.4.2”,    //scala drvier
"com.orange.redis-embedded" % "embedded-redis" % "0.6" % “test”  //embedded server

And there is only one RedisElastiCache.scala core implementation
package com.sillycat.jobsconsumer.persistence

import akka.actor.ActorSystem
import akka.util.ByteString
import com.sillycat.jobsconsumer.utilities.{IncludeConfig, IncludeLogger}
import redis.{RedisClientMasterSlaves, RedisServer}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.collection.JavaConverters._

object RedisElastiCache extends IncludeLogger with IncludeConfig{

  implicit var actorSystem: ActorSystem = _

  private val cachePool = {
    try {
      logger.info("Init the Akka System.")
      actorSystem = ActorSystem("RedisScalaClients")

      val masterHost = config.getString(envStr("redis.master"))
      logger.info("Connect to master host = " + masterHost)
      val master = RedisServer(masterHost)

      val slaves = config.getStringList(envStr("redis.slaves")).asScala map { case slaveHost: String =>
        logger.info("Connect to slave host = " + slaveHost)
        RedisServer(slaveHost)
      }

      RedisClientMasterSlaves(master,slaves.toSeq)
    } catch {
      case x: Throwable =>
        logger.error("Couldn't connect to ElastiCache: " + x)
        null
    }
  }

  def releaseResource = {
    if(actorSystem != null){
        actorSystem.shutdown()
    }
  }

  def get(key: String):Option[Any] = {
    val future = cachePool.get(key)
    future onFailure {
      case e => {
        logger.error("Fetch to fetch the value from ElastiCache: " + e.getMessage)
      }
    }
    Await.result(future, 5 seconds) match {
      case Some(v:ByteString) => {
        logger.debug("Receiving the result from remote: " + new String(v.toArray))
        Some(new String(v.toArray))
      }
      case _ => {
        logger.error("Get Wrong format from ElastiCache.")
        None
      }
    }
  }

  def put(key:String, value:Any) = {
    val future = cachePool.set(key, value.toString)
    future onFailure {
      case e => logger.error("Fetch to put the value to ElastiCache: " + e.getMessage)
    }
    Await.result(future, 5 seconds)
  }

}

Here is the test class RedisElastiCacheSpec.scala
package com.sillycat.jobsconsumer.persistence

import com.sillycat.jobsconsumer.utilities.IncludeConfig
import org.scalatest.{Matchers, FunSpec}
import org.scalatest.BeforeAndAfterAll
import redis.embedded.RedisServer

/**
* Created by carl on 7/31/15.
*/
class RedisElastiCacheSpec extends FunSpec with Matchers with BeforeAndAfterAll with IncludeConfig{

  var redisEmbeded :RedisServer = _

  override def beforeAll() {
    if(config.getString("build.env").equals("test")){
      redisEmbeded = new RedisServer(6379)
      redisEmbeded.start()
    }
  }

  override def afterAll() {
    RedisElastiCache.releaseResource
    if(redisEmbeded != null){
      redisEmbeded.stop()
    }
  }

  describe("RedisElastiCache") {
    describe("#put & get"){
      it("Put String to ElastiCache") {
        val expect = "<job>sdfasdf</job>"
        RedisElastiCache.put("key1",expect)
        val result = RedisElastiCache.get("key1")
        result should be (Some(expect))
      }
    }
  }
}


References:
http://maciejb.me/2012/10/17/testing-your-java-amazon-sqs-code-with-elasticmq/
https://github.com/kstyrc/embedded-redis
http://msgpack.org/
http://alvinalexander.com/scala/serializing-deserializing-xml-scala-classes

https://github.com/xetorthio/jedis

master and slave
http://etaty.github.io/rediscala/latest/api/index.html#redis.RedisClientMasterSlaves
https://github.com/debop/debop4s/blob/36ab5a45181e03022d5b219ac0dec5bcaed714b6/debop4s-rediscala/src/test/scala/debop4s/rediscala/client/MasterSlavesFunSuite.scala

embeded server for testing
https://github.com/kstyrc/embedded-redis
分享到:
评论

相关推荐

    使用 ElastiCache for Redis 构建聊天应用程序的示例架构 .zip

    elasticache-chatapp构建集成 Amazon ElastiCache for Redis 的基于 Web 的聊天应用程序的示例架构。ElastiCache 聊天应用程序(见下图)演示了如何在前端使用 Vue.js 和 Socket.io 构建 Web 聊天客户端,以便使用 ...

    使用 Amazon ElastiCache Redis 和 Memcached 的示例和文档.zip

    Amazon ElastiCache 示例使用与Redis OSS 兼容的Amazon ElastiCache和Memcached的示例和文档。博客在线特征存储使用兼容 Redis OSS 的 Amazon ElastiCache 在 AWS 上构建在线特征存储,以支持需要超低延迟和高吞吐量...

    terraform-aws-elasticache-redis:用于配置ElastiCache Redis集群的Terraform模块

    terraform-aws-elasticache-redis Terraform模块以配置 Redis集群该项目是我们针对DevOps的全面方法的一部分。 它是100%开源的,并根据许可。 从字面上看,我们有,它们都是开源的并且维护良好。 去看一下!安全与...

    elasticache-refarch-chatapp:使用ElastiCache for Redis构建聊天应用程序的示例架构

    弹性的chatapp 用于构建集成了Amazon ElastiCache for Redis的基于Web的聊天应用程序的示例架构。 ElastiCache聊天应用程序(见下图)演示了如何在前端使用Vue.js和Socket.io构建Web聊天客户端,以使用Node.js,...

    terraform-aws-elasticache-redis:用于创建Amazon Web Services(AWS)Redis ElastiCache集群的Terraform模块

    1. **集群大小**:定义Redis集群的节点数量,包括主节点和副本节点。 2. **安全组**:配置访问ElastiCache集群的安全规则,如入站和出站端口,以及允许的IP范围。 3. **参数组**:设置Redis实例的参数,如内存限制、...

    redisbackup-to-s3:从 AWS Elasticache (Redis) 获取数据库转储并将其复制到 AWS S3

    从 AWS Elasticache (Redis) 获取数据库转储并将其复制到 AWS S3 这里我们使用 [Terraform] ( ) 来进行自动化。 #要求 安装 Terraform 您需要提供以下值 AWS ACCESS KEY AWS SECRET KEY AWS REGION AWS ...

    用于创建 AWS Redis ElastiCache 集群的 Terraform 模块 .zip

    Terraform-aws-elasticache-redis用于创建 AWS Redis ElastiCache 集群的 Terraform 模块Terraform 版本对于 AWS 提供商 &gt;= 4.0.0,将模块版本固定至~&gt; v3.0。对于 Terraform 0.14.5 及更高版本和AWS Provider ,将...

    Terraform 模块用于配置 ElastiCache Redis 集群.zip

    Terraform 模块用于配置ElastiCacheRedis 集群或无服务器实例。提示 将 Atmos 与 Terraform 结合使用Cloud Posseatmos使用 Terraform 轻松协调多个环境。可与Github Actions、Atlantis或Spacelift配合使用。观看使用...

    aws-node-elasticache-vpc:在VPC中使用Elasticache(Redis)的无服务器功能

    aws-node-elasticache-vpc 一组在VPC中使用Elasticache(redis)的无服务器功能入门为了安装和运行此示例,您需要使用系统配置的AWS账户凭证。 要开始使用AWS账户配置,请点击此克隆aws-node-elasticache-vpc并安装...

    redis desktop manager 0.98

    RDM supports SSL/TLS encryption, SSH tunnels, TLS over SSH tunnel (AWS ElastiCache with In-Transit Encryption) and cloud Redis instances such as: Amazon ElastiCache, Microsoft Azure Redis Cache and ...

    redis_downyi.com.zip

    redis desktop manager(redisdesktop...rdm支持ssl/tls加密,ssh隧道,基于ssh隧道的tls(带有in-transit加密的aws elasticache)和云redis实例,例如:amazon elasticache,microsoft azure redis cache和redis labs。

    Redis可视化管理工具

    Redis桌面管理器(又名RDM) -是一个快速开放源码的...RDM支持SSL/TLS加密、SSH隧道、SSH隧道之上的TLS (AWS ElastiCache支持传输加密)和云Redis实例,如:Amazon ElastiCache、Microsoft Azure Redis Cache和Redis Labs。

    redis-desktop-manager-2019.0.0.zip 免费

    Redis桌面管理器(又名RDM) - 是一...RDM支持SSL / TLS加密,SSH隧道,基于SSH隧道的TLS(带有In-Transit加密的AWS ElastiCache)和云Redis实例,例如:Amazon ElastiCache,Microsoft Azure Redis Cache和Redis Labs

    redis-desktop-manager-2020.0.196.exe

    Redis桌面管理器(又名RDM) - 是一...RDM支持SSL / TLS加密,SSH隧道,基于SSH隧道的TLS(带有In-Transit加密的AWS ElastiCache)和云Redis实例,例如:Amazon ElastiCache,Microsoft Azure Redis Cache和Redis Labs

    Redis Desktop Manager 0.9.7 Windows安装包

    Redis Desktop Manager (aka RDM) — is a fast open source ...RDM supports SSL/TLS encryption, SSH tunnels and cloud Redis instances such as: Amazon ElastiCache, Microsoft Azure Redis Cache and Redis Labs.

    redis desktop manager_2019.5.rar

    如将键视为树,CRUD键,通过shell执行命令等,并且Redis Desktop Manager支持SSL / TLS加密,SSH隧道,基于SSH隧道的TLS(带有In-Transit加密的AWS ElastiCache)和云Redis实例,例如:Amazon ElastiCache,...

    Redis Desktop Manager

    Redis Desktop Manager 是一个可视化...RDM支持SSL / TLS加密,SSH隧道,基于SSH隧道的TLS(带有In-Transit加密的AWS ElastiCache)和云Redis实例,例如:Amazon ElastiCache,Microsoft Azure Redis Cache和Redis Labs

    redis-desktop-manager-2020.4.104 mac系统

    RedisDesktopManager 2020.4.104 mac 最新版本。Redis桌面管理器(又名RDM) -是一个可以应用于Windows, Linux...RDM支持SSL/TLS加密,SSH隧道和云Redis实例,如:Amazon ElastiCache,微软Azure Redis缓存和Redis实验室。

    Redis Desktop Manager 2020.0.79 for Mac

    可以与 Amazon ElastiCache,Microsoft Azure Redis Cache 和 Redis Labs 等服一起使用。使用 RDM 分析您的Redis服务器内存使用情况,并通过批量删除来删除过期的数据。RDM支持 TLS,SSH 和 TLS-over-SSH 隧道,可...

    redis-desktop-manager-v0.9.3.817

    RedisDesktopManager 是 Redis桌面...RDM支持SSL / TLS加密,SSH隧道,基于SSH隧道的TLS(带有In-Transit加密的AWS ElastiCache)和云Redis实例,例如:Amazon ElastiCache,Microsoft Azure Redis Cache和Redis Labs

Global site tag (gtag.js) - Google Analytics