elasticache_类固醇上的分布式缓存:Amazon ElastiCache

elasticache

Web applications can often be made to perform better and run faster by caching critical pieces of data in memory.  Frequently accessed data, results of time-consuming/expensive database queries, search results, session data and results of complex calculations are usually very good candidates for cache storage. We will understand basics of caching post which we will deep dive in Amazon ElastiCache

通过将关键数据缓存在内存中,通常可以使Web应用程序具有更好的性能和更快的运行速度。 经常访问的数据,耗时/昂贵的数据库查询结果,搜索结果,会话数据以及复杂的计算结果通常是缓存存储的很好的候选者。 我们将了解缓存后的基础知识,我们将在Amazon ElastiCache中进行深入探讨

缓存架构的类型 (Types of Caching Architectures)

本地内存缓存 (Local In-Memory Caching)

The Cache objects are stored locally in-memory (example Java Heap) of the application servers. Open source frameworks like EHCache, OSCache can be used inside Java Application Servers for serving cached items from the heap. Since the cache items are accessed from the same process heap of the application programs, this model offers very fast “Set/Get” operations for cache items. On the other hand because of the limited nature of RAM only few GB can be cached in the Local In-Memory Caching model.

缓存对象存储在应用程序服务器的本地内存中(例如Java Heap)。 诸如EHCache,OSCache之类的开源框架可以在Java Application Server内部使用,以服务于堆中的缓存项。 由于缓存项是从应用程序的同一进程堆访问的,因此该模型为缓存项提供了非常快速的“设置/获取”操作。 另一方面,由于RAM的有限性,在本地内存缓存模型中只能缓存少量GB。

网络附加缓存 (Network Attached Caching)

The Cache objects are stored in a separate Cache Server accessible over TCP network. Cache Clients or Cache Drivers need to be embedded on the Application Servers which enable the GET/PUT/Sync operations. Cache behaves like a network attached RAM. Terracotta Cache is an example of network attached RAM caching. Since the cache operations need to travel over the network, few milliseconds of latency can be felt on “Set/Get” operations. Since the cache is centralized and consolidated it is easy manage, extend and maintain this tier.

缓存对象存储在可通过TCP网络访问的单独的缓存服务器中。 缓存客户端或缓存驱动程序需要嵌入在启用GET / PUT / Sync操作的应用服务器上。 缓存的行为类似于网络连接的RAM。 Terracotta Cache是​​网络附加RAM缓存的一个示例。 由于缓存操作需要通过网络传输,因此“设置/获取”操作可能会感觉到几毫秒的延迟。 由于缓存是集中和合并的,因此易于管理,扩展和维护该层。

分布式缓存 (Distributed Caching)

Distributed caching may run on multiple cache servers so that it can grow in size and in transactional capacity. It is mainly used to store application data residing in database and web session data. The web applications may access the distributed cache deployed locally or remotely using a client library. The most popular distributed caching software is Memcached. Deploying large farms of Memcached has become possible because memory is affordable and cheap now and networks have become very fast.  Distributed cache works well on low cost commodity machines and cloud providers. One such popular distributed cache on AWS we are going to discuss in this article is Amazon ElastiCache.

分布式缓存可以在多个缓存服务器上运行,以便可以增加大小和事务处理能力。 它主要用于存储数据库和Web会话数据中的应用程序数据。 Web应用程序可以使用客户端库访问本地或远程部署的分布式缓存。 最流行的分布式缓存软件是Memcached。 部署大型Memcached服务器场已成为可能,因为现在内存价格低廉且价格便宜,并且网络变得非常快。 分布式缓存在低成本的商用机器和云提供商上运行良好。 我们将在本文中讨论的一种在AWS上流行的分布式缓存是Amazon ElastiCache。

Amazon ElastiCache简介: (Introducing Amazon ElastiCache:)

Amazon ElastiCache is a managed distributed caching service provided by Amazon Web services.  Amazon ElastiCache currently uses memcached as the caching engine, so memcached compatible programs can be easily ported to Amazon ElastiCache usually without code change. With Amazon ElastiCache operating as a separate tier, AWS team offloads typical cache tier management tasks like the ones listed below from the application and infrastructure teams of the customer:

