条条大路通罗马系列—— 使用 Hiredis-cluster 连接 Amazon ElastiCache for Redis 集群

前言

Amazon ElastiCache for Redis 是速度超快的内存数据存储,能够提供亚毫秒级延迟来支持 实时应用程序。适用于 Redis 的 ElastiCache 基于开源 Redis 构建,可与 Redis API 兼容,能够与 Redis 客户端配合工作,并使用开放的 Redis 数据格式来存储数据。适用于 Redis 的 ElastiCache 兼具开源 Redis 的速度、简单性和多功能性与 Amazon 的可管理性、安全性和可扩展性,能够在游戏、广告技术、电子商务、医疗保健、金融服务和物联网领域支持要求最严苛的实时应用程序。

亚马逊云科技开发者社区为开发者们提供全球的开发技术资源。这里有技术文档、开发案例、技术专栏、培训视频、活动与竞赛等。帮助中国开发者对接世界最前沿技术,观点,和项目,并将中国优秀开发者或技术推荐给全球云社区。如果你还没有关注/收藏,看到这里请一定不要匆匆划过,点这里让它成为你的技术宝库!

 

利用 ElastiCache for Redis,客户可以使用多个分区创建和运行托管的 Redis 集群。当遇到以下三种主要场景时,必须扩展 Redis 环境。第一,如果 Redis 数据的总内存大小超出或预计超出单个虚拟机的内存容量。第二,如果应用程序将数据写入 Redis 的写入吞吐量超出单个虚拟机的容量。第三,如果要将数据分布到多个分区中,以便在单个节点遇到任何问题时,对总体 Redis 环境产生的影响都较小。

我们推出了一系列博客,展示了如何在不同语言中使用不同的支持 ElastiCache 集群模式的客户端对 ElastiCache 集群进行连接和操作,前面已经有一篇博客介绍了 “使用 redission 连接 Amazon ElastiCache for redis 集群”, 今天的主题是讨论如何使用 C 语言连接 Elasticache for redis 集群。通过 redis 官网上查询到现有的客户端,C 语言中支持 redis cluster 的主要有 Hiredis-cluster, hiredis-vip 等,C++ 语言中支持 redis cluster 的主要有 redis-plus-plus,xredis 等。本篇博客主要会介绍 Hiredis-cluster 的使用。

2. 搭建测试环境

在此说明下,此次测试在宁夏区域进行,测试的主要内容包括:

  • 在开启 TLS 及 Auth 的 ElastiCache 集群中验证读写和 Failover
  • 在未开启 TLS 及 Auth 的 ElastiCache 集群中验证读写和 Failover,因为对于未开启 TLS 及 Auth 的集群,Client 端的代码实现会有所不同。

2.1. 创建测试环境

创建ElastiCache集群

  1. 首先创建一个开启 TLS 及其 Auth 的3 shards,6节点的ElastiCache 集群,实例类型为 cache.t3.small,版本为5.0.6, 按下文的方式获取 configuration endpoint,此处假设其值为:

具体获取 endpoint 的方式如下:

image.png

查找 Redis(已启用集群模式)集群的 configuration endpoint

  • 登录 Amazon Management Console 并打开 ElastiCache 控制台 (https://console.aws.amazon.com/elasticache/)。
  • 从导航窗格中,选择 Redis。
  • 此时会显示一个列表,其中包含运行任意版本 Redis 的集群。
  • 从集群列表中,选择运行“集群 Redis”的集群左侧的复选框。
  • 此时屏幕会展开,以显示有关选定集群的详细信息。
  • 找到 Configuration endpoint

image.png

2.创建一个关闭 TLS 且无 auth 的3 shards,6节点的 ElastiCache 集群,实例类型为 cache.t3.medium,版本为5.0.6,按上文的方式获取 configuration endpoint,此处假设其值为:

image.png

创建EC2测试客户端

1.在同一个 VPC 内创建一个 EC2并配置好响应 security group,我使用的 EC2是 Ubuntu 18.04,安装的环境是一些 Ubuntu 的参考命令。

2.在 EC2上准备环境, Hiredis-cluster 是基于 hiredis 扩展编写的, 我们环境准备准备的时候也会涉及到 hiredis 部分,

  • C Compiler 安装,这里我使用 GCC,可参考这个 How to install GCC Compiler on Ubuntu 18.04
  • libssl-dev 安装,sudo apt-get install libssl-dev 注意在CMake 之前安装,否则会报错 “Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)”
  • CMake 安装,我使用的是 CMake 编译,CMake 官网提供了安装方式Installing | CMake
  • libevent-dev 安装,sudo apt install libevent-dev, 直接安装可能会报如下错误,解决办法是
