使用php的aws elasticache - 无法设置键/值对

问题描述 投票:0回答:1

我可以像这样连接到我的弹性集群:

$awsElasticache = new ElastiCacheClient(CredentialProvider::atsDefaultConfigConstructor(false, false));
$clusterResult = $awsElasticache->describeCacheClusters(array('CacheClusterId'=>'my_cluster'));

当我打印$clusterResult时,我得到有关群集的信息,很好。

但是,我如何实际与端点交互以设置键/值对?

我没试这么成功:

$this->mem = new Memcached();
$this->mem->addServer($this->endPoint,11211);
$this->mem->set('myKey','myValue',3600);
$result = $this->mem->get('myKey');
echo $result;

我没有从$result打印出任何东西。我很困惑用于设置和获取键/值对的对象。

php memcached aws-sdk amazon-elasticache
1个回答
1
投票

要在Memcached中设置键/值对,请始终从当前时间延长到期时间。

试试这个

$this->mem = new Memcached();
$this->mem->addServer($this->endPoint,11211);

$expires = Carbon::now()->addMinutes(10);
$this->mem->set('myKey','myValue', $expires);
$result = $this->mem->get('myKey');
echo $result;

NOTE:出于某种原因,Memcached在Carbon时间最佳

请参阅https://artisansweb.net/work-php-datetime-using-carbon/,了解如何在当前项目中设置和使用Carbon

© www.soinside.com 2019 - 2024. All rights reserved.