에 대한 ElastiCache 클러스터 클라이언트 사용 PHP - Amazon ElastiCache

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

에 대한 ElastiCache 클러스터 클라이언트 사용 PHP

아래 프로그램은 ElastiCache 클러스터 클라이언트를 사용하여 클러스터 구성 엔드포인트에 연결하고 캐시에 데이터 항목을 추가하는 방법을 보여줍니다. 프로그램은 Auto Discovery를 사용하여 추가 개입 없이 클러스터에 있는 모든 노드에 연결합니다.

ElastiCache 클러스터 클라이언트를 에 사용하려면 PHP먼저 Amazon EC2 인스턴스에 클러스터 클라이언트를 설치해야 합니다. 자세한 내용은 PHP용 ElastiCache 클러스터 클라이언트 설치 단원을 참조하세요.

<?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 cache 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 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'); ?>

TLS 활성화된 에서 ElastiCache 클러스터 클라이언트를 사용하는 방법에 대한 예는 PHP 및 Memcached 에서 전송 중 암호화 사용을 참조하세요.