CMake Error at /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
 Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Call Stack (most recent call first):
 /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
 /usr/local/share/cmake-3.23/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
 tests/CMakeLists.txt:40 (find_package)
  • hiredis 下载并编译,因为 hiredis-cluster 是基于 hiredis 扩展编写的,所以需要安装并编译 hiredis。 如下命令,因为会用到 SSL,所以我使用 make USE_SSL=1, 可以直接使用 make 替代。
git clone https://github.com/redis/hiredis.git
cd hiredis
make USE_SSL=1
sudo make install
  • hiredis-cluster 环境准备,因为会测试 ssl,所以通过选项指定,Redis
mkdir build; cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_SSL=ON ..
make

3.在上面的步骤完成后,你的环境会是这样的:

hiredis 相关,中会生成 hiredis_ssl lib 文件,在</usr/local/lib/>中 hiredis.a 文件

image.png

image.png

中,hiredis_cluster lib 文件生成

image.png

image.png

2.2 不开启传输中加密(TLS)及 auth 的 ElastiCache 集群测试

加载测试数据

  1. 使用 redis-cli 登录未开启了 TLS 和 auth 的 ElastiCache 集群并通过 cluster nodes 命令获取 slots 在 shards 中的分布,通过 redis-cli 工具连接集群并进行操作的具体方法请见使用 redis-cli 连接到 Redis 集群。

redis-cli -c -h -p

image.png

  1. 分别生成 testka,testb,testc 三个 key,可以通过其 slot 值结合上文各个 shard 上 slot 分布信息,判断出3个 key 恰好分布在 shard1,shard2 和 shard3 上

image.png

C代码

1.以下是写入 ElastiCache 集群的代码, 针对于 Elasticache 三个 shard 上的 test1,test2,test3 三个 key 进行写入,请注意配置的地址为 ElastiCache 集群的 configuration endpoint,另外修改不同的 keyname。

#include "hircluster.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);
    struct timeval timeout = {1, 500000}; // 1.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, "<No TLS and auth ElastiCache configuration endpoint>:<port>");    
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "SET %s %d", "test1", count);
        printf("SET: %d\n", count);
        count++ ;
        if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
        freeReplyObject(reply);
        sleep(1);
    }


    redisClusterFree(cc);
    return 0;
}

2.以下是读取 ElastiCache 集群的代码, 针对于 Elasticache 三个 shard 上的 test1,test2,test3 三个 key 进行读取,请注意配置的地址为 ElastiCache 集群的 configuration endpoint,另外修改不同的 keyname。

#include "hircluster.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);
    struct timeval timeout = {1, 500000}; // 1.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, "<No TLS and auth ElastiCache configuration endpoint>:<port>");    
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "GET %s", "test1");
        if(reply && reply->str) {
                printf("GET: %s\n", reply->str);
        
        }
        freeReplyObject(reply);
    if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
        count++;
        sleep(1);
    }

    redisClusterFree(cc);
    return 0;
}

基本功能测试

1.使用如下命令编译代码:

gcc hiredisc-naw1.c -o hiredisc-naw1 -L./build -lhiredis_cluster /usr/local/lib/libhiredis.a -L~/hiredis -lhiredis_ssl

2.运行程序并监控 ElastiCache 未开启 TLS 及 Auth 集群的 CurrConnections 指标,可以看到负载被均衡地发送到了6个节点上,即 hiredis-cluster 可以完成读写分离和负载均衡的工作:

我的代码在~/hiredis-cluster 路径下面,所以

cd hiredis-cluster/ &&./hiredisc-naw1
cd hiredis-cluster/ &&./hiredisc-naw2
cd hiredis-cluster/ &&./hiredisc-naw3
cd hiredis-cluster/ &&./hiredisc-nar1
cd hiredis-cluster/ &&./hiredisc-nar2
cd hiredis-cluster/ &&./hiredisc-nar3

image.png

