PHP code example of alksily / memory

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

    

alksily / memory example snippets


Alksily\Memory\Mem::initialize([
    [
        'host'    => 'localhost',
        'port'    => '11211',
        'timeout' => 10,
        // additional can be passed options, server-role and pool name:
        // 'driver' => 'memcache', // or redis
    ]
]);

Alksily\Memory\Mem::set('foo', 'bar');

Alksily\Memory\Mem::get('foo', /* 'default value' */);

// -- or --

Alksily\Memory\Mem::get('foo', function () {
    // some action, e.g. just return string
    return 'baz';
});

// set rows
Alksily\Memory\Mem::setMultiple([
    'cat:0' => 'Kiki',
    'cat:1' => 'Lucky',
    'dog:0' => 'Bucks',
    'cat:2' => 'Simon',
    'dog:1' => 'Eugene',
    'cat:3' => 'Rocky',
], 3600, 'animal');

// get data
$animals = Alksily\Memory\Mem::getMultiple(['cat:0', 'cat:1', 'dog:0', 'cat:2', 'dog:1', 'cat:3']);

// remove data
Alksily\Memory\Mem::deleteMultiple(['cat:0', 'cat:1', 'dog:0', 'cat:2', 'dog:1', 'cat:3']);

// set few rows
Alksily\Memory\Mem::set('cat:0', 'Kiki', 3600, 'animal');
Alksily\Memory\Mem::set('cat:1', 'Lucky', 3600, 'animal');
Alksily\Memory\Mem::set('dog:0', 'Bucks', 3600, 'animal');
Alksily\Memory\Mem::set('cat:2', 'Simon', 3600, 'animal');
Alksily\Memory\Mem::set('dog:1', 'Eugene', 3600, 'animal');
Alksily\Memory\Mem::set('cat:3', 'Rocky', 3600, 'animal');

// get data as array
$animal = Alksily\Memory\Mem::getByTag('animal');

// remove data
Alksily\Memory\Mem::deleteByTag('animal');