public function testRedisKeysWork() { $conn = $this->module->getConnection(); $conn->set('stest1', 'stest1val'); $val = $conn->get('stest1'); Debug::debug($val); $this->assertTrue($val == 'stest1val'); $conn->del('stest1'); $val = $conn->get('stest1'); $this->assertEmpty($val); $conn->executeCommand('RPUSH', ['slist1', 'A']); $conn->rpush('slist1', 'B'); $conn->rpush('slist1', 'C', 'D', 'E'); $val = $conn->lrange('slist1', 0, -1); $this->assertTrue(is_array($val)); $this->assertTrue(count($val) == 5); $this->assertTrue(in_array('B', $val)); $conn->del('slist1'); $vals = ['k1', 'k2', 'k3']; $key = 'slist1'; array_unshift($vals, $key); $conn->executeCommand('RPUSH', $vals); $val = $conn->lrange('slist1', 0, -1); Debug::debug($val); $this->assertEquals($val, ['k1', 'k2', 'k3']); $conn->del('slist1'); $conn->hset('shash1', 'Gr1', 'd1'); $conn->hset('shash1', 'Gr2', 'd2'); $conn->hmset('shash1', 'Gr3', 'd3', 'Gr4', 'd4', 'Gr5', 'd5'); $val = $conn->hgetall('shash1'); Debug::debug($val); $this->assertTrue(in_array('d3', $val)); $val = $conn->hget('shash1', 'Gr3'); $this->assertTrue($val == 'd3'); Debug::debug($val); $conn->del('shash1'); $conn->sadd('setik1', 'Gr1'); $conn->executeCommand('SADD', ['setik1', 'Gr2']); $conn->sadd('setik1', 'Gr3', 'Gr4', 'Gr2'); $conn->executeCommand('SADD', ['setik1', 'Gr6', 'Gr7', 'Gr5']); $val = $conn->smembers('setik1'); Debug::debug($val); $this->assertTrue(is_array($val)); $this->assertTrue(count($val) == 7); $conn->del('setik1'); $conn->zadd('zsetik1', 1, 'Gr1'); $conn->zadd('zsetik1', 4, 'Gr2'); $conn->zadd('zsetik1', 2, 'Gr3', 3, 'Gr4', 1, 'Gr5', 2, 'Gr2'); $val = $conn->zrange('zsetik1', 0, -1, 'withscores'); $conn->del('zsetik1'); Debug::debug($val); $val = $conn->zrange('zaddik', 0, -1, 'withscores'); Debug::debug($val); }
public function testFind() { $this->assertEquals('localnat', $this->module->getCurrentConn()); $this->assertInstanceOf('insolita\\redisman\\components\\PhpredisConnection', $this->module->getConnection()); $res = RedisItem::find('tfx_string'); $this->assertNotEmpty($res); $this->assertEquals($res->value, null); $this->assertEquals($res->formatvalue, null); $this->assertEquals($res->type, 'string'); $this->assertEquals($res->ttl, -1); $res = RedisItem::find('tfx_string')->findValue(); $this->assertNotEmpty($res); $this->assertEquals(13, $res->size); $this->assertEquals($res->value, 'somestringval'); $this->assertEquals($res->formatvalue, 'somestringval'); $res = RedisItem::find('tfx_list')->findValue(); Debug::debug($res->getValue()); Debug::debug($res->getAttributes()); $this->assertNotEmpty($res); $this->assertEquals(3, $res->size); $this->assertEquals($res->value, ['someval1', 'someval2', 'someval3']); $this->assertEquals($res->formatvalue, "someval1\r\nsomeval2\r\nsomeval3"); $res = RedisItem::find('tfx_set')->findValue(); $this->assertNotEmpty($res); Debug::debug($res->getValue()); Debug::debug($res->getAttributes()); $this->assertEquals(4, $res->size); $this->assertTrue(in_array('someval4', $res->value)); $this->assertTrue(in_array('someval1', $res->value)); $this->assertEquals($res->formatvalue, implode("\r\n", $res->value)); $res = RedisItem::find('tfx_hash')->findValue(); Debug::debug($res->getValue()); Debug::debug($res->getAttributes()); $this->assertNotEmpty($res); $this->assertEquals(1, $res->size); $this->assertEquals(['hashfield' => 'hashval'], $res->value); $this->assertAttributeInstanceOf('\\yii\\data\\ArrayDataProvider', 'formatvalue', $res); $res = RedisItem::find('tfx_zset')->findValue(); Debug::debug($res->getValue()); Debug::debug($res->getAttributes()); $this->assertNotEmpty($res); $this->assertEquals(3, $res->size); $this->assertEquals(['someval2' => 3, 'someval1' => 4, 'someval3' => 8], $res->value); $this->assertAttributeInstanceOf('\\yii\\data\\ArrayDataProvider', 'formatvalue', $res); $this->setExpectedException('yii\\web\\NotFoundHttpException'); $res = RedisItem::find('iugigigi giu')->findValue(); }
public function testGetValue() { $this->assertEquals('local', $this->module->getCurrentConn()); $this->assertNotInstanceOf('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 = new RedisItem(); $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 = new RedisItem(); $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 = new RedisItem(); $model->setAttributes(['key' => 'testfxt:3:hash']); $this->assertTrue($model->validate()); $val = $model->getValue(); Debug::debug($model->getAttributes()); Debug::debug($val); Debug::debug($model->findValue()->getAttributes()); Debug::debug($this->module->executeCommand('HGETALL', ['testfxt:3:hash'])); $this->assertTrue(is_array($val)); $this->assertEquals($this->module->executeCommand('HGETALL', ['testfxt:3:hash']), $val); $model = new RedisItem(); $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); }