2.3. 开启传输中加密(TLS)及 auth 的 ElastiCache 集群测试

Amazon ElastiCache 传输中加密是一项可选功能,它允许您在数据最脆弱时候(从一个位置传输到另一个位置时)提高数据的安全性。由于在终端节点加密和解密数据时需要进行一些处理,因此启用传输中加密会对性能产生一些影响。应对使用和不使用传输中加密的数据进行基准测试,以确定对使用案例的性能影响。 关于 TLS 加密这一块,具体可以参考条条大路通罗马- 使用 redission 连接 Amazon ElastiCache for redis 集群。

加载测试数据

1.使用 redis-cli 登录开启了 TLS 和 auth 的 ElastiCache 集群并通过 cluster nodes 命令获取 slots 在 shards 中的分布,通过 redis-cli 工具连接集群并进行操作的具体方法请见使用 redis-cli 连接到 Redis 集群。

111.png

redis-cli -c -h -p

2.分别生成 testka,testb,testc 三个 key,可以通过其 slot 值结合上文各个 shard 上 slot 分布信息,判断出 3 个 key 恰好分布在 shard1,shard2 和 shard3 上

222.png

C代码

1.以下是写入 ElastiCache 集群的代码, 针对于 Elasticache 三个shard 上的 test1,test2,test3 三个 key 进行写入,请注意配置的地址为 ElastiCache 集群的 configuration endpoint,设置密码,另外修改不同的 keyname。这里需要注意的是 hiredis-cluster 对 SSL 的支持,可以分为两种方式,一种是指定 SSL 证书路径,另一种是指定证书,对于 EC2 访问 ElastiCache 的情况,指定证书路径即可, 具体可参考 hiredis 的文档。

#include "hiredis_cluster/hircluster.h"

#include "hiredis/hiredis_ssl.h"
#include <stdio.h>
#include <stdlib.h>

#define CLUSTER_NODE_TLS ":<Enable TLS and auth ElastiCache configuration endpoint>:<port>"
#define CLUSTER_PASSWORD "<PASSWORD>"

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);

    redisSSLContext *ssl;
    redisSSLContextError ssl_error;

    redisInitOpenSSL();
    ssl = redisCreateSSLContext(NULL, "/etc/ssl/certs", NULL, NULL,
                                NULL, &ssl_error);
    if (!ssl) {
        printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error));
        exit(1);
    }

    struct timeval timeout = {5, 500000}; // 5.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, CLUSTER_NODE_TLS);
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterSetOptionEnableSSL(cc, ssl);
    redisClusterSetOptionPassword(cc, CLUSTER_PASSWORD);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "SET %s %d", "test1", count);
        printf("SET: %d\n", count);
        if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
    count++ ;
        freeReplyObject(reply);
        sleep(1);
    }

    redisClusterFree(cc);
    redisFreeSSLContext(ssl);
    return 0;
}

2.以下是读取 ElastiCache 集群的代码, 针对于 Elasticache 三个shard 上的 test1,test2,test3 三个 key 进行读取,请注意配置的地址为 ElastiCache 集群的 configuration endpoint ,另外修改不同的 keyname。

#include "hircluster.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);
    struct timeval timeout = {1, 500000}; // 1.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, "<No TLS and auth ElastiCache configuration endpoint>:<port>");    
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "GET %s", "test1");
        if(reply && reply->str) {
                printf("GET: %s\n", reply->str);
        
        }
        freeReplyObject(reply);
    if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
        count++;
        sleep(1);
    }

    redisClusterFree(cc);
    return 0;
}

基本功能测试

1.使用如下命令编译代码:

gcc hiredisc-naw1.c -o hiredisc-naw1 -L./build -lhiredis_cluster /usr/local/lib/libhiredis.a -L~/hiredis -lhiredis_ssl

2.运行程序并监控 ElastiCache 未开启 TLS 及 Auth 集群的CurrConnections 指标,可以看到负载被均衡地发送到了6个节点上,即 hiredis-cluster 可以完成读写分离和负载均衡的工作:

我的代码在~/hiredis-cluster 路径下面,所以

cd hiredis-cluster/ &&./hiredisc-naw1
cd hiredis-cluster/ &&./hiredisc-naw2
cd hiredis-cluster/ &&./hiredisc-naw3
cd hiredis-cluster/ &&./hiredisc-nar1
cd hiredis-cluster/ &&./hiredisc-nar2
cd hiredis-cluster/ &&./hiredisc-nar3

