php-awsHow can I use PHP to connect to an Amazon Web Services Elasticache instance?
Connecting to an Amazon Web Services Elasticache instance with PHP is quite simple. The following example code will demonstrate how to do so:
<?php
// Create a connection to the ElastiCache instance
$redis = new Redis();
$redis->connect('example.cache.amazonaws.com', 6379);
// Authenticate with the ElastiCache instance
$redis->auth('password');
// Set a value
$redis->set('key', 'value');
// Get the value
echo $redis->get('key');
?>
This example code will output the following:
value
The code is composed of the following parts:
$redis = new Redis();
- This creates a new Redis object.$redis->connect('example.cache.amazonaws.com', 6379);
- This connects to the ElastiCache instance using the hostname and port provided.$redis->auth('password');
- This authenticates with the ElastiCache instance using the password provided.$redis->set('key', 'value');
- This sets a key/value pair in the ElastiCache instance.echo $redis->get('key');
- This retrieves the value from the ElastiCache instance.
For more information on connecting to an Amazon Web Services Elasticache instance with PHP, please refer to the following links:
More of Php Aws
- How do I use PHP to create a ZIP file on AWS?
- How can I use AWS and Zksync together with PHP?
- How can I use Yum to install PHP on an Amazon EC2 instance?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How can I use AWS PHP SDK without credentials?
- How do I generate an AWS Signature Version 4 with PHP?
- How can I use the AWS API Gateway with PHP?
- How can I use PHP to connect to an Amazon Aurora database?
- How do I determine the version of PHP I am running on AWS?
See more codes...