public function testGetValue() { $this->assertEquals('localnat', $this->module->getCurrentConn()); $this->assertInstanceOf('insolita\\redisman\\components\\PhpredisConnection', $this->module->getConnection()); $model = new RedisItem(); $model->setAttributes(['key' => 'tfx_string', 'type' => 'string']); $this->assertTrue($model->validate()); $val = $model->getValue(); $this->assertEquals('somestringval', $val); $model->setAttributes(['key' => 'tfx_list', 'type' => 'list']); $this->assertTrue($model->validate()); $val = $model->getValue(); $this->assertTrue(is_array($val)); $this->assertEquals(['someval1', 'someval2', 'someval3'], $val); $model->setAttributes(['key' => 'tfx_set', 'type' => 'set']); $this->assertTrue($model->validate()); $val = $model->getValue(); $this->assertTrue(is_array($val)); $this->assertTrue(in_array('someval4', $val)); $this->assertTrue(in_array('someval1', $val)); $this->assertTrue(in_array('someval2', $val)); $this->assertTrue(in_array('someval3', $val)); $model->setAttributes(['key' => 'testfxt:3:hash', 'type' => 'hash']); $this->assertTrue($model->validate()); $val = $model->getValue(); $this->assertTrue(is_array($val)); $this->assertEquals(['hashfield1' => 'hashval1', 'hashfield2' => 'hashval2'], $val); $model->setAttributes(['key' => 'tfx_zset', 'type' => 'zset']); $this->assertTrue($model->validate()); $val = $model->getValue(); $this->assertTrue(is_array($val)); $this->assertEquals(['someval2' => 3, 'someval1' => 4, 'someval3' => 8], $val); }
public function testCreate() { $model = new RedisItem(); $model->scenario = 'create'; $model->setAttributes(['key' => 'newstringkey', 'ttl' => 2000, 'formatvalue' => 'h ehfif ierireh ei', 'type' => 'string']); $this->assertTrue($model->validate()); $model->create(); $this->assertEquals(1, $this->module->executeCommand('EXISTS', ['newstringkey'])); $tmodel = RedisItem::find('newstringkey')->findValue(); $this->assertLessThanOrEqual(2000, $tmodel->ttl); $this->assertNotEquals(-1, $tmodel->ttl); }