image.png

2.3. 开启传输中加密(TLS)及 auth 的 ElastiCache 集群测试

Amazon ElastiCache 传输中加密是一项可选功能,它允许您在数据最脆弱时候(从一个位置传输到另一个位置时)提高数据的安全性。由于在终端节点加密和解密数据时需要进行一些处理,因此启用传输中加密会对性能产生一些影响。应对使用和不使用传输中加密的数据进行基准测试,以确定对使用案例的性能影响。 关于 TLS 加密这一块,具体可以参考条条大路通罗马- 使用 redission 连接 Amazon ElastiCache for redis 集群。

加载测试数据

1.使用 redis-cli 登录开启了 TLS 和 auth 的 ElastiCache 集群并通过 cluster nodes 命令获取 slots 在 shards 中的分布,通过 redis-cli 工具连接集群并进行操作的具体方法请见使用 redis-cli 连接到 Redis 集群。

image.png

redis-cli -c -h -p

2.分别生成 testka,testb,testc 三个 key,可以通过其 slot 值结合上文各个 shard 上 slot 分布信息,判断出 3 个 key 恰好分布在shard1,shard2 和 shard3 上

image.png

C代码

1.以下是写入 ElastiCache 集群的代码, 针对于 Elasticache 三个shard 上的 test1,test2,test3 三个 key 进行写入,请注意配置的地址为 ElastiCache 集群的 configuration endpoint,设置密码,另外修改不同的 keyname。这里需要注意的是 hiredis-cluster 对SSL的支持,可以分为两种方式,一种是指定 SSL 证书路径,另一种是指定证书,对于 EC2 访问 ElastiCache 的情况,指定证书路径即可, 具体可参考 hiredis 的文档。

#include "hiredis_cluster/hircluster.h"

#include "hiredis/hiredis_ssl.h"
#include <stdio.h>
#include <stdlib.h>

#define CLUSTER_NODE_TLS ":<Enable TLS and auth ElastiCache configuration endpoint>:<port>"
#define CLUSTER_PASSWORD "<PASSWORD>"

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);

    redisSSLContext *ssl;
    redisSSLContextError ssl_error;

    redisInitOpenSSL();
    ssl = redisCreateSSLContext(NULL, "/etc/ssl/certs", NULL, NULL,
                                NULL, &ssl_error);
    if (!ssl) {
        printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error));
        exit(1);
    }

    struct timeval timeout = {5, 500000}; // 5.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, CLUSTER_NODE_TLS);
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterSetOptionEnableSSL(cc, ssl);
    redisClusterSetOptionPassword(cc, CLUSTER_PASSWORD);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "SET %s %d", "test1", count);
        printf("SET: %d\n", count);
        if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
    count++ ;
        freeReplyObject(reply);
        sleep(1);
    }

    redisClusterFree(cc);
    redisFreeSSLContext(ssl);
    return 0;
}

2.以下是读取 ElastiCache 集群的代码, 针对于 Elasticache 三个shard 上的 test1,test2,test3 三个 key 进行读取,请注意配置的地址为 ElastiCache 集群的 configuration endpoint ,另外修改不同的 keyname 。

#include "hiredis_cluster/hircluster.h"

#include "hiredis/hiredis_ssl.h"
#include <stdio.h>
#include <stdlib.h>

