

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# Verwenden von Auto Discovery
<a name="AutoDiscovery.Using"></a>

Gehen Sie wie folgt vor, um Auto Discovery ElastiCache für Memcached zu verwenden:
+ [Rufen Sie den Konfigurationsendpunkt ab](#AutoDiscovery.Using.ConfigEndpoint)
+ [Laden Sie den ElastiCache Cluster-Client herunter](#AutoDiscovery.Using.ClusterClient)
+ [Ändern Sie Ihr Anwendungsprogramm](#AutoDiscovery.Using.ModifyApp)

## Rufen Sie den Konfigurationsendpunkt ab
<a name="AutoDiscovery.Using.ConfigEndpoint"></a>

Zum Herstellen der Verbindung mit einem Cluster müssen die Client-Programme den Cluster-Konfigurationsendpunkt kennen. Weitere Informationen finden Sie im Thema [Die Endpunkte eines Clusters finden (Konsole) (Memcached)](Endpoints.md#Endpoints.Find.Memcached).

Sie können auch den Befehl `aws elasticache describe-cache-clusters` mit dem Parameter `--show-cache-node-info` verwenden:

Unabhängig von der Methode, mit der Sie die Endpunkte des Clusters suchen, enthält der Konfigurationsendpunkt in seiner Adresse immer **.cfg**.

**Example Finden von Endpunkten mit dem for AWS CLI ElastiCache**  
Für Linux, macOS oder Unix:  

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

```
aws elasticache describe-cache-clusters ^
    --cache-cluster-id mycluster ^
    --show-cache-node-info
```
Dieser Vorgang erzeugt eine Ausgabe ähnlich der folgenden (JSON-Format):  

```
{
    "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"
        }
    ]
}
```

## Laden Sie den ElastiCache Cluster-Client herunter
<a name="AutoDiscovery.Using.ClusterClient"></a>

Um Auto Discovery nutzen zu können, müssen Client-Programme den *ElastiCache-Cluster-Client* verwenden. Der ElastiCache Cluster-Client ist für Java, PHP und .NET verfügbar und enthält die gesamte erforderliche Logik, um all Ihre Cache-Knoten zu erkennen und eine Verbindung zu ihnen herzustellen.

**Um den ElastiCache Cluster-Client herunterzuladen**

1. Melden Sie sich bei der AWS Management Console an und öffnen Sie die ElastiCache Konsole unter [https://console.aws.amazon.com/elasticache/](https://console.aws.amazon.com/elasticache/).

1. Wählen Sie in der ElastiCache Konsole **ElastiCache Cluster Client** und dann **Herunterladen** aus.

Der Quellcode für den ElastiCache Cluster-Client für Java ist unter [https://github.com/amazonwebservices/aws-elasticache-cluster-client-](https://github.com/amazonwebservices/aws-elasticache-cluster-client-memcached-for-java) verfügbarmemcached-for-java. Diese Bibliothek basiert auf dem häufig verwendeten Spymemcached-Client. Der ElastiCache Cluster-Client ist unter der Amazon-Softwarelizenz [https://aws.amazon.com/asl](https://aws.amazon.com/asl) veröffentlicht. Es steht Ihnen frei, den Quellcode nach eigenen Wünschen zu ändern. Sie können den Code sogar in andere Memcached-Open-Source-Bibliotheken oder in Ihren eigenen Client-Code integrieren.

**Anmerkung**  
Um den ElastiCache Cluster Client für PHP verwenden zu können, müssen Sie ihn zunächst auf Ihrer EC2 Amazon-Instance installieren. Weitere Informationen finden Sie unter [Installation des ElastiCache Cluster-Clients für PHP](Appendix.PHPAutoDiscoverySetup.md).  
Für einen von TLS unterstützten Client laden Sie die Binärdatei mit PHP-Version 7.4 oder höher herunter.  
Um den ElastiCache Cluster Client für.NET verwenden zu können, müssen Sie ihn zunächst auf Ihrer EC2 Amazon-Instance installieren. Weitere Informationen finden Sie unter [Installation des ElastiCache Clusterclients für.NET](Appendix.DotNETAutoDiscoverySetup.md).

## Ändern Sie Ihr Anwendungsprogramm
<a name="AutoDiscovery.Using.ModifyApp"></a>

Ändern Sie Ihr Anwendungsprogramm, sodass es Auto Discovery verwendet. In den folgenden Abschnitten wird gezeigt, wie Sie den ElastiCache Cluster-Client für Java, PHP und .NET verwenden. 

**Wichtig**  
Stellen Sie beim Angeben des Cluster-Konfigurationsendpunkts sicher, dass der Endpunkt in seiner Adresse ".cfg" enthält, wie hier dargestellt. Verwenden Sie keinen CNAME oder einen Endpunkt ohne ".cfg" in der Adresse.   

```
"mycluster.fnjyzo.cfg.use1.cache.amazonaws.com";
```
 Wenn Sie den Cluster-Konfigurationsendpunkt nicht explizit angeben, erfolgt die Konfiguration für einen spezifischen Knoten.

# Den ElastiCache Cluster-Client für Java verwenden
<a name="AutoDiscovery.Using.ModifyApp.Java"></a>

Das folgende Programm zeigt, wie Sie den ElastiCache Cluster-Client verwenden, um eine Verbindung zu einem Cluster-Konfigurationsendpunkt herzustellen und dem Cache ein Datenelement hinzuzufügen. Mithilfe von Auto Discovery stellt das Programm eine Verbindung mit allen Knoten im Cluster her, ohne dass ein Eingreifen erforderlich ist.

```
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");
    }
}
```

# Den ElastiCache Cluster-Client für PHP verwenden
<a name="AutoDiscovery.Using.ModifyApp.PHP"></a>

Das folgende Programm zeigt, wie Sie den ElastiCache Cluster-Client verwenden, um eine Verbindung zu einem Cluster-Konfigurationsendpunkt herzustellen und dem Cache ein Datenelement hinzuzufügen. Mithilfe von Auto Discovery stellt das Programm eine Verbindung mit allen Knoten im Cluster her, ohne dass ein Eingreifen erforderlich ist.

Um den ElastiCache Cluster Client für PHP verwenden zu können, müssen Sie ihn zunächst auf Ihrer EC2 Amazon-Instance installieren. Weitere Informationen finden Sie unter [Installation des ElastiCache Cluster-Clients für 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');  
  ?>
```

Ein Beispiel zur Verwendung des ElastiCache Cluster-Clients mit aktiviertem TLS finden Sie unter [Verwenden von In-Transit-Verschlüsselung mit PHP und Memcached](in-transit-encryption.md#in-transit-encryption-connect-php-mc).

# Den ElastiCache Cluster-Client für.NET verwenden
<a name="AutoDiscovery.Using.ModifyApp.DotNET"></a>

**Anmerkung**  
 ElastiCache Der.NET-Clusterclient ist seit Mai 2022 veraltet.

.NET-Client für ElastiCache ist Open Source unter. [https://github.com/awslabs/elasticache-cluster-config-net](https://github.com/awslabs/elasticache-cluster-config-net)

 Die .NET-Anwendungen erhalten ihre Konfigurationen in der Regel von ihrer Config-Datei. Nachfolgend finden Sie ein Beispiel einer Anwendungs-Config-Datei.

```
<?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>
```

Das unten stehende C\$1-Programm zeigt, wie Sie den ElastiCache Cluster-Client verwenden, um eine Verbindung zu einem Clusterkonfigurationsendpunkt herzustellen und dem Cache ein Datenelement hinzuzufügen. Mithilfe von Auto Discovery stellt das Programm eine Verbindung mit allen Knoten im Cluster her, ohne dass ein Eingreifen erforderlich ist.

```
// *****************
// 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
```