Amazon ElastiCache是​​由Amazon Web服务提供的托管分布式缓存服务。 Amazon ElastiCache当前使用memcached作为缓存引擎,因此通常可以在不更改代码的情况下轻松将兼容memcached的程序移植到Amazon ElastiCache。 通过将Amazon ElastiCache作为单独的层运行,AWS团队可以从客户的应用程序和基础架构团队分担以下典型的缓存层管理任务:

  • Managing the work involved in setting up a distributed in-memory cache tier

    管理建立分布式内存中缓存层所涉及的工作
  • Provisioning the server resources you request to installing the caching software

    调配您请求安装缓存软件的服务器资源
  • Common administrative tasks such as failure detection, recovery and software patching

    常见的管理任务,例如故障检测,恢复和软件修补
  • Adding / removing Cache nodes from the cluster

    从集群添加/删除缓存节点

Now lets us explore in detail the major components of Amazon ElastiCache.

现在,让我们详细探索Amazon ElastiCache的主要组件。

Amazon ElastiCache的组件 (Components of Amazon ElastiCache )

alt

Amazon ElastiCache节点: (Amazon ElastiCache node:)

Amazon ElastiCache node is a memcached instance with a unique endpoint URL and port. You can configure the memcached configuration file used by the popular memcached clients with this endpoint URL(s) provided. Memcached clients are available for all popular programming languages and the latest list can be found here. Amazon ElastiCache nodes are protocol compliant with memcached server and usually the same memcached client mentioned above can be switched to Amazon ElastiCache nodes without requiring code changes. You can use standard Memcached operations like get, set, incr and decr in exactly the same way as you would in your existing Memcached deployments and as well perform requests using both Binary and Text messages over TCP protocol.

Amazon ElastiCache节点是具有唯一端点URL和端口的memcached实例。 您可以使用提供的此终结点URL配置流行的memcached客户端使用的memcached配置文件。 Memcached客户端可用于所有流行的编程语言,最新列表可在此处找到。 Amazon ElastiCache节点与memcached服务器兼容,并且通常可以将上述提到的同一memcached客户端切换到Amazon ElastiCache节点,而无需更改代码。 您可以使用与现有Memcached部署完全相同的方式来使用标准的Memcached操作(如get,set,incr和decr),并可以通过TCP协议使用Binary和Text消息执行请求。

A sample pseudo code illustrating SET operation in Text TCP protocol using Java Spymemcached library and Amazon ElastiCache Tier:

示例伪代码示例了使用Java Spymemcached库和Amazon ElastiCache层的Text TCP协议中的SET操作:

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.*;
import java.util.*;
public class ElastiCacheTextTCPSet {
 public void setTextValue() throws IOException {
 MemcachedClient memcachedClient = new MemcachedClient( new DefaultConnectionFactory(),AddrUtil.getAddresses("ecache1a.sqjbuo.0001.use1.cache.amazonaws.com:11211"));
 String key = "1000002";
 String value = "1000002-Test value in Text";
 Integer expires = Integer.parseInt("1000");
 try {
 Future<Boolean> result = memcachedClient.set(key, expires, value);
…………
…………
 } catch (InterruptedException e) {
 e.printStackTrace();
 } catch (ExecutionException e) {
 e.printStackTrace();
 }
 memcachedClient.shutdown();
 }

}

A sample program illustrating GET operation in Text TCP protocol using Java Spymemcached library and Amazon ElastiCache Tier:

一个示例程序,说明了使用Java Spymemcached库和Amazon ElastiCache层在Text TCP协议中进行GET操作:

import java.io.IOException;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactory;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.HashAlgorithm;
import net.spy.memcached.MemcachedClient;
import java.util.*;

public class ElastiCacheTextTCPGet {
 public void getTextValue() throws Exception {
 MemcachedClient memcachedClient = new MemcachedClient( new DefaultConnectionFactory(),AddrUtil.getAddresses("ecache1a.sqjbuo.0001.use1.cache.amazonaws.com:11211"));
 String key = "1000002";
 Object obj=null;
 try {
 obj = memcachedClient.get(key);
 System.out.println("Value = :"+obj.toString());
 } catch (Exception e) {
 e.printStackTrace();
 }
 memcachedClient.shutdown();
 }

}

You can also communicate with Amazon ElastiCache using Binary protocol of Memcached. A sample program illustrating SET operation using Java Spymemcached-TCP Binary Protocol and Amazon ElastiCache Tier:

