PHP Classes


Recommend this page to a friend!
  Classes of Payam Naderi  >  Key-Value Storage  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Key-Value Storage
Store and retrieve values on different containers
Author: By
Last change:
Date: 4 years ago
Size: 1,671 bytes


Class file image Download


InMemory Store

// Storage for 'test' Realm.

$s = new InMemoryStore('test');
$s->set('name', 'Payam');
$s->set('family', 'Naderi');

$fullname = $s->getFromKeys(['name', 'family']);
$fullname = StdTravers::of($fullname)
    ->each(function($val, $_ ,$prev) {
        return $prev.= ' '.$val;


FlatFile Store

$s = new FlatFileStore('user_codes');
$user_id = 'd5e110k33f';
$s->set($user_id, '1453');
// Without this syntax storage will save given entity when dispatch shutdown.
$s->save(); // force to save current 

> In Next Calls

values can be retrieved.

$s = new FlatFileStore('user_codes');
if ($s->has('d5e110k33f'))

> Destroy Storage

will destroy storage for given 'user_codes' realm.

$s = new FlatFileStore('user_codes');

> Choose Desired Options

Options In under_score with construct

$s = new FlatFileStore('user_codes', ['dir_path' => __DIR__.'/my_user_codes.dat']);
$s->set('key', 'value');

will map to setter methods

$s = new FlatFileStore('user_codes');
$s->set('key', 'value');

Mongo Store

$client     = \Module\MongoDriver\Actions::Driver()->getClient('master');
$collection = $client->selectCollection('papioniha', '');

$s = new MongoStore('pass_trough', ['collection' => $collection]);

// Traverse All Data

$v = StdTravers::of( $s )
    ->each(function($val, $key ,$prev) {
        if ( is_array($prev) )
            return $prev[$key] = $val;

        return [$key => $val];

For more information send a message to info at phpclasses dot org.