1. Go to this page and download the library: Download seregazhuk/react-memcached 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/ */
seregazhuk / react-memcached example snippets
use seregazhuk\React\Memcached\Factory;
$loop = React\EventLoop\Factory::create();
$client = Factory::createClient($loop);
$client->set('example', 'Hello world');
$client->get('example')->then(function ($data) {
echo $data . PHP_EOL; // Hello world
});
// Close the connection when all requests are resolved
$client->end();
$loop->run();
$client
->set('some-key', 'my-data')
->then(function () {
echo "Value was stored" . PHP_EOL;
});
// advanced: with compression and expires in 30 seconds
$client
->set('some-key', 'my-data', MEMCACHE_COMPRESSED, 30)
->then(function () {
echo "Value was stored" . PHP_EOL;
});
$client
->add('name', 'test')
->then(function() {
echo "The value was added" . PHP_EOL;
});
// advanced: with compression and expires in 30 seconds
$client
->add('name', 'test', MEMCACHE_COMPRESSED, 30)
->then(function() {
echo "The value was added" . PHP_EOL;
});
$client
->replace('name', 'test')
->then(function(){
echo "The value was replaced" . PHP_EOL;
});
// advanced
$client
->replace('name', 'test', $flags, $exptime)
->then(function(){
echo "The value was replaced" . PHP_EOL;
});
$client
->delete('name')
->then(function(){
echo "The value was deleted" . PHP_EOL;
});
$client
->incr('var', 2)
->then(
function($data){
echo "New value is: " . $data . PHP_EOL;
},
function(FailedCommandException $e) {
echo "Key not found" . PHP_EOL;
});
$client
->decr('var', 2)
->then(
function($data){
echo "New value is: " . $data . PHP_EOL;
},
function(FailedCommandException $e) {
echo "Key not found" . PHP_EOL;
});
$client
->touch('var', $exp)
->then(
function($data){
echo "The value was toched". PHP_EOL;
},
function(FailedCommandException $e) {
echo "Key not found" . PHP_EOL;
});