您还可以使用Memcached的二进制协议与Amazon ElastiCache通信。 一个示例程序,说明了使用Java Spymemcached-TCP二进制协议和Amazon ElastiCache层的SET操作:

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.BinaryConnectionFactory;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.*;
import java.util.*;
public class ElastiCacheBinaryTCPSet {
 public void setBinaryValue() throws Exception {
 MemcachedClient memcachedClient = new MemcachedClient( new BinaryConnectionFactory(),AddrUtil.getAddresses("ecache1a.sqjbuo.0001.use1.cache.amazonaws.com:11211"));
 String key = "1000004";
 String value = "1000004-Test value in Binary-TCP protocol";
 Integer expires = Integer.parseInt("1000");
 try {
 Future<Boolean> result = memcachedClient.set(key, expires, value);
 } catch (InterruptedException e) {
 e.printStackTrace();
 } catch (ExecutionException e) {
 e.printStackTrace();
 }
 memcachedClient.shutdown();
 }
}

Memcached software version 1.4.5 is used as the cache engine in the Amazon ElastiCache nodes. Cache nodes accept connections on port 11211 and only for Amazon EC2 network. In order to allow network requests to your Cache Nodes from web/application EC2 instances, you will need to authorize access in AWS security groups. Amazon ElastiCache provides variety of cache node types (capacities) and pricing models to suit the customer requirements. The latest cache node type information can be found here

Memcached软件版本1.4.5用作Amazon ElastiCache节点中的缓存引擎。 缓存节点仅在Amazon EC2网络上接受端口11211上的连接。 为了允许网络请求从Web /应用程序EC2实例到您的缓存节点,您将需要授权AWS安全组中的访问。 Amazon ElastiCache提供了各种缓存节点类型(容量)和定价模型,以满足客户的需求。 最新的缓存节点类型信息可以在这里找到

Amazon ElastiCache集群: (Amazon ElastiCache Cluster:)

An Amazon ElastiCache Cluster is a collection of one or more Amazon ElastiCache Nodes. All Cache Nodes within a Cache Cluster will be of the same Node Type (capacity). A node type is an associated memory size of the cache nodes to be deployed in your cache cluster. Currently cache nodes come in 11 different capacities in AWS to suit a variety of your needs, new capacity types will be added by AWS in future. If you need cache nodes of different capacities in your application systems you need to create multiple cache clusters in your account. The Cache Cluster should be supplied with an Identifier name by the customer during its creation process. For example: if you give a name “ecache1a” for the cache cluster, the endpoint URL of a particular cache node may look like this ecache1a.sqjbuo.0001.use1.cache.amazonaws.com:11211.This name identifies a particular Cache Cluster when interacting with the Amazon ElastiCache API and commands. The Cache Cluster Identifier must be unique for that customer in an AWS region.

Amazon ElastiCache集群是一个或多个Amazon ElastiCache节点的集合。 缓存群集中的所有缓存节点将具有相同的节点类型(容量)。 节点类型是要在缓存群集中部署的缓存节点的关联内存大小。 当前,缓存节点在AWS中具有11种不同的容量,可以满足您的各种需求,AWS将来会添加新的容量类型。 如果在应用程序系统中需要不同容量的缓存节点,则需要在帐户中创建多个缓存集群。 客户在其创建过程中应为缓存群集提供一个标识符名称。 例如:如果为缓存集群指定名称“ ecache1a”,则特定缓存节点的端点URL可能类似于以下ecache1a .sqjbuo.0001.use1.cache.amazonaws.com:11211。此名称标识特定的缓存。与Amazon ElastiCache API和命令进行交互时进行集群。 缓存群集标识符对于该客户在AWS区域中必须是唯一的。

While configuring a cluster you need to mention the availability zone in in which you would prefer to deploy your Cache Cluster. Currently a single Amazon ElastiCache Cluster cannot span multiple Availability zones inside an Amazon EC2 region. It is advised to keep the cache cluster and related web/application ec2 instances in the same Availability zone for better latency. Refer here for common Amazon ElastiCache deployment architectures in AWS infrastructure.  Parameters and Security group settings of all the nodes inside the Amazon ElastiCache cluster can be grouped and controlled at cluster level. This clustering/grouping of cache nodes helps in easy management and maintenance of huge farms of cache nodes.  Amazon ElastiCache Clusters are can be created, using the AWS Management Console, Amazon ElastiCache APIs, or Command Line Tools. In addition to the above you can specify whether you would like to receive SNS notifications related to your cache nodes/cluster using Amazon Simple Notification Service (SNS) system. You can either select an existing SNS topic or disable notifications completely as well for the entire Amazon ElastiCache Cluster.

