PHP code example of qmegas / memcache-search

1. Go to this page and download the library: Download qmegas/memcache-search 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/ */

    

qmegas / memcache-search example snippets




$search = new \Qmegas\MemcacheSearch();
$search->addServer('127.0.0.1', 11211);

//Inline search in key name
$find = new \Qmegas\Finder\Inline('test');
foreach ($search->search($find) as $item) {
	echo "Key: {$item->getKey()} expires ".($item->getExpiration() === -1 ? 'NEVER' : 'on '.date('d/m/Y H:m:i', $item->getExpiration()))."\n";
}

//Inline search in key name - method 2
foreach ($search->search('test') as $item) {
	...
}

//Searching for non expiring items
$find = new \Qmegas\Finder\ExpiresNever();
foreach ($search->search($find) as $item) {
	...
}

//Searching in name by using regular expression
$find = new \Qmegas\Finder\RegExp('/Test([0-9]*)/i');
foreach ($search->search($find) as $item) {
	...
}

//Custom search logic
foreach ($search->search(function(\Qmegas\MemcacheItem $item): bool {
	//Your logic is here
}) as $item) {
	...
}