PHP code example of momentohq / momento-php-redis-client
1. Go to this page and download the library: Download momentohq/momento-php-redis-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
momentohq / momento-php-redis-client example snippets
declare(strict_types=1);
use Momento\Auth\CredentialProvider;
use Momento\Cache\CacheClient;
use Momento\Cache\MomentoCacheClient;
use Momento\Config\Configurations\Laptop;
use Momento\Logging\StderrLoggerFactory;
OMENTO_API_KEY");
$configuration = Laptop::latest(new StderrLoggerFactory());
$client = new CacheClient($configuration, $authProvider, $ITEM_DEFAULT_TTL_SECONDS);
$logger = $configuration->getLoggerFactory()->getLogger("ex:");
// Create a Redis client backed by Momento cache client over the cache
$momentoCacheClient = new MomentoCacheClient($client, $CACHE_NAME);
// IMPORTANT: The example assumes that the cache ($CACHE_NAME) is already created.
// To create a cache, you can use the Momento Console (https://console.gomomento.com/) or SDK methods.
// Refer to the documentation (https://docs.momentohq.com/platform/sdks/php/cache) for details.
// Perform operations vs Momento as if using a regular Redis client
$setResult = $momentoCacheClient->set($KEY, $VALUE);
$logger->info("Set result: " . $setResult . "\n");
$getResult = $momentoCacheClient->get($KEY);
$logger->info("Get result: " . $getResult . "\n");