

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Menggunakan Penemuan Otomatis
<a name="AutoDiscovery.Using"></a>

Untuk mulai menggunakan Auto Discovery with ElastiCache for Memcached, ikuti langkah-langkah berikut:
+ [Dapatkan Endpoint Konfigurasi](#AutoDiscovery.Using.ConfigEndpoint)
+ [Unduh Klien ElastiCache Cluster](#AutoDiscovery.Using.ClusterClient)
+ [Ubah Program Aplikasi Anda](#AutoDiscovery.Using.ModifyApp)

## Dapatkan Endpoint Konfigurasi
<a name="AutoDiscovery.Using.ConfigEndpoint"></a>

Untuk terhubung ke klaster, program klien harus mengetahui titik akhir konfigurasi klaster. Lihat topik [Menemukan Titik Akhir Cluster (Konsol) (Memcached)](Endpoints.md#Endpoints.Find.Memcached).

Anda juga dapat menggunakan perintah `aws elasticache describe-cache-clusters` dengan parameter `--show-cache-node-info`:

Apa pun metode yang Anda gunakan untuk menemukan titik akhir klaster, titik akhir konfigurasi akan selalu memiliki **.cfg** pada alamatnya.

**Example Menemukan titik akhir menggunakan for AWS CLI ElastiCache**  
Untuk Linux, macOS, atau Unix:  

```
aws elasticache describe-cache-clusters \
    --cache-cluster-id mycluster \
    --show-cache-node-info
```
Untuk Windows:  

```
aws elasticache describe-cache-clusters ^
    --cache-cluster-id mycluster ^
    --show-cache-node-info
```
Operasi ini menghasilkan output seperti yang berikut ini (format JSON):  

```
{
    "CacheClusters": [
        {
            "Engine": "memcached", 
            "CacheNodes": [
                {
                    "CacheNodeId": "0001", 
                    "Endpoint": {
                        "Port": 11211, 
                        "Address": "mycluster.fnjyzo.cfg.0001.use1.cache.amazonaws.com"
                    }, 
                    "CacheNodeStatus": "available", 
                    "ParameterGroupStatus": "in-sync", 
                    "CacheNodeCreateTime": "2016-10-12T21:39:28.001Z", 
                    "CustomerAvailabilityZone": "us-east-1e"
                }, 
                {
                    "CacheNodeId": "0002", 
                    "Endpoint": {
                        "Port": 11211, 
                        "Address": "mycluster.fnjyzo.cfg.0002.use1.cache.amazonaws.com"
                    }, 
                    "CacheNodeStatus": "available", 
                    "ParameterGroupStatus": "in-sync", 
                    "CacheNodeCreateTime": "2016-10-12T21:39:28.001Z", 
                    "CustomerAvailabilityZone": "us-east-1a"
                }
            ], 
            "CacheParameterGroup": {
                "CacheNodeIdsToReboot": [], 
                "CacheParameterGroupName": "default.memcached1.4", 
                "ParameterApplyStatus": "in-sync"
            }, 
            "CacheClusterId": "mycluster", 
            "PreferredAvailabilityZone": "Multiple", 
            "ConfigurationEndpoint": {
                "Port": 11211, 
                "Address": "mycluster.fnjyzo.cfg.use1.cache.amazonaws.com"
            }, 
            "CacheSecurityGroups": [], 
            "CacheClusterCreateTime": "2016-10-12T21:39:28.001Z", 
            "AutoMinorVersionUpgrade": true, 
            "CacheClusterStatus": "available", 
            "NumCacheNodes": 2, 
            "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:", 
            "CacheSubnetGroupName": "default", 
            "EngineVersion": "1.4.24", 
            "PendingModifiedValues": {}, 
            "PreferredMaintenanceWindow": "sat:06:00-sat:07:00", 
            "CacheNodeType": "cache.r3.large"
        }
    ]
}
```

## Unduh Klien ElastiCache Cluster
<a name="AutoDiscovery.Using.ClusterClient"></a>

Untuk memanfaatkan Penemuan Otomatis, program klien harus menggunakan *Klien Klaster ElastiCache*. ElastiCache Cluster Client tersedia untuk Java, PHP, dan .NET dan berisi semua logika yang diperlukan untuk menemukan dan menghubungkan ke semua node cache Anda.

**Untuk mengunduh Klien ElastiCache Cluster**

1. Masuk ke Konsol AWS Manajemen dan buka ElastiCache konsol di [https://console.aws.amazon.com/elasticache/](https://console.aws.amazon.com/elasticache/).

1. Dari ElastiCache konsol, pilih **ElastiCache Cluster Client** lalu pilih **Download**.

Kode sumber untuk Klien ElastiCache Cluster untuk Java tersedia di [https://github.com/amazonwebservices/aws-elasticache-cluster-client- memcached-for-java](https://github.com/amazonwebservices/aws-elasticache-cluster-client-memcached-for-java). Pustaka ini didasarkan pada klien Spymemcached yang populer. Klien ElastiCache Cluster dirilis di bawah Lisensi Perangkat Lunak [https://aws.amazon.com.rproxy.goskope.comAmazon/asl](https://aws.amazon.com/asl). Anda bebas mengubah kode sumber sesuai kebutuhan Anda. Anda bahkan dapat memasukkan kode ke pustaka Memcached sumber terbuka lainnya, atau ke kode klien Anda sendiri.

**catatan**  
Untuk menggunakan ElastiCache Cluster Client untuk PHP, pertama-tama Anda harus menginstalnya di EC2 instans Amazon Anda. Untuk informasi selengkapnya, lihat [Menginstal klien ElastiCache cluster untuk PHP](Appendix.PHPAutoDiscoverySetup.md).  
Untuk klien yang didukung TLS, unduh biner dengan PHP versi 7.4 atau lebih tinggi.  
Untuk menggunakan ElastiCache Cluster Client untuk.NET, pertama-tama Anda harus menginstalnya di EC2 instans Amazon Anda. Untuk informasi selengkapnya, lihat [Menginstal klien ElastiCache cluster untuk.NET](Appendix.DotNETAutoDiscoverySetup.md).

## Ubah Program Aplikasi Anda
<a name="AutoDiscovery.Using.ModifyApp"></a>

Perubahan program aplikasi Anda sehingga menggunakan Penemuan Otomatis. Bagian berikut menunjukkan cara menggunakan ElastiCache Cluster Client untuk Java, PHP, dan .NET. 

**penting**  
Saat menentukan titik akhir konfigurasi klaster, pastikan bahwa titik akhir memiliki ".cfg" di alamatnya, seperti ditunjukkan di sini. Jangan menggunakan CNAME atau titik akhir tanpa ".cfg" dalamnya.   

```
"mycluster.fnjyzo.cfg.use1.cache.amazonaws.com";
```
 Kegagalan untuk secara eksplisit menentukan titik akhir konfigurasi klaster akan mengakibatkan konfigurasi yang dibuat ke simpul tertentu.

# Menggunakan ElastiCache Cluster Client untuk Java
<a name="AutoDiscovery.Using.ModifyApp.Java"></a>

Program di bawah ini menunjukkan cara menggunakan ElastiCache Cluster Client untuk terhubung ke endpoint konfigurasi cluster dan menambahkan item data ke cache. Dengan Penemuan Otomatis, program ini terhubung ke semua simpul dalam klaster tanpa intervensi lebih lanjut.

```
package com.amazon.elasticache;

import java.io.IOException;
import java.net.InetSocketAddress;

// Import the &AWS;-provided library with Auto Discovery support 
import net.spy.memcached.MemcachedClient;  

public class AutoDiscoveryDemo {

    public static void main(String[] args) throws IOException {
            
        String configEndpoint = "mycluster.fnjyzo.cfg.use1.cache.amazonaws.com";
        Integer clusterPort = 11211;

        MemcachedClient client = new MemcachedClient(
                                 new InetSocketAddress(configEndpoint, 
                                                       clusterPort));       
        // The client will connect to the other cache nodes automatically.

        // Store a data item for an hour.  
        // The client will decide which cache host will store this item. 
        client.set("theKey", 3600, "This is the data value");
    }
}
```

# Menggunakan ElastiCache Cluster Client untuk PHP
<a name="AutoDiscovery.Using.ModifyApp.PHP"></a>

Program di bawah ini menunjukkan cara menggunakan ElastiCache Cluster Client untuk terhubung ke endpoint konfigurasi cluster dan menambahkan item data ke cache. Dengan Penemuan Otomatis, program ini akan terhubung ke semua simpul di klaster tanpa intervensi lebih lanjut.

Untuk menggunakan ElastiCache Cluster Client untuk PHP, pertama-tama Anda harus menginstalnya di EC2 instance Amazon Anda. Untuk informasi selengkapnya, lihat [Menginstal klien ElastiCache cluster untuk PHP](Appendix.PHPAutoDiscoverySetup.md)

```
<?php
	
 /**
  * Sample PHP code to show how to integrate with the Amazon ElastiCache
  * Auto Discovery feature.
  */

  /* Configuration endpoint to use to initialize memcached client. 
   * This is only an example. 	*/
  $server_endpoint = "mycluster.fnjyzo.cfg.use1.cache.amazonaws.com";
  
  /* Port for connecting to the ElastiCache cluster. 
   * This is only an example 	*/
  $server_port = 11211;

 /**
  * The following will initialize a Memcached client to utilize the Auto Discovery feature.
  * 
  * By configuring the client with the Dynamic client mode with single endpoint, the
  * client will periodically use the configuration endpoint to retrieve the current cache
  * cluster configuration. This allows scaling the cluster up or down in number of nodes
  * without requiring any changes to the PHP application. 
  *
  * By default the Memcached instances are destroyed at the end of the request. 
  * To create an instance that persists between requests, 
  *    use persistent_id to specify a unique ID for the instance. 
  * All instances created with the same persistent_id will share the same connection. 
  * See [http://php.net/manual/en/memcached.construct.php](http://php.net/manual/en/memcached.construct.php) for more information.
  */
  $dynamic_client = new Memcached('persistent-id');
  $dynamic_client->setOption(Memcached::OPT_CLIENT_MODE, Memcached::DYNAMIC_CLIENT_MODE);
  $dynamic_client->addServer($server_endpoint, $server_port);
  
  /**
  * Store the data for 60 seconds in the cluster. 
  * The client will decide which cache host will store this item.
  */  
  $dynamic_client->set('key', 'value', 60);  


 /**
  * Configuring the client with Static client mode disables the usage of Auto Discovery
  * and the client operates as it did before the introduction of Auto Discovery. 
  * The user can then add a list of server endpoints.
  */
  $static_client = new Memcached('persistent-id');
  $static_client->setOption(Memcached::OPT_CLIENT_MODE, Memcached::STATIC_CLIENT_MODE);
  $static_client->addServer($server_endpoint, $server_port);

 /**
  * Store the data without expiration. 
  * The client will decide which cache host will store this item.
  */  
  $static_client->set('key', 'value');  
  ?>
```

Untuk contoh tentang cara menggunakan Klien ElastiCache Cluster dengan TLS diaktifkan, lihat [Menggunakan enkripsi transit dengan PHP dan Memcached](in-transit-encryption.md#in-transit-encryption-connect-php-mc).

# Menggunakan ElastiCache Cluster Client untuk.NET
<a name="AutoDiscovery.Using.ModifyApp.DotNET"></a>

**catatan**  
Klien klaster ElastiCache .NET telah tidak digunakan lagi per Mei 2022.

Klien.NET untuk ElastiCache adalah open source di [https://github.com/awslabs/elasticache-cluster-config-net](https://github.com/awslabs/elasticache-cluster-config-net).

 Aplikasi .NET biasanya mendapatkan konfigurasi dari file config yang dimilikinya. Berikut ini adalah contoh file config aplikasi.

```
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section 
            name="clusterclient" 
            type="Amazon.ElastiCacheCluster.ClusterConfigSettings, Amazon.ElastiCacheCluster" />
    </configSections>

    <clusterclient>
        <!-- the hostname and port values are from step 1 above -->
        <endpoint hostname="mycluster.fnjyzo.cfg.use1.cache.amazonaws.com" port="11211" />
    </clusterclient>
</configuration>
```

Program C\$1 di bawah ini menunjukkan cara menggunakan Klien ElastiCache Cluster untuk terhubung ke titik akhir konfigurasi cluster dan menambahkan item data ke cache. Dengan Penemuan Otomatis, program ini akan terhubung ke semua simpul di klaster tanpa intervensi lebih lanjut.

```
// *****************
// Sample C# code to show how to integrate with the Amazon ElastiCcache Auto Discovery feature.

using System;

using Amazon.ElastiCacheCluster;

using Enyim.Caching;
using Enyim.Caching.Memcached;

public class DotNetAutoDiscoveryDemo  {

    public static void Main(String[] args)  {
    
        // instantiate a new client.
        ElastiCacheClusterConfig config = new ElastiCacheClusterConfig();
        MemcachedClient memClient = new MemcachedClient(config);
        
        // Store the data for 3600 seconds (1hour) in the cluster. 
        // The client will decide which cache host will store this item.
        memClient.Store(StoreMode.Set, 3600, "This is the data value.");
        
    }  // end Main
    
}  // end class DotNetAutoDiscoverDemo
```