本文整理匯總了PHP中Storage::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP Storage::set方法的具體用法?PHP Storage::set怎麽用?PHP Storage::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Storage
的用法示例。
在下文中一共展示了Storage::set方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSet
public function testSet()
{
$value = 'a string value';
$redis = $this->getMockBuilder('\\Redis')->getMock();
$redis->expects($this->once())->method('set')->with('prefix:key', serialize($value))->willReturn(true);
$storage = new Storage($redis, 'prefix');
$this->assertTrue($storage->set('key', $value));
}
示例2: __construct
public function __construct($config, $classes, $dependants)
{
// Set the config
$this->config = $config;
// Set the default class path
$this->classPath = CORE_BASE . "classes/";
// Core classes
$this->classes = $classes;
// Load our classes
$this->loadClasses();
// Then load our dependants
$this->loadClasses($dependants, $this->classPath . 'dependants/');
// Set our model up
Storage::set('db', $this->objects['database']);
$this->objects['model'] = $this->bind('model');
// Save the model for the controller
Storage::set('objects', $this->objects);
// And go
return $this->bind('controller');
}
示例3: testCanSetAValue
public function testCanSetAValue()
{
$this->storage->set('var', 'value');
$this->assertEquals('value', $this->namespace->var);
}
示例4: set
public function set($key, $value, $expiration)
{
$this->values[$key] = array('value' => $value, 'expires' => time() + $expiration);
}
public function get($key)
{
if (isset($this->values[$key])) {
if ($this->values[$key]['expires'] < time()) {
unset($this->values[$key]);
return null;
}
return $this->values[$key]['value'];
} else {
return null;
}
}
}
$storage = new Storage();
$server->on(Memcached::ON_GET, function ($client_id, $key, &$value, &$flags, &$cas) use($storage) {
echo "Getting key=[{$key}]" . PHP_EOL;
if (($value = $storage->get($key)) != null) {
return Memcached::RESPONSE_SUCCESS;
}
return Memcached::RESPONSE_KEY_ENOENT;
});
$server->on(Memcached::ON_SET, function ($client_id, $key, $value, $flags, $expiration, $cas, &$result_cas) use($storage) {
echo "Setting key=[{$key}] value=[{$value}]" . PHP_EOL;
$storage->set($key, $value, $expiration);
return Memcached::RESPONSE_SUCCESS;
});
$server->run("127.0.0.1:3434");