#define CLUSTER_NODE_TLS "<Enable TLS and auth ElastiCache configuration endpoint>:<port>"
#define CLUSTER_PASSWORD "<PASSWORD>"

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);

    redisSSLContext *ssl;
    redisSSLContextError ssl_error;

    redisInitOpenSSL();
    ssl = redisCreateSSLContext(NULL, "/etc/ssl/certs", NULL, NULL,
                                NULL, &ssl_error);
    if (!ssl) {
        printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error));
        exit(1);
    }

    struct timeval timeout = {5, 500000}; // 5.5s

    redisClusterContext *cc = redisClusterContextInit();
    redisClusterSetOptionAddNodes(cc, CLUSTER_NODE_TLS);
    redisClusterSetOptionConnectTimeout(cc, timeout);
    redisClusterSetOptionRouteUseSlots(cc);
    redisClusterSetOptionEnableSSL(cc, ssl);
    redisClusterSetOptionPassword(cc, CLUSTER_PASSWORD);
    redisClusterConnect2(cc);
    if (cc && cc->err) {
        printf("Error: %s\n", cc->errstr);
        // handle error
        exit(-1);
    }

    int count = 0;
    while(count < 10000){
        redisReply *reply = (redisReply *)redisClusterCommand(cc, "GET %s", "test1");
        if(reply && reply->str) {
        printf("GET: %s\n", reply->str);
        
    }
    freeReplyObject(reply);
if (cc && cc->err) {
                printf("Error: %s\n", cc->errstr);
        }
    count++;
        sleep(1);
    }

    redisClusterFree(cc);
    redisFreeSSLContext(ssl);
    return 0;
}

基本功能测试

1.使用如下命令编译代码:

gcc hiredisc-aw1.c -o hiredisc-aw1 -L./build -lhiredis_cluster /usr/local/lib/libhiredis.a -L~/hiredis -lhiredis_ssl

2.运行程序并监控 ElastiCache 开启 TLS 及 Auth 集群的CurrConnections 指标,可以看到负载被均衡地发送到了 6 个节点上,即 hiredis-cluster 可以完成读写分离和负载均衡的工作:

我的代码在~/hiredis-cluster 路径下面,所以

cd hiredis-cluster/ &&./hiredisc-aw1
cd hiredis-cluster/ &&./hiredisc-aw2
cd hiredis-cluster/ &&./hiredisc-aw3
cd hiredis-cluster/ &&./hiredisc-ar1
cd hiredis-cluster/ &&./hiredisc-ar2
cd hiredis-cluster/ &&./hiredisc-ar3

image.png

三级标题

3.1. 未开启 TLS 及 auth 的 ElastiCache failover 测试

登录 console,对 Shard1 进行 failover,然后观测我们的C程序的输出, 此过程大约持续12s ((观测所得)),

image.png

从 ElastiCache 集群的每个节点的 CurrConnections 指标截图同样可以看出,hiredis-cluster 将读写请求都发送到了 shard1 新的主节点上:

image.png

3.2. 开启 TLS 及 auth 的 ElastiCache failover 测试

登录 console,对 Shard1 进行 failover,然后观测我们的C程序的输出,这个时间大概 10s 左右(观测所得),

image.png

从 ElastiCache 集群的每个节点的 CurrConnections 指标截图同样可以看出, hiredis-cluster 将读写请求都发送到了 shard1 新的主节点上:

image.png

failover 测试中发生问题以及解决方案

在做 failover 的时候发现一个问题,在 failover 过程中,有的时候client 端直接断开链接,有的时候成功,后来经过分析 hiredis 的代码得知需要把 timeout 时间调整下,所以从 1.5s 调整为 5.5s, 注意这个值并不是最佳实践,是根据测试得来的。

4. 结束语

在本博客中,主要使用C语言通过 hiredis-cluster 连接和操作ElastiCache 集群,从简单的 Demo 中我们可以看到 hiredis-cluster 可以很好地支持 ElastiCache 集群开启 TLS 及 auth 等功能,并自动完成读写分离,负载均衡,failover 等工作,有助于我们便捷,高效地使用 ElastiCache。

5.参考

Hiredis-cluster 文档:GitHub - Nordix/hiredis-cluster: C client library for Redis Cluster. This project is used and sponsored by Ericsson. It is a fork of the now unmaintained hiredis-vip.

Hiredis 文档: GitHub - redis/hiredis: Minimalistic C client for Redis >= 1.2

Amazon Elasticache : Amazon ElastiCache for Redis

条条大路通罗马 —— 使用 redisson 连接 Amazon ElastiCache for redis 集群:条条大路通罗马 —— 使用redisson连接Amazon ElastiCache for redis 集群 | 亚马逊AWS官方博客

相关博客

条条大路通罗马 —— 使用 redisson 连接 Amazon ElastiCache for redis 集群

条条大路通罗马 —— 使用 redis-py 访问 Amazon ElastiCache for redis集群

条条大路通罗马 —— 使用 go-redis 连接 Amazon ElastiCache for Redis 集群

本篇作者

image.png

冯秋爽

