setName('memcache:distributed:set')
->setDescription('Set a value in the distributed memcache')
->addArgument('key', InputArgument::REQUIRED, 'The key to set')
->addArgument('value', InputArgument::REQUIRED, 'The value to set')
->addOption(
'type',
null,
InputOption::VALUE_REQUIRED,
'Value type [string, integer, float, boolean, json, null]',
'string'
);
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$cache = $this->cacheFactory->createDistributed();
$key = $input->getArgument('key');
$value = $input->getArgument('value');
$type = $input->getOption('type');
['value' => $value, 'readable-value' => $readable] = $this->castHelper->castValue($value, $type);
if ($cache->set($key, $value)) {
$output->writeln('Distributed cache key ' . $key . ' set to ' . $readable . '');
return 0;
} else {
$output->writeln('Failed to set cache key ' . $key . '');
return 1;
}
}
}