本文整理汇总了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");