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)); }
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'); }
public function testCanSetAValue() { $this->storage->set('var', 'value'); $this->assertEquals('value', $this->namespace->var); }
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");