regeda/nest

Nest 是一个基于键的方法调用装饰器

v1.1 2013-04-24 06:58 UTC

This package is not auto-updated.

Last update: 2024-09-23 10:49:22 UTC


README

Nest 是一个基于键的方法调用装饰器。PHP 5.3 的类只包含一个文件。

Build Status

使用方法

定义初始命名空间和客户端

$nest = new Nest('foo', new Redis());
echo $nest; // -> foo

扩展命名空间

$nest = new Nest('foo', new Redis());

echo $nest['bar']; // -> foo:bar
echo $nest['bar']['baz']; // -> foo:bar:baz

调用方法

$redis = new Redis(); // or $memcached = new Memcached()

$user = new Nest('user', $redis);

// getter

foreach ($ids as $id) {
    echo $user[$id]['username']->get(); // makes the proxy to $redis->get('user:$id:username')
}

// setter

$user[$id]['age']->set(18); // $redis->set('user:$id:age', 18)

来源: https://github.com/regeda/php-nest