Amazon 解决方案架构师,负责跨国企业级客户基于 Amazon 的技术架构设计、咨询和设计优化工作。在加入 Amazon 之前曾就职于 IBM 、甲骨文等 IT 企业,积累了丰富的程序开发和数据库的实践经验。

文章来源:https://dev.amazoncloud.cn/column/article/630a21a42ecbae73705ffb40?sc_medium=regulartraffic&amp;sc_campaign=crossplatform&amp;sc_channel=CSDN 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/66966.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【算法篇C++实现】五大常规算法

文章目录 &#x1f680;一、分治法⛳&#xff08;一&#xff09;算法思想⛳&#xff08;二&#xff09;相关代码 &#x1f680;二、动态规划算法⛳&#xff08;一&#xff09;算法思想⛳&#xff08;二&#xff09;相关代码 &#x1f680;三、回溯算法⛳&#xff08;一&#xf…

数据挖掘具体步骤

数据挖掘具体步骤 1、理解业务与数据 2、准备数据 数据清洗&#xff1a; 缺失值处理&#xff1a; 异常值: 数据标准化&#xff1a; 特征选择&#xff1a; 数据采样处理&#xff1a; 3、数据建模 分类问题&#xff1a; 聚类问题&#xff1a; 回归问题 关联分析 集成学习 image B…

区块链学习6-长安链部署:如何创建特定共识节点数和同步节点数的链

正常prepare的时候只支持4 7 13 16个节点个数&#xff0c;想要创建10个节点&#xff0c;其中5个是共识节点&#xff0c;如何实现&#xff1f; 1. 注释掉prepare.sh的这几行&#xff1a; 2. 修改 crytogen的模板文件&#xff1a; 如果是cert模式&#xff1a;chainmaker-crypt…

idea+gradle阅读spring5.2.9源码之源码构建报错解决方案

注意 1、先确保gradle版本和spring、jdk版本对应 本文:gradle:5.6.4/spring 5.2.9/jdk1.8&#xff08;gradle和jdk都要先安装好&#xff0c;gradle还要配置好本地资源文件路径&#xff09; 2、原来项目乱了的话&#xff0c;先重新导入下载的源码项目 3、进入源码所在根目录&…

Redis数据库的下载和安装

目录 第一章、Redis数据库的下载和安装1.1&#xff09;nosql数据库和 Redis 介绍1.2&#xff09;Windows中下载安装Redis数据库1.3&#xff09;Linux中安装Redis数据库1.4&#xff09;Linux中启动redis1.5&#xff09;Linux中关闭redis 第二章、三种Redis客户端连接Redis数据库…

java代码审计9之XXE

文章目录 1、简介2、 java XXE审计函数3、漏洞3.1、正常的业务3.2、有回显的情况3.3、无回显的情况3.4、修复 之前的文章&#xff0c; php代码审计9之XXE 1、简介 XXE&#xff08;XML外部实体注⼊&#xff0c;XML External Entity) &#xff0c;在应⽤程序解析XML输⼊时&…

【Java-16】动态代理的使用方法及原理实现

代理模式&#xff1a;静态代理 目标 了解静态代理模式实现 路径 静态代理概述静态代理案例 静态代理概述 静态代理&#xff1a; 是由程序员创建或工具生成代理类的源码&#xff0c;再编译成为字节码 &#xff08;字节码文件在没有运行java之前就存在了&#xff09; 在编译…

深度学习:使用卷积神经网络CNN实现MNIST手写数字识别

引言 本项目基于pytorch构建了一个深度学习神经网络&#xff0c;网络包含卷积层、池化层、全连接层&#xff0c;通过此网络实现对MINST数据集手写数字的识别&#xff0c;通过本项目代码&#xff0c;从原理上理解手写数字识别的全过程&#xff0c;包括反向传播&#xff0c;梯度…

【第一阶段】kotlin语言的Nothing类型

fun main() {show(60) } //两种写法一样 private fun show(num:Int){when(num){//下面这句话不是注释提示&#xff0c;会终止程序-1->TODO("不符合")in 0..59->println("不及格")in 60..89->println("及格")in 90..100->println(&qu…

桥接模式(C++)