在配置集群时,您需要提及可用性区域,您希望在该可用性区域中部署缓存集群。 当前,单个Amazon ElastiCache集群无法跨越Amazon EC2区域内的多个可用性区域。 建议将缓存群集和相关的Web /应用程序ec2实例保留在同一可用区中,以实现更好的延迟。 请参阅此处以了解AWS基础架构中的常见Amazon ElastiCache部署架构。 可以在集群级别对Amazon ElastiCache集群内所有节点的参数和安全组设置进行分组和控制。 缓存节点的这种群集/分组有助于轻松管理和维护庞大的缓存节点场。 可以使用AWS管理控制台,Amazon ElastiCache API或命令行工具创建Amazon ElastiCache集群。 除上述内容外,您还可以指定是否要使用Amazon Simple Notification Service(SNS)系统接收与您的缓存节点/集群有关的SNS通知。 您可以选择一个现有的SNS主题,也可以完全禁用整个Amazon ElastiCache集群的通知。

Amazon ElastiCache参数组: (Amazon ElastiCache Parameter Group:)

Amazon ElastiCache Parameter Groups allows you to control the runtime parameters and cache engine configuration values of your Nodes. The values configured will get passed to memcached nodes during startup and gets applied to all the nodes associated in the Amazon ElastiCache Cluster. If you do not specify a Cache Parameter Group for your Cache Cluster, then a default Cache Parameter Group (default.memcached1.4) will be used. Usually the default parameter group contains engine defaults and Amazon ElastiCache system defaults optimized for the Cache Cluster nodes you are running. Since Amazon ElastiCache by default chooses the optimal configuration parameters for your Cache Cluster taking into account the Node Type’s memory/compute resource capacity, it does not require change for most use cases. However, if you want your Cache Cluster to run with your custom configuration values, you can simply create a new Cache Parameter Group, modify the desired parameters and use it for new or existing clusters. In event the custom parameter group is applied to running cache cluster the changes will not be applied to the Cache Nodes until the Cache Cluster is rebooted.

Amazon ElastiCache参数组使您可以控制节点的运行时参数和缓存引擎配置值。 配置的值将在启动期间传递到memcached节点,并应用于Amazon ElastiCache集群中关联的所有节点。 如果未为缓存群集指定缓存参数组,则将使用默认的缓存参数组(default.memcached1.4)。 通常,默认参数组包含引擎默认值和针对您正在运行的Cache Cluster节点优化的Amazon ElastiCache系统默认值。 由于Amazon ElastiCache默认情况下会考虑节点类型的内存/计算资源容量为您的缓存集群选择最佳配置参数,因此在大多数用例中不需要更改。 但是,如果您希望缓存集群以自定义配置值运行,则可以简单地创建一个新的缓存参数组,修改所需的参数,并将其用于新的或现有的集群。 如果将自定义参数组应用于正在运行的缓存集群,则更改将不会应用于缓存节点,直到重新启动缓存集群。

Amazon ElastiCache安全组: (Amazon ElastiCache Security Group:)

An Amazon ElastiCache Security Group acts like a firewall, controlling network access to your Cache Cluster. Since IP-range based access control is currently not enabled for Amazon ElastiCache Clusters, All clients to a Cache Cluster must be within the EC2 network and authorized via security groups.  If you want your Web application EC2 instances to access your Cache Cluster, you must explicitly enable access from hosts in their specific EC2 security groups. For example: To allow network access to your Cache Cluster, you first need to create a Cache Security Group and link the desired EC2 security groups (which in turn specify the EC2 instances allowed) to it.

Amazon ElastiCache安全组就像防火墙一样,控制对缓存集群的网络访问。 由于当前未为Amazon ElastiCache集群启用基于IP范围的访问控制,因此,缓存集群的所有客户端都必须位于EC2网络内并通过安全组进行授权。 如果希望Web应用程序EC2实例访问缓存集群,则必须显式启用来自其特定EC2安全组中主机的访问。 例如:要允许网络访问缓存集群,首先需要创建一个缓存安全组,并将所需的EC2安全组(依次指定允许的EC2实例)链接到该组。

Amazon ElastiCache通过EC2上的MemCache提供的功能是什么 (What features Amazon ElastiCache offers over MemCached on EC2)

操作1:修改缓存集群 (Operation 1: Modification of Cache Cluster)

An Amazon ElastiCache cluster can be modified anytime.  Properties like Cache Security group, Cache Parameter group, Maintenance window period, SNS notifications and Auto Minor version upgrade can be modified at cluster level applying to all nodes. Security group changes may take a few minutes to be applied to the cluster. Parameter Group changes will take effect only after you reboot your Cache Nodes.  Instance capacity type of a Cache Node cannot be modified at runtime.

可以随时修改Amazon ElastiCache集群。 可以在集群级别上将“缓存安全性”组,“缓存参数”组,“维护”窗口期,“ SNS通知”和“自动次要版本升级”等属性修改为适用于所有节点的属性。 安全组更改可能需要几分钟才能应用到群集。 仅在重新引导缓存节点后,参数组更改才会生效。 缓存节点的实例容量类型无法在运行时修改。

操作2:重新启动 (Operation 2: Reboot)

Using this option you can reboot a single cache node or the entire cache cluster. The cache nodes will not be available during the cluster reboot operation. In case a single cache node alone is rebooted, other cache nodes are available for processing requests. Reboot operation can be done using the AWS console or API. Reboot is usually performed:

使用此选项,您可以重新引导单个缓存节点或整个缓存群集。 在集群重新引导操作期间,缓存节点将不可用。 万一单独重启单个缓存节点,其他缓存节点可用于处理请求。 可以使用AWS控制台或API完成重启操作。 重新启动通常执行:

  • When a cache node(s) is not responsive

    高速缓存节点无响应时
  • Parameter Group changes applied need to take effect on all the nodes of the cache cluster

    应用的参数组更改需要在缓存集群的所有节点上生效

In our tests, we found reboot of 5 X m1.large cache node type in Amazon EC2 US-EAST region takes around ~140 seconds. This may vary time to time depending upon the cache node type and Amazon EC2 regions in consideration. Because of the ephemeral nature of the Cache, the cache node begin empty (also called “cold”) after reboot operation, and depending on your workload pattern, it may take some time to be re-populated with data (also called “warming up” phase).

在我们的测试中,我们发现Amazon EC2 US-EAST地区中的5 X m1.large缓存节点类型的重新启动需要大约140秒。 这可能会不时变化,具体取决于所考虑的缓存节点类型和Amazon EC2区域。 由于缓存的短暂特性,缓存节点在重新启动操作后开始为空(也称为“冷”),并且根据您的工作负载模式,可能需要一些时间来重新填充数据(也称为“预热”) ”阶段)。

操作3:删除和删除 (Operation 3: Delete and Removal )

You can remove a one or more nodes from a cache cluster or delete the entire cluster. In case only one node is present in the cache cluster, you need to delete the cache cluster itself. Deleting one or more nodes takes ~200 seconds. This may vary time to time depending upon the cache node type and Amazon EC2 regions in consideration. In case a cluster is deleted, you can recreate a cache cluster in the same name at later point of time in the same Amazon EC2 region.

您可以从缓存群集中删除一个或多个节点,也可以删除整个群集。 如果缓存集群中仅存在一个节点,则需要删除缓存集群本身。 删除一个或多个节点大约需要200秒。 这可能会不时变化,具体取决于所考虑的缓存节点类型和Amazon EC2区域。 如果集群被删除,您可以稍后在同一Amazon EC2区域中以相同的名称重新创建缓存集群。

操作4:添加缓存节点 (Operation 4: Addition of Cache Nodes)

Amazon ElastiCache as the name suggests you can automatically/manually add cache nodes to the existing ElastiCache cluster making the whole tier elastic. One or more cache nodes can be added to the existing cache cluster at a time. In our tests, we found adding 5 X m1.large cache node type in Amazon EC2 US-EAST region takes around ~320 seconds. This may vary time to time depending upon the cache node type and Amazon EC2 regions in consideration. While adding new cache nodes in existing cluster, the cache node type should be the same size as the existing node type. You cannot change that size, in case you need different cache node capacity a new cache cluster needs to be created.