定义 将抽象部分(业务功能)与实现部分(平台实现)分离&#xff0c;使它们都可以独立地变化。 使用场景 由于某些类型的固有的实现逻辑&#xff0c;使得它们具有两个变化的维度&#xff0c;乃至多个纬度的变化。如何应对这种“多维度的变化”?如何利用面向对象技术来使得类型…

idea - 刷新 Git 分支数据 / 命令刷新 Git 分支数据

一、idea - 刷新 Git 分支数据 idea 找到 fetch 选项&#xff0c;重新获取分支数据 二、命令刷新 Git 分支数据 git fetch参考链接 1. 远程Gitlab新建的分支在IDEA里不显示

OSPF工作原理及其配置命令

目录 一、OSPF&#xff08;开放式最短路径优先协议&#xff09;&#xff1a; 作用&#xff1a;防环 弊端&#xff1a; 结构化部署: 更新方式&#xff1a; 二、OSPF的数据包 三、OSPF的状态机 Down Init 2way 条件&#xff1a; Exstart Exchange Loadi…

Pytorch量化之Post Train Static Quantization(训练后静态量化)

使用Pytorch训练出的模型权重为fp32&#xff0c;部署时&#xff0c;为了加快速度&#xff0c;一般会将模型量化至int8。与fp32相比&#xff0c;int8模型的大小为原来的1/4, 速度为2~4倍。 Pytorch支持三种量化方式&#xff1a; 动态量化&#xff08;Dynamic Quantization&…

Android 13 Hotseat定制化修改

一.背景 由于需求是需要自定义修改Hotseat,所以此篇文章是记录如何自定义修改hotseat的,应该可以覆盖大部分场景,修改点有修改hotseat布局方向,hotseat图标数量,hotseat图标大小,hotseat布局位置,hotseat图标禁止形成文件夹,hotseat图标禁止移动到Launcher中,下面开始…

Gpt微信小程序搭建的前后端流程 - 前端小程序部分-2.确定交互所需的后端API(二)

Gpt微信小程序搭建的前后端流程 - 前端小程序部分-2.确定交互所需的后端API(二) 参考微信小程序-小柠AI智能聊天&#xff0c;可自行先体验。 根据上一节的小程序静态页面设计&#xff0c;需要从后端获取数据的主要4个点&#xff1a; 登录流程&#xff1b;获取今日已提问次数&a…

[保研/考研机试] KY102 计算表达式 上海交通大学复试上机题 C++实现

描述 对于一个不存在括号的表达式进行计算 输入描述&#xff1a; 存在多组数据&#xff0c;每组数据一行&#xff0c;表达式不存在空格 输出描述&#xff1a; 输出结果 示例1 输入&#xff1a; 6/233*4输出&#xff1a; 18思路&#xff1a; ①设立运算符和运算数两个…

CSS的引入方式有哪些?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 内联样式&#xff08;Inline Styles&#xff09;⭐ 内部样式表&#xff08;Internal Stylesheet&#xff09;⭐ 外部样式表&#xff08;External Stylesheet&#xff09;⭐ 导入样式表&#xff08;Import Stylesheet&#xff09;⭐ 写在最…

HarmonyOS应用开发者基础认证考试题库

此博文为HarmonyOS应用开发者基础认证考试的最后的大考&#xff0c;要求100分取得90分方可获取证书、现将考试的题库进行分享&#xff0c;希望能帮到大家。但是需要注意的是&#xff0c;题库会不定时的进行题目删减&#xff0c;但是大概的内容是不会进行改变的。真心希望这篇博…

ArcGISPro随机森林自动化调参分类预测模型展示

更改ArcGISPro的python环境变量请参考文章 ArcGISPro中如何使用机器学习脚本_Z_W_H_的博客-CSDN博客 脚本文件如下 点击运行 结果展示 负类预测概率 正类预测概率 二值化概率 文件夹&#xff08;模型验证结果&#xff09; 数据集数据库 ROC曲线 由于个人数据量太少所以…

立即开始使用 3D 图像

一、说明 这个故事介绍了使用这种类型的数据来训练机器学习3D模型。特别是&#xff0c;我们讨论了Kaggle中可用的MNIST数据集的3D版本&#xff0c;以及如何使用Keras训练模型识别3D数字。 3D 数据无处不在。由于我们希望构建AI来与我们的物理世界进行交互&#xff0c;因此使用3…
最新文章