顾名思义,Amazon ElastiCache可以自动/手动将缓存节点添加到现有ElastiCache集群,从而使整个层具有弹性。 可以一次将一个或多个缓存节点添加到现有的缓存集群中。 在我们的测试中,我们发现在Amazon EC2 US-EAST地区中添加5 X m1.large缓存节点类型大约需要320秒。 这可能会不时变化,具体取决于所考虑的缓存节点类型和Amazon EC2区域。 在现有群集中添加新的缓存节点时,缓存节点类型的大小应与现有节点类型的大小相同。 如果需要不同的缓存节点容量,则不能更改该大小,需要创建新的缓存群集。

With a normal hashing algorithm, increasing the number of memcached cache nodes can cause many keys to be remapped to different cache node resulting in huge set of cache misses. Imagine you have 10 Amazon ElastiCache Nodes in your cache Cluster, adding an eleventh server may cause ~40%+ of your keys to suddenly point to different servers than normal. This activity may cause cache misses and swamp your backend Database with requests. To minimize this remapping process it is recommended to follow consistent Hashing in your cache clients. Consistent Hashing allows for more stable distribution of keys and minimal remapping when new cache nodes are added. Using this algorithm, adding an eleventh server should cause less than 10% of your keys to be reassigned. This % may vary in production but it is far more efficient in such elastic scenarios compared to normal hash algorithms.  It is also advised to keep cache node ordering and number of cache node entries same in all the client configurations while using consistent Hashing algorithm. Java Applications can use “Ketama library” through Spymemcached library to integrate this algorithm into their applications.  Refer URL to know more about consistent Hashing in memcached.

使用普通的哈希算法,增加memcached缓存节点的数量会导致许多键被重新映射到不同的缓存节点,从而导致大量的缓存未命中。 想象一下,您的缓存集群中有10个Amazon ElastiCache节点,添加第11个服务器可能会导致〜40%+的密钥突然指向与正常服务器不同的服务器。 此活动可能会导致高速缓存未命中,并使后端数据库充满请求。 为了最大程度地减少此重新映射过程,建议在缓存客户端中遵循一致的哈希。 当添加新的缓存节点时,一致的散列可以更稳定地分配键并最小化重新映射。 使用此算法,添加第十一台服务器应导致少于10%的密钥被重新分配。 该百分比可能会因生产而异,但与常规哈希算法相比,在这种弹性情况下它的效率要高得多。 还建议在使用一致的散列算法时,在所有客户端配置中均应保持高速缓存节点的顺序和高速缓存节点条目的数量相同。 Java应用程序可以通过Spymemcached库使用“ Ketama库”来将该算法集成到其应用程序中。 请参阅URL,以了解有关memcached中一致哈希的更多信息。

A sample Pseudo code illustrating SET operation in TEXT-TCP protocol using Java Spymemcached –Ketama Hashing library and Amazon ElastiCache Tier:

示例伪代码示例说明了使用Java Spymemcached –Ketama哈希库和Amazon ElastiCache层的TEXT-TCP协议中的SET操作:

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.*;
import java.util.*;
public class ElastiCacheKetamaTCPSet {
 public void setValue() throws IOException {
 ConnectionFactory connFactory = new DefaultConnectionFactory(
 DefaultConnectionFactory.DEFAULT_OP_QUEUE_LEN,
 DefaultConnectionFactory.DEFAULT_READ_BUFFER_SIZE,
 HashAlgorithm.KETAMA_HASH);
 MemcachedClient memcachedClient = new MemcachedClient(connFactory,AddrUtil.getAddresses("ecache1a.sqjbuo.0001.use1.cache.amazonaws.com:11211"));
 String key = "1000001";
 String value = "1000001-Test value in Consistent Hashing";
 Integer expires = Integer.parseInt("1000");
 try {
 Future<Boolean> result = memcachedClient.set(key, expires, value);
………………..
………………..
 } catch (InterruptedException e) {
 e.printStackTrace();
 } catch (ExecutionException e) {
 e.printStackTrace();
 }
 memcachedClient.shutdown();
 }
}

翻译自: https://www.sitepoint.com/amazon-elasticache-cache-on-steroids/

elasticache

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值