1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Tioncico
- * Date: 2019/9/24 0024
- * Time: 16:16
- */
- namespace Test;
- use EasySwoole\Redis\Config\RedisConfig;
- use EasySwoole\Redis\Exception\RedisException;
- use EasySwoole\Redis\Redis;
- use PHPUnit\Framework\TestCase;
- use Swoole\Coroutine;
- class RedisTest extends TestCase
- {
- /**
- * @var $redis Redis
- */
- protected $redis;
- /**
- * @var $redisPHPSerialize Redis
- */
- protected $redisPHPSerialize;
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $this->redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- $this->redisPHPSerialize = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH,
- 'serialize' => RedisConfig::SERIALIZE_PHP
- ]));
- $this->redis->connect();
- $this->redisPHPSerialize->connect();
- //测试原始rawCommand
- $redis = $this->redis;
- $redis->flushAll();
- $data = $redis->rawCommand(['set','a','1']);
- $this->assertEquals('OK',$data);
- $data = $redis->rawCommand(['get','a']);
- $this->assertEquals('1',$data);
- $redis->del('a');
- }
- function testConnect()
- {
- $this->assertTrue($this->redis->connect());
- }
- public function testAuth()
- {
- if (!empty(REDIS_AUTH)) {
- $this->assertTrue($this->redis->auth(REDIS_AUTH));
- }
- $this->assertTrue(true);
- }
- /**
- * key值操作测试
- * testKey
- * @author Tioncico
- * Time: 10:02
- */
- function testKey()
- {
- $redis = $this->redis;
- $key = 'test123213Key';
- $redis->select(0);
- $redis->flushAll();
- $redis->set($key, 123);
- $data = $redis->dump($key);
- $this->assertTrue(!!$data);
- $data = $redis->dump($key . 'x');
- $this->assertNull($data);
- $data = $this->redis->exists($key);
- $this->assertEquals(1, $data);
- $data = $this->redis->expire($key, 1);
- $this->assertEquals(1, $data);
- Coroutine::sleep(2);
- $this->assertEquals(0, $this->redis->exists($key));
- $redis->set($key, 123);
- $data = $this->redis->pExpire($key, 1000);
- $this->assertEquals(1, $data);
- $this->assertEquals(123, $this->redis->get($key));
- Coroutine::sleep(2);
- $this->assertEquals(0, $this->redis->pExpire($key));
- $redis->expireAt($key, 1 * 100);
- Coroutine::sleep(0.1);
- $this->assertEquals(0, $this->redis->exists($key));
- $redis->set($key, 123);
- $data = $redis->keys("{$key}");
- $this->assertEquals($key, $data[0]);
- $redis->select(1);
- $redis->del($key);
- $redis->select(0);
- $data = $redis->move($key, 1);
- $this->assertEquals(1, $data);
- $data = $redis->exists($key);
- $this->assertEquals(0, $data);
- $redis->select(0);
- $redis->set($key, 123);
- $data = $redis->expire($key, 1);
- $this->assertEquals(1, $data);
- $data = $redis->persist($key);
- $this->assertEquals(1, $data);
- $redis->expire($key, 1);
- $data = $redis->pTTL($key);
- $this->assertLessThanOrEqual(1000, $data);
- $data = $redis->ttl($key);
- $this->assertLessThanOrEqual(1, $data);
- $data = $redis->randomKey();
- $this->assertTrue(!!$data);
- $data = $redis->rename($key, $key . 'new');
- $this->assertTrue($data);
- $redis->set($key.'old',1);
- $data = $redis->renameNx($key.'old', $key . 'new');
- $this->assertEquals(0, $data);
- $redis->renameNx($key . 'new', $key);
- $data = $redis->renameNx($key, $key . 'new');
- $this->assertEquals(1, $data);
- $data = $redis->type($key);
- $this->assertEquals('none', $data);
- $data = $redis->type($key . 'new');
- $this->assertEquals('string', $data);
- //del单元测试新增
- $keyArr = ['a1','a2','a3','a4'];
- $valueArr = ['a1','a2','a3','a4'];
- $redis->mSet([
- $keyArr[0]=>$valueArr[0],
- $keyArr[1]=>$valueArr[1],
- $keyArr[2]=>$valueArr[2],
- $keyArr[3]=>$valueArr[3],
- ]);
- $data = $redis->del($keyArr[0]);
- $this->assertEquals(1,$data);
- $data = $redis->del($keyArr[1],$keyArr[2],$keyArr[3]);
- $this->assertEquals(3,$data);
- $redis->mSet([
- $keyArr[0]=>$valueArr[0],
- $keyArr[1]=>$valueArr[1],
- $keyArr[2]=>$valueArr[2],
- $keyArr[3]=>$valueArr[3],
- ]);
- $data = $redis->del([$keyArr[1],$keyArr[2],$keyArr[3]]);
- $this->assertEquals(3,$data);
- //unlink命令新增
- $keyArr = ['a1','a2','a3','a4'];
- $valueArr = ['a1','a2','a3','a4'];
- $redis->mSet([
- $keyArr[0]=>$valueArr[0],
- $keyArr[1]=>$valueArr[1],
- $keyArr[2]=>$valueArr[2],
- $keyArr[3]=>$valueArr[3],
- ]);
- $data = $redis->unlink($keyArr[0]);
- $this->assertEquals(1,$data);
- $data = $redis->unlink($keyArr[0].'test');
- $this->assertEquals(0,$data);
- $data = $redis->unlink($keyArr[1],$keyArr[2],$keyArr[3]);
- $this->assertEquals(3,$data);
- $redis->mSet([
- $keyArr[0]=>$valueArr[0],
- $keyArr[1]=>$valueArr[1],
- $keyArr[2]=>$valueArr[2],
- $keyArr[3]=>$valueArr[3],
- ]);
- $data = $redis->unlink([$keyArr[1],$keyArr[2],$keyArr[3]]);
- $this->assertEquals(3,$data);
- }
- /**
- * 字符串单元测试
- * testString
- * @author tioncico
- * Time: 下午9:41
- */
- function testString()
- {
- $redis = $this->redis;
- $key = 'test';
- $value = 1;
- $data = $redis->del($key);
- $this->assertNotFalse($data);
- $data = $redis->set($key, $value);
- $this->assertTrue($data);
- $redis->set($key, $value);
- $data = $redis->get($key);
- $this->assertEquals($data, $value);
- //set的其他作用测试(超时作用)
- $keyTTL=$key.'ttl';
- $redis->set($keyTTL,$value,20);
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $redis->set($keyTTL,$value,['EX'=>20]);
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $redis->set($keyTTL,$value,['PX'=>20000]);
- $this->assertGreaterThan(18000,$redis->pTTL($keyTTL));
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- //set的其他作用测试(存在以及不存在时候设置)
- $keyExist = $key.'exist';
- $redis->del($keyExist);
- $data = $redis->set($keyExist,'1','XX');
- $this->assertNull($data);
- $data = $redis->set($keyExist,'1','NX');
- $this->assertTrue($data);
- $this->assertEquals('1',$redis->get($keyExist));
- $data = $redis->set($keyExist,'1','NX');
- $this->assertNull($data);
- $data = $redis->set($keyExist,'2','XX');
- $this->assertTrue($data);
- $this->assertEquals('2',$redis->get($keyExist));
- //set组合测试
- $data = $redis->set($keyExist,'3',['XX','EX'=>10]);
- $this->assertTrue($data);
- $this->assertEquals('3',$redis->get($keyExist));
- $this->assertGreaterThan(8,$redis->ttl($keyTTL));
- $data = $redis->set($keyExist,'3',['NX','EX'=>10]);
- $this->assertNull($data);
- $redis->del($keyExist);;
- $redis->set($keyExist,'4',['NX','EX'=>20]);
- $this->assertEquals('4',$redis->get($keyExist));
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $data = $redis->exists($key);
- $this->assertEquals(1, $data);
- $data = $redis->set($key, $value);
- $this->assertTrue($data);
- $value += 1;
- $data = $redis->incr($key);
- $this->assertEquals($value, $data);
- $value += 10;
- $data = $redis->incrBy($key, 10);
- $this->assertEquals($value, $data);
- $value -= 1;
- $data = $redis->decr($key);
- $this->assertEquals($value, $data);
- $value -= 10;
- $data = $redis->decrBy($key, 10);
- $this->assertEquals($value, $data);
- $key = 'stringTest';
- $value = 'tioncico';
- $redis->set($key, $value);
- $data = $redis->getRange($key, 1, 2);
- $this->assertEquals('io', $data);
- $data = $redis->getSet($key, $value . 'a');
- $this->assertEquals($data, $value);
- $redis->set($key, $value);
- $bitKey = 'testBit';
- $bitValue = 10000;
- $redis->set($bitKey, $bitValue);
- $data = $redis->setBit($bitKey, 1, 0);
- $this->assertEquals(0, $data);
- $data = $redis->getBit($key, 1);
- $this->assertEquals(1, $data);
- $field = [
- 'stringField1',
- 'stringField2',
- 'stringField3',
- 'stringField4',
- 'stringField5',
- ];
- $value = [
- 1,
- 2,
- 3,
- 4,
- 5,
- ];
- $data = $redis->mSet([
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- "{$field[2]}" => $value[2],
- "{$field[3]}" => $value[3],
- "{$field[4]}" => $value[4],
- ]);
- $this->assertTrue($data);
- $data = $redis->mGet([$field[3], $field[2], $field[1]]);
- $this->assertEquals([$value[3], $value[2], $value[1]], $data);
- $data = $redis->setEx($key, 2, $value[0] . $value[0]);
- $this->assertTrue($data);
- $this->assertEquals($value[0] . $value[0], $redis->get($key));
- $data = $redis->pSetEx($key, 2, $value[0]);
- $this->assertTrue($data);
- $this->assertEquals($value[0], $redis->get($key));
- $redis->del($key);
- $data = $redis->setNx($key, 1);
- $this->assertEquals(1, $data);
- $redis->del($field[0]);
- $data = $redis->mSetNx([
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- ]);
- $this->assertEquals(0, $data);
- $this->assertEquals($value[1], $redis->get($field[1]));
- $redis->del($field[1]);
- $data = $redis->mSetNx([
- "{$field[0]}" => $value[0] + 1,
- "{$field[1]}" => $value[1] + 1,
- ]);
- $this->assertEquals(1, $data);
- $this->assertEquals($value[0] + 1, $redis->get($field[0]));
- $data = $redis->setRange($field[0], 1, 1);
- $this->assertEquals(2, $data);
- $this->assertEquals('2' . $value[0], $redis->get($field[0]));
- $data = $redis->strLen($field[0]);
- $this->assertEquals(2, $data);
- $redis->set($key, 1);
- $data = $redis->incrByFloat($key, 0.1);
- $this->assertEquals(1.1, $data);
- $data = $redis->appEnd($field[0], '1');
- $this->assertEquals($redis->strLen($field[0]), $data);
- $this->assertEquals('2' . $value[0] . '1', $redis->get($field[0]));
- //迭代测试
- $cursor = 0;
- $redis->flushAll();
- $redis->set('xxxa', '仙士可');
- $redis->set('xxxb', '仙士可');
- $redis->set('xxxc', '仙士可');
- $redis->set('xxxd', '仙士可');
- $data = [];
- do {
- $keys = $redis->scan($cursor, 'xxx*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(4, count($data));
- }
- /**
- * 序列化字符串单元测试
- * testString
- * @author tioncico
- * Time: 下午9:41
- */
- function testStringSerialize()
- {
- $redis = $this->redisPHPSerialize;
- $key = 'test';
- $value = 1;
- $data = $redis->del($key);
- $this->assertNotFalse($data);
- $data = $redis->set($key, $value);
- $this->assertTrue($data);
- $redis->set($key, $value);
- $data = $redis->get($key);
- $this->assertEquals($data, $value);
- //set的其他作用测试(超时作用)
- $keyTTL=$key.'ttl';
- $redis->set($keyTTL,$value,20);
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $redis->set($keyTTL,$value,['EX'=>20]);
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $redis->set($keyTTL,$value,['PX'=>20000]);
- $this->assertGreaterThan(18000,$redis->pTTL($keyTTL));
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- //set的其他作用测试(存在以及不存在时候设置)
- $keyExist = $key.'exist';
- $redis->del($keyExist);
- $data = $redis->set($keyExist,'1','XX');
- $this->assertNull($data);
- $data = $redis->set($keyExist,'1','NX');
- $this->assertTrue($data);
- $this->assertEquals('1',$redis->get($keyExist));
- $data = $redis->set($keyExist,'1','NX');
- $this->assertNull($data);
- $data = $redis->set($keyExist,'2','XX');
- $this->assertTrue($data);
- $this->assertEquals('2',$redis->get($keyExist));
- //set组合测试
- $data = $redis->set($keyExist,'3',['XX','EX'=>10]);
- $this->assertTrue($data);
- $this->assertEquals('3',$redis->get($keyExist));
- $this->assertGreaterThan(8,$redis->ttl($keyTTL));
- $data = $redis->set($keyExist,'3',['NX','EX'=>10]);
- $this->assertNull($data);
- $redis->del($keyExist);;
- $redis->set($keyExist,'4',['NX','EX'=>20]);
- $this->assertEquals('4',$redis->get($keyExist));
- $this->assertGreaterThan(18,$redis->ttl($keyTTL));
- $data = $redis->get($key);
- $this->assertEquals($data, $value);
- $data = $redis->exists($key);
- $this->assertEquals(1, $data);
- $key = 'stringTest';
- $value = 'tioncico';
- $redis->set($key, $value);
- $data = $redis->getSet($key, $value . 'a');
- $this->assertEquals($data, $value);
- $redis->set($key, $value);
- $field = [
- 'stringField1',
- 'stringField2',
- 'stringField3',
- 'stringField4',
- 'stringField5',
- ];
- $value = [
- 1,
- 2,
- 3,
- 4,
- 5,
- ];
- $data = $redis->mSet([
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- "{$field[2]}" => $value[2],
- "{$field[3]}" => $value[3],
- "{$field[4]}" => $value[4],
- ]);
- $this->assertTrue($data);
- $data = $redis->mGet([$field[3], $field[2], $field[1]]);
- $this->assertEquals([$value[3], $value[2], $value[1]], $data);
- $data = $redis->setEx($key, 2, $value[0] . $value[0]);
- $this->assertTrue($data);
- $this->assertEquals($value[0] . $value[0], $redis->get($key));
- $data = $redis->pSetEx($key, 2, $value[0]);
- $this->assertTrue($data);
- $this->assertEquals($value[0], $redis->get($key));
- $redis->del($key);
- $data = $redis->setNx($key, 1);
- $this->assertEquals(1, $data);
- $this->assertEquals(1, $redis->get($key));
- $redis->del($field[0]);
- $data = $redis->mSetNx([
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- ]);
- $this->assertEquals(0, $data);
- $this->assertEquals($value[1], $redis->get($field[1]));
- $redis->del($field[1]);
- $data = $redis->mSetNx([
- "{$field[0]}" => $value[0] + 1,
- "{$field[1]}" => $value[1] + 1,
- ]);
- $this->assertEquals(1, $data);
- $this->assertEquals($value[0] + 1, $redis->get($field[0]));
- //迭代测试
- $cursor = 0;
- $redis->flushAll();
- $redis->set('xxxa', '仙士可');
- $redis->set('xxxb', '仙士可');
- $redis->set('xxxc', '仙士可');
- $redis->set('xxxd', '仙士可');
- $data = [];
- do {
- $keys = $redis->scan($cursor, 'xxx*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(4, count($data));
- $this->assertTrue(in_array('xxxa', $data));
- }
- /**
- * testHash
- * @author Tioncico
- * Time: 11:54
- */
- function testHash()
- {
- $key = 'hKey';
- $field = [
- 'hField1',
- 'hField2',
- 'hField3',
- 'hField4',
- 'hField5',
- ];
- $value = [
- 1,
- 2,
- 3,
- 4,
- 5,
- ];
- $redis = $this->redis;
- $redis->del($key);
- $data = $redis->hSet($key, $field[0], $value[0]);
- $this->assertNotFalse($data);
- $data = $redis->hGet($key, $field[0]);
- $this->assertEquals($data, $value[0]);
- $data = $redis->hExists($key, $field[0]);
- $this->assertEquals(1, $data);
- $data = $redis->hDel($key, $field[0]);
- $this->assertEquals(1, $data, $redis->getErrorMsg());
- $data = $redis->hExists($key, $field[0]);
- $this->assertEquals(0, $data);
- $data = $redis->hMSet($key, [
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- "{$field[2]}" => $value[2],
- "{$field[3]}" => $value[3],
- "{$field[4]}" => $value[4],
- ]);
- $this->assertTrue($data);
- $data = $redis->hValS($key);
- sort($data);
- $this->assertEquals($value, $data);
- $data = $redis->hGetAll($key);
- $keyTmp = array_keys($data);
- sort($keyTmp);
- $this->assertEquals($field, $keyTmp);
- $valueTmp = array_values($data);
- sort($valueTmp);
- $this->assertEquals($value, $valueTmp);
- $this->assertEquals($value, [
- $data[$field[0]],
- $data[$field[1]],
- $data[$field[2]],
- $data[$field[3]],
- $data[$field[4]],
- ]);
- $data = $redis->hKeys($key);
- sort($data);
- $this->assertEquals($field, $data);
- $data = $redis->hLen($key);
- $this->assertEquals(count($field), $data);
- $data = $redis->hMGet($key, [$field[0], $field[1], $field[2]]);
- $this->assertEquals([$field[0]=>1, $field[1]=>2, $field[2]=>3], $data);
- $data = $redis->hIncrBy($key, $field[4], 1);
- $this->assertEquals($value[4] + 1, $data);
- $data = $redis->hIncrByFloat($key, $field[1], 1.1);
- $this->assertEquals($value[1] + 1.1, $data);
- $data = $redis->hSetNx($key, $field[0], 1);
- $this->assertEquals(0, $data);
- $data = $redis->hSetNx($key, $field[0] . 'a', 1);
- $this->assertEquals(1, $data);
- $this->assertEquals(1, $redis->hGet($key, $field[0] . 'a'));
- $cursor = 0;
- $redis->del('a');
- $redis->hMSet('a', [
- 'a' => 'tioncico',
- 'b' => 'tioncico',
- 'c' => 'tioncico',
- 'd' => 'tioncico',
- 'e' => 'tioncico',
- 'f' => 'tioncico',
- 'g' => 'tioncico',
- 'h' => 'tioncico',
- ]);
- $data = [];
- do {
- $keys = $redis->hScan('a', $cursor);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(8, count($data));
- }
- /**
- * testHash序列化测试
- * @author Tioncico
- * Time: 11:54
- */
- function testHashSerialize()
- {
- $key = 'hKey';
- $field = [
- 'hField1',
- 'hField2',
- 'hField3',
- 'hField4',
- 'hField5',
- ];
- $value = [
- 1,
- 2,
- 3,
- 4,
- 5,
- ];
- $redis = $this->redisPHPSerialize;
- $redis->del($key);
- $data = $redis->hSet($key, $field[0], $value[0]);
- $this->assertNotFalse($data);
- $data = $redis->hGet($key, $field[0]);
- $this->assertEquals($data, $value[0]);
- $data = $redis->hExists($key, $field[0]);
- $this->assertEquals(1, $data);
- $data = $redis->hDel($key, $field[0]);
- $this->assertEquals(1, $data, $redis->getErrorMsg());
- $data = $redis->hExists($key, $field[0]);
- $this->assertEquals(0, $data);
- $data = $redis->hMSet($key, [
- "{$field[0]}" => $value[0],
- "{$field[1]}" => $value[1],
- "{$field[2]}" => $value[2],
- "{$field[3]}" => $value[3],
- "{$field[4]}" => $value[4],
- ]);
- $this->assertTrue($data);
- $data = $redis->hValS($key);
- sort($data);
- $this->assertEquals($value, $data);
- $data = $redis->hGetAll($key);
- $keyTmp = array_keys($data);
- sort($keyTmp);
- $this->assertEquals($field, $keyTmp);
- $valueTmp = array_values($data);
- sort($valueTmp);
- $this->assertEquals($value, $valueTmp);
- $this->assertEquals($value, [
- $data[$field[0]],
- $data[$field[1]],
- $data[$field[2]],
- $data[$field[3]],
- $data[$field[4]],
- ]);
- $data = $redis->hKeys($key);
- sort($data);
- $this->assertEquals($field, $data);
- $data = $redis->hLen($key);
- $this->assertEquals(count($field), $data);
- $data = $redis->hMGet($key, [$field[0], $field[1], $field[2]]);
- $this->assertEquals([$field[0]=>1, $field[1]=>2, $field[2]=>3], $data);
- $data = $redis->hSetNx($key, $field[0], 1);
- $this->assertEquals(0, $data);
- $data = $redis->hSetNx($key, $field[0] . 'a', 1);
- $this->assertEquals(1, $data);
- $this->assertEquals(1, $redis->hGet($key, $field[0] . 'a'));
- $cursor = 0;
- $redis->del('a');
- $redis->hMSet('a', [
- 'a' => 'tioncico',
- 'b' => 'tioncico',
- 'c' => 'tioncico',
- 'd' => 'tioncico',
- 'e' => 'tioncico',
- 'f' => 'tioncico',
- 'g' => 'tioncico',
- 'h' => 'tioncico',
- ]);
- $data = [];
- do {
- $keys = $redis->hScan('a', $cursor);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(8, count($data));
- $this->assertEquals('tioncico', $data['a']);
- }
- /**
- * testList
- * @author tioncico
- * Time: 下午8:17
- */
- function testList()
- {
- $redis = $this->redis;
- $key = [
- 'listKey1',
- 'listKey2',
- 'listKey3',
- ];
- $value = [
- 'a', 'b', 'c', 'd'
- ];
- $redis->flushAll();
- //测试null的时候
- $data = $redis->bLPop([$key[0], $key[1]], 1);
- $this->assertNull($data);
- $data = $redis->lPush($key[0], $value[0], $value[1]);
- $this->assertEquals(2, $data);
- //测试null的时候
- $data = $redis->bLPop([$key[1]], 1);
- $this->assertNull($data);
- $data = $redis->bRPop([$key[1]], 1);
- $this->assertNull($data);
- $data = $redis->bLPop([$key[0], $key[1]], 1);
- $this->assertTrue(!!$data);
- $data = $redis->bRPop([$key[0], $key[1]], 1);
- $this->assertTrue(!!$data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->bRPopLPush($key[0], $key[1], 1);
- $this->assertEquals($value[0], $data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->rPopLPush($key[0], $key[1]);
- $this->assertEquals($value[0], $data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->lIndex($key[0], 1);
- $this->assertEquals($value[0], $data);
- $data = $redis->lLen($key[0]);
- $this->assertEquals(2, $data);
- $data = $redis->lInsert($key[0], true, 'b', 'c');
- $this->assertEquals($redis->lLen($key[0]), $data);
- $data = $redis->lInsert($key[0], true, 'd', 'c');
- $this->assertEquals(-1, $data);
- $redis->del($key[1]);
- $data = $redis->rPush($key[1], $value[0], $value[2], $value[1]);
- $this->assertEquals(3, $data);
- $data = $redis->lRange($key[1], 0, 3);
- $this->assertEquals(count($data), 3);
- $data = $redis->lPop($key[1]);
- $this->assertEquals($value[0], $data);
- $data = $redis->rPop($key[1]);
- $this->assertEquals($value[1], $data);
- $data = $redis->lPuShx($key[1], 'x');
- $this->assertEquals($redis->lLen($key[1]), $data);
- $this->assertEquals('x', $redis->lPop($key[1]));
- $data = $redis->rPuShx($key[1], 'z');
- $this->assertEquals($redis->lLen($key[1]), $data);
- $this->assertEquals('z', $redis->rPop($key[1]));
- $redis->del($key[1]);
- $redis->rPush($key[1], $value[0], $value[0], $value[0]);
- $data = $redis->lRem($key[1], 1, $value[0]);
- $this->assertEquals(1, $data);
- $data = $redis->lSet($key[1], 0, 'xx');
- $this->assertTrue($data);
- $this->assertEquals('xx', $redis->lPop($key[1]));
- $data = $redis->lTrim($key[1], 0, 2);
- $this->assertTrue($data);
- $this->assertEquals(1, $redis->lLen($key[1]));
- }
- /**
- * testList序列化测试
- * @author tioncico
- * Time: 下午8:17
- */
- function testListSerialize()
- {
- $redis = $this->redisPHPSerialize;
- $key = [
- 'listKey1',
- 'listKey2',
- 'listKey3',
- ];
- $value = [
- 'a', 'b', 'c', 'd'
- ];
- $redis->flushAll();
- //测试null的时候
- $data = $redis->bLPop([$key[0], $key[1]], 1);
- $this->assertNull($data);
- $data = $redis->lPush($key[0], $value[0], $value[1]);
- $this->assertEquals(2, $data);
- //测试null的时候
- $data = $redis->bLPop([$key[1]], 1);
- $this->assertNull($data);
- $data = $redis->bRPop([$key[1]], 1);
- $this->assertNull($data);
- $data = $redis->bLPop([$key[0], $key[1]], 1);
- $this->assertTrue(!!$data);
- $data = $redis->bRPop([$key[0], $key[1]], 1);
- $this->assertTrue(!!$data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->bRPopLPush($key[0], $key[1], 1);
- $this->assertEquals($value[0], $data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->rPopLPush($key[0], $key[1]);
- $this->assertEquals($value[0], $data);
- $redis->del($key[0]);
- $redis->lPush($key[0], $value[0], $value[1]);
- $data = $redis->lIndex($key[0], 1);
- $this->assertEquals($value[0], $data);
- $data = $redis->lLen($key[0]);
- $this->assertEquals(2, $data);
- $data = $redis->lInsert($key[0], true, 'b', 'c');
- $this->assertEquals($redis->lLen($key[0]), $data);
- $data = $redis->lInsert($key[0], true, 'd', 'c');
- $this->assertEquals(-1, $data);
- $redis->del($key[1]);
- $data = $redis->rPush($key[1], $value[0], $value[2], $value[1]);
- $this->assertEquals(3, $data);
- $data = $redis->lRange($key[1], 0, 3);
- $this->assertEquals([$value[0], $value[2], $value[1]], $data);
- $data = $redis->lPop($key[1]);
- $this->assertEquals($value[0], $data);
- $data = $redis->rPop($key[1]);
- $this->assertEquals($value[1], $data);
- $data = $redis->lPuShx($key[1], 'x');
- $this->assertEquals($redis->lLen($key[1]), $data);
- $this->assertEquals('x', $redis->lPop($key[1]));
- $data = $redis->rPuShx($key[1], 'z');
- $this->assertEquals($redis->lLen($key[1]), $data);
- $this->assertEquals('z', $redis->rPop($key[1]));
- $redis->del($key[1]);
- $redis->rPush($key[1], $value[0], $value[0], $value[0]);
- $data = $redis->lRem($key[1], 1, $value[0]);
- $this->assertEquals(1, $data);
- $data = $redis->lSet($key[1], 0, 'xx');
- $this->assertTrue($data);
- $this->assertEquals('xx', $redis->lPop($key[1]));
- $data = $redis->lTrim($key[1], 0, 2);
- $this->assertTrue($data);
- $this->assertEquals(1, $redis->lLen($key[1]));
- }
- /**
- * 集合测试
- * testMuster
- * @author Tioncico
- * Time: 9:10
- */
- function testMuster()
- {
- $redis = $this->redis;
- $key = [
- 'muster1',
- 'muster2',
- 'muster3',
- 'muster4',
- 'muster5',
- ];
- $value = [
- '1',
- '2',
- '3',
- '4',
- ];
- $redis->del($key[0]);
- $redis->del($key[1]);
- $data = $redis->sAdd($key[0], $value[0], $value[1]);
- $this->assertEquals(2, $data);
- $data = $redis->sCard($key[0]);
- $this->assertEquals(2, $data);
- $redis->sAdd($key[1], $value[0], $value[2]);
- $data = $redis->sDiff($key[0], $key[1]);
- $this->assertEquals([$value[1]], $data);
- $data = $redis->sDiff($key[1], $key[0]);
- $this->assertEquals([$value[2]], $data);
- $data = $redis->sMembers($key[0]);
- $this->assertEquals([$value[0], $value[1]], $data);
- $data = $redis->sMembers($key[1]);
- $this->assertEquals([$value[0], $value[2]], $data);
- $data = $redis->sDiffStore($key[2], $key[0], $key[1]);
- $this->assertEquals(1, $data);
- $data = $redis->sMembers($key[2]);
- $this->assertEquals([$value[1]], $data);
- $data = $redis->sInter($key[0], $key[1]);
- $this->assertEquals([$value[0]], $data);
- $data = $redis->sInterStore($key[3], $key[0], $key[1]);
- $this->assertEquals(1, $data);
- $this->assertEquals([$value[0]], $redis->sMembers($key[3]));
- $data = $redis->sIsMember($key[0], $value[0]);
- $this->assertEquals(1, $data);
- $data = $redis->sIsMember($key[0], $value[3]);
- $this->assertEquals(0, $data);
- $data = $redis->sMove($key[0], $key[1], $value[1]);
- $this->assertEquals(1, $data);
- $data = $redis->sPop($key[0]);
- $this->assertEquals(1, $data);
- $redis->sAdd('myset','one','two','three');
- $this->assertCount(2,new \ArrayIterator($redis->sPop('myset',2)));
- $this->assertIsString( $redis->sPop('myset'));
- $redis->del('myset');
- $redis->del($key[3]);
- $redis->sAdd($key[3], $value[0], $value[1], $value[2], $value[3]);
- $data = $redis->sRandMember($key[3], 4);
- $this->assertEquals(4, count($data));
- $data = $redis->sRandMember($key[3].rand(1,1111));
- $this->assertEquals(null, $data);
- $data = $redis->sRandMember($key[3]);
- $this->assertTrue(in_array($data,$value));
- $data = $redis->sRem($key[3], $value[0], $value[1], $value[2], $value[3]);
- $this->assertEquals(4, $data);
- $this->assertEquals([], $redis->sMembers($key[3]));
- $data = $redis->sUnion($key[0], $key[1]);
- $this->assertEquals([$value[0], $value[1], $value[2]], $data);
- $redis->del($key[1]);
- $redis->del($key[2]);
- $redis->del($key[3]);
- $redis->del($key[4]);
- $redis->sAdd($key[1], 1, 2, 3, 4);
- $redis->sAdd($key[2], 5);
- $redis->sAdd($key[3], 6, 7);
- $data = $redis->sUnIonStore($key[4], $key[1], $key[2], $key[3]);
- $this->assertEquals(7, $data);
- $cursor = 0;
- $redis->del('a');
- $redis->sAdd('a', 'a1', 'a2', 'a3', 'a4', 'a5');
- $data = [];
- do {
- $keys = $redis->sScan('a', $cursor, '*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(5, count($data));
- }
- /**
- * 集合序列化测试
- * testMuster
- * @author Tioncico
- * Time: 9:10
- */
- function testMusterSerialize()
- {
- $redis = $this->redisPHPSerialize;
- $key = [
- 'muster1',
- 'muster2',
- 'muster3',
- 'muster4',
- 'muster5',
- ];
- $value = [
- '1',
- '2',
- '3',
- '4',
- ];
- $redis->del($key[0]);
- $redis->del($key[1]);
- $data = $redis->sAdd($key[0], $value[0], $value[1]);
- $this->assertEquals(2, $data);
- $data = $redis->sCard($key[0]);
- $this->assertEquals(2, $data);
- $redis->sAdd($key[1], $value[0], $value[2]);
- $data = $redis->sDiff($key[0], $key[1]);
- // auth2.0
- $this->assertEquals([$value[1]], $data);
- $data = $redis->sDiff($key[1], $key[0]);
- $this->assertEquals([$value[2]], $data);
- $data = $redis->sMembers($key[0]);
- sort($data);
- $this->assertEquals([$value[0], $value[1]], $data);
- $data = $redis->sMembers($key[1]);
- $this->assertEquals([$value[2], $value[0]], $data);
- $data = $redis->sDiffStore($key[2], $key[0], $key[1]);
- $this->assertEquals(1, $data);
- $data = $redis->sMembers($key[2]);
- $this->assertEquals([$value[1]], $data);
- $data = $redis->sInter($key[0], $key[1]);
- $this->assertEquals([$value[0]], $data);
- $data = $redis->sInterStore($key[3], $key[0], $key[1]);
- $this->assertEquals(1, $data);
- $this->assertEquals([$value[0]], $redis->sMembers($key[3]));
- $data = $redis->sIsMember($key[0], $value[0]);
- $this->assertEquals(1, $data);
- $data = $redis->sIsMember($key[0], $value[3]);
- $this->assertEquals(0, $data);
- $data = $redis->sMove($key[0], $key[1], $value[1]);
- $this->assertEquals(1, $data);
- $data = $redis->sPop($key[0]);
- $this->assertEquals(1, $data);
- $redis->del($key[3]);
- $redis->sAdd($key[3], $value[0], $value[1], $value[2], $value[3]);
- $data = $redis->sRandMember($key[3], 4);
- $this->assertEquals(4, count($data));
- $data = $redis->sRandMember($key[3].rand(1,1111));
- $this->assertEquals(null, $data);
- $data = $redis->sRandMember($key[3]);
- $this->assertTrue(in_array($data,$value));
- $data = $redis->sRem($key[3], $value[0], $value[1], $value[2], $value[3]);
- $this->assertEquals(4, $data);
- $this->assertEquals([], $redis->sMembers($key[3]));
- $data = $redis->sUnion($key[0], $key[1]);
- $this->assertTrue(!!$data);
- $redis->del($key[1]);
- $redis->del($key[2]);
- $redis->del($key[3]);
- $redis->del($key[4]);
- $redis->sAdd($key[1], 1, 2, 3, 4);
- $redis->sAdd($key[2], 5);
- $redis->sAdd($key[3], 6, 7);
- $data = $redis->sUnIonStore($key[4], $key[1], $key[2], $key[3]);
- $this->assertEquals(7, $data);
- $cursor = 0;
- $redis->del('a');
- $redis->sAdd('a', 'a1', 'a2', 'a3', 'a4', 'a5');
- $data = [];
- do {
- $keys = $redis->sScan('a', $cursor, '*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(5, count($data));
- $this->assertTrue(in_array('a1', $data));
- }
- /**
- * 有序集合测试
- * testSortMuster
- * @author Tioncico
- * Time: 14:17
- */
- function testSortMuster()
- {
- $redis = $this->redis;
- $key = [
- 'sortMuster1',
- 'sortMuster2',
- 'sortMuster3',
- 'sortMuster4',
- 'sortMuster5',
- ];
- $member = [
- 'member1',
- 'member2',
- 'member3',
- 'member4',
- 'member5',
- ];
- $score = [
- 1,
- 2,
- 3,
- 4,
- ];
- $redis->del($key[0]);
- $data = $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $this->assertEquals(2, $data);
- $data = $redis->zCard($key[0]);
- $this->assertEquals(2, $data);
- $data = $redis->zCount($key[0], 0, 3);
- $this->assertEquals(2, $data);
- $data = $redis->zInCrBy($key[0], 1, $member[1]);
- $this->assertEquals($score[1] + 1, $data);
- $redis->del($key[0]);
- $redis->del($key[1]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
- $data = $redis->zInTerStore($key[2], [$key[0], $key[1]], [1, 2]);
- $this->assertEquals(1, $data);
- $data = $redis->zLexCount($key[0], '-', '+');
- $this->assertEquals(2, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRange($key[0], 0, -1, true);
- $this->assertEquals([
- $member[0] => $score[0],
- $member[1] => $score[1],
- $member[2] => $score[2],
- ], $data);
- $data = $redis->zRange($key[0], 0, -1, false);
- $this->assertEquals([
- $member[0],
- $member[1],
- $member[2],
- ], $data);
- $data = $redis->zRangeByLex($key[0], '-', '+');
- $this->assertEquals(3, count($data));
- $data = $redis->zRangeByScore($key[0], 2, 3, ['withScores' => true, 'limit' => array(0, 2)]);
- $this->assertEquals([
- $member[1] => $score[1],
- $member[2] => $score[2],
- ], $data);
- $data = $redis->zRangeByScore($key[0], 2, 3, ['withScores' => false, 'limit' => array(0, 2)]);
- $this->assertEquals([
- $member[1],
- $member[2],
- ], $data);
- $data = $redis->zRank($key[0], $member[1]);
- $this->assertEquals(1, $data);
- $data = $redis->zRem($key[0], $member[1], $member[2]);
- $this->assertEquals(2, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByLex($key[0], '-', '+');
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByRank($key[0], 0, 2);
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByScore($key[0], 0, 3);
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRange($key[0], 0, 3);
- $this->assertEquals([
- $member[2],
- $member[1],
- $member[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRange($key[0], 0, 3, true);
- $this->assertEquals([
- $member[2] => $score[2],
- $member[1] => $score[1],
- $member[0] => $score[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRangeByScore($key[0], 3, 0, ['withScores' => true, 'limit' => array(0, 3)]);
- $this->assertEquals([
- $member[2] => $score[2],
- $member[1] => $score[1],
- $member[0] => $score[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zReVRangeByScore($key[0], 3, 0, ['withScores' => false, 'limit' => array(0, 3)]);
- $this->assertEquals([
- $member[2],
- $member[1],
- $member[0],
- ], $data);
- $data = $redis->zRevRank($key[0], $member[0]);
- $this->assertEquals(2, $data);
- $data = $redis->zScore($key[0], $member[0]);
- $this->assertEquals($score[0], $data);
- $redis->del($key[0]);
- $redis->del($key[1]);
- $redis->del($key[2]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
- $data = $redis->zUnionStore($key[2], [$key[1], $key[0]]);
- $this->assertEquals(3, $data);
- $cursor = 0;
- $redis->del('a');
- $redis->zAdd('a', 1, 'a1', 2, 'a2', 3, 'a3', 4, 'a4', 5, 'a5');
- $data = [];
- do {
- $keys = $redis->zScan('a', $cursor, '*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(5, count($data));
- $this->redisPHPSerialize->zAdd('myzset',3,'three');
- $this->redisPHPSerialize->zAdd('myzset',2,'two');
- $this->redisPHPSerialize->zAdd('myzset',1,'one');
- $this->assertEquals(['three' => 3, 'two' => 2], $this->redisPHPSerialize->zPopMax('myzset',2));
- $redis->del('myzset');
- $this->redisPHPSerialize->zAdd('myzset',3,'three');
- $this->redisPHPSerialize->zAdd('myzset',2,'two');
- $this->redisPHPSerialize->zAdd('myzset',1,'one');
- $this->assertEquals(['two' => 2, 'one' => 1], $this->redisPHPSerialize->zPopMin('myzset',2));
- $this->assertEquals(['three' => 3], $this->redisPHPSerialize->zPopMin('myzset',2));
- $this->assertEquals([], $this->redisPHPSerialize->zPopMin('myzset',2));
- $redis->del('myzset');
- $this->redisPHPSerialize->zAdd('myzset',3,'three');
- $this->redisPHPSerialize->zAdd('myzset',2,'two');
- $this->redisPHPSerialize->zAdd('myzset',1,'one');
- $this->assertEquals(['myzset','three',3], $this->redisPHPSerialize->bZPopMax('myzset',1));
- $this->assertEquals(['myzset','one',1], $this->redisPHPSerialize->bZPopMin('myzset',1));
- $redis->del('myzset');
- }
- /**
- * 有序集合序列化测试
- * testSortMuster
- * @author Tioncico
- * Time: 14:17
- */
- function testSortMusterSerialize()
- {
- $redis = $this->redisPHPSerialize;
- $key = [
- 'sortMuster1',
- 'sortMuster2',
- 'sortMuster3',
- 'sortMuster4',
- 'sortMuster5',
- ];
- $member = [
- 'member1',
- 'member2',
- 'member3',
- 'member4',
- 'member5',
- ];
- $score = [
- 1,
- 2,
- 3,
- 4,
- ];
- $redis->del($key[0]);
- $data = $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $this->assertEquals(2, $data);
- $data = $redis->zCard($key[0]);
- $this->assertEquals(2, $data);
- $data = $redis->zCount($key[0], 0, 3);
- $this->assertEquals(2, $data);
- $redis->del($key[0]);
- $redis->del($key[1]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
- $data = $redis->zInTerStore($key[2], [$key[0], $key[1]], [1, 2]);
- $this->assertEquals(1, $data);
- $data = $redis->zLexCount($key[0], '-', '+');
- $this->assertEquals(2, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRange($key[0], 0, -1, true);
- $this->assertEquals([
- $member[0] => $score[0],
- $member[1] => $score[1],
- $member[2] => $score[2],
- ], $data);
- $data = $redis->zRange($key[0], 0, -1, false);
- $this->assertEquals([
- $member[0],
- $member[1],
- $member[2],
- ], $data);
- $data = $redis->zRangeByLex($key[0], '-', '+');
- $this->assertEquals(3, count($data));
- $data = $redis->zRangeByScore($key[0], 2, 3, ['withScores' => true, 'limit' => array(0, 2)]);
- $this->assertEquals([
- $member[1] => $score[1],
- $member[2] => $score[2],
- ], $data);
- $data = $redis->zRangeByScore($key[0], 2, 3, ['withScores' => false, 'limit' => array(0, 2)]);
- $this->assertEquals([
- $member[1],
- $member[2],
- ], $data);
- $data = $redis->zRank($key[0], $member[1]);
- $this->assertEquals(1, $data);
- $data = $redis->zRem($key[0], $member[1], $member[2]);
- $this->assertEquals(2, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByLex($key[0], '-', '+');
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByRank($key[0], 0, 2);
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRemRangeByScore($key[0], 0, 3);
- $this->assertEquals(3, $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRange($key[0], 0, 3);
- $this->assertEquals([
- $member[2],
- $member[1],
- $member[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRange($key[0], 0, 3, true);
- $this->assertEquals([
- $member[2] => $score[2],
- $member[1] => $score[1],
- $member[0] => $score[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zRevRangeByScore($key[0], 3, 0, ['withScores' => true, 'limit' => array(0, 3)]);
- $this->assertEquals([
- $member[2] => $score[2],
- $member[1] => $score[1],
- $member[0] => $score[0],
- ], $data);
- $redis->del($key[0]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
- $data = $redis->zReVRangeByScore($key[0], 3, 0, ['withScores' => false, 'limit' => array(0, 3)]);
- $this->assertEquals([
- $member[2],
- $member[1],
- $member[0],
- ], $data);
- $data = $redis->zRevRank($key[0], $member[0]);
- $this->assertEquals(2, $data);
- $data = $redis->zScore($key[0], $member[0]);
- $this->assertEquals($score[0], $data);
- $redis->del($key[0]);
- $redis->del($key[1]);
- $redis->del($key[2]);
- $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
- $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
- $data = $redis->zUnionStore($key[2], [$key[1], $key[0]], [1, 2]);
- $this->assertEquals(3, $data);
- $cursor = 0;
- $redis->del('a');
- $redis->zAdd('a', 1, 'a1', 2, 'a2', 3, 'a3', 4, 'a4', 5, 'a5');
- $data = [];
- do {
- $keys = $redis->zScan('a', $cursor, '*', 1);
- $data = array_merge($data, $keys);
- } while ($cursor);
- $this->assertEquals(1, $data['a1']);
- }
- /**
- * Stream 测试
- * @author gaobinzhan <gaobinzhan@gmail.com>
- */
- function tream(){
- $redis = $this->redis;
- $id = $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $this->assertIsString($id);
- $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy'], 1);
- $length = $redis->xLen('test');
- $this->assertEquals(1, $length);
- $ids[] = $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $ids[] = $redis->xAdd('test','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- $delNum = $redis->xDel('test',$ids);
- $this->assertEquals(2, $delNum);
- $result = $redis->xRange('test','-','+',0);
- $this->assertEmpty($result);
- $result = $redis->xRange('test','-','+');
- $this->assertIsArray($result);
- $result = $redis->xRevRange('test','+','-',0);
- $this->assertEmpty($result);
- $result = $redis->xRevRange('test','+','-');
- $this->assertIsArray($result);
- $redis->del('test1');
- $redis->xAdd('test1','*',['name' => 'gaobinzhan', 'sex' => 'boy']);
- $redis->xAdd('test1','*',['name' => 'gaobinzhan', 'sex' => 'boy']);
- $redis->xAdd('test1','*',['name' => 'gaobinzhan', 'sex' => 'boy']);
- $len = $redis->xTrim('test1',2);
- $this->assertEquals(1, $len);
- $result = $redis->xRead(['test1' => '0-0'],1,0);
- $this->assertIsArray($result);
- $this->assertCount(1,$result['test1']);
- $result = $redis->xRead(['test1' => '0-0'],2,0);
- $this->assertCount(2,$result['test1']);
- $result = $redis->xRead(['test' => '$'],1,1000);
- $this->assertFalse($result);
- go(function (){
- $result = (new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ])))->xRead(['test1' => '$'],1,1000);
- $this->assertIsArray($result);
- });
- go(function (){
- (new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ])))->xAdd('test2','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- });
- $array = $redis->xGroup('HELP');
- $this->assertIsArray($array);
- $groupName = time();
- $bool = $redis->xGroup('CREATE','mystream',$groupName,'$',true);
- $this->assertTrue($bool);
- $bool = $redis->xGroup('SETID','mystream',$groupName,0);
- $this->assertTrue($bool);
- $int = $redis->xGroup('DELCONSUMER','mystream',$groupName,1);
- $this->assertEquals(0,$int);
- $num = $redis->xGroup('DESTROY','mystream',$groupName);
- $this->assertEquals(1,$num);
- $array = $redis->xInfo('STREAM','mystream');
- $this->assertIsArray($array);
- $groupName =time();
- $redis->xGroup('CREATE','mystream',$groupName,'$',true);
- $array = $redis->xInfo('GROUPS','mystream');
- $this->assertIsArray($array);
- $array = $redis->xPending('mystream',$groupName);
- $this->assertIsArray($array);
- $array = $redis->xPending('mystream',$groupName,'-','+',10);
- $this->assertIsArray($array);
- $array = $redis->xPending('mystream',$groupName,'-','+',10,'consumer-123');
- $this->assertIsArray($array);
- $result = $redis->xReadGroup($groupName,'consumer-111',['mystream' => '>'],1,1000);
- $this->assertFalse($result);
- go(function () use ($groupName){
- $result = (new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ])))->xReadGroup($groupName,'consumer-111',['mystream' => '>'],1,1000);
- $this->assertIsArray($result);
- });
- go(function (){
- (new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ])))->xAdd('mystream','*',['name'=>'gaobinzhan', 'sex'=>'boy']);
- });
- $redis->xAdd('mystream','*',['name' => 1]);
- $num = $redis->xAck('mystream',$groupName,[0]);
- $this->assertEquals(0,$num);
- $result = $redis->xReadGroup($groupName,'consumer-111',['mystream' => '>'],1,1000);
- $num = $redis->xAck('mystream',$groupName,array_keys($result['mystream']));
- $this->assertEquals(1,$num);
- $redis->xAdd('mystream','*',['name' => 1]);
- $redis->xAdd('mystream','*',['name' => 1]);
- $result = $redis->xReadGroup($groupName,'consumer-111',['mystream' => '>'],2,0);
- $num = $redis->xAck('mystream',$groupName,array_keys($result['mystream']));
- $this->assertEquals(2,$num);
- $redis->xAdd('mystream','*',['name' => 1]);
- $redis->xReadGroup($groupName,'consumer-111',['mystream' => '>'],2,0);
- $result = $redis->xPending('mystream',$groupName,'-','+',2);
- $ids[] = $result[0][0];
- $ids[] = $result[1][0];
- $array = $redis->xClaim('mystream',$groupName,'abc',2,$ids);
- $this->assertIsArray($array);
- }
- /**
- * 基数统计 测试
- * testHyperLog
- * @author Tioncico
- * Time: 14:59
- */
- function testHyperLog()
- {
- $redis = $this->redis;
- $key = [
- 'hp1',
- 'hp2',
- 'hp3',
- 'hp4',
- 'hp5',
- ];
- $redis->del($key[0]);
- $redis->del($key[1]);
- $data = $redis->pfAdd($key[0], [1, 2, 2, 3, 3]);
- $this->assertEquals(1, $data);
- $redis->pfAdd($key[1], [1, 2, 2, 3, 3]);
- $data = $redis->pfCount([$key[0], $key[1]]);
- $this->assertEquals(3, $data);
- $data = $redis->pfMerge($key[2], [$key[0], $key[1]]);
- $this->assertEquals(1, $data);
- }
- /**
- * 发布订阅测试
- * testSubscribe
- * @author Tioncico
- * Time: 14:59
- */
- function testSubscribe()
- {
- // $this->assertEquals(1,1);
- go(function () {
- $redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- $redis->pSubscribe(function (Redis $redis, $pattern, $str) {
- $redis2 = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- var_dump($redis2);
- var_dump($redis2->set('a',2133));
- var_dump($redis2->get('a'));
- $this->assertEquals('test', $str);
- $data = $redis->unsubscribe('test');
- $this->assertTrue(!!$data);
- $redis->setSubscribeStop(true);
- }, 'test', 'test1', 'test2');
- });
- go(function () {
- $redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- $redis->subscribe(function (Redis $redis, $pattern, $str) {
- $this->assertEquals('test', $str);
- $data = $redis->unsubscribe('test');
- $this->assertTrue(!!$data);
- $redis->setSubscribeStop(true);
- }, 'test', 'test1', 'test2');
- });
- $redis = $this->redis;
- $data = $redis->pubSub('CHANNELS');
- $this->assertIsArray($data);
- Coroutine::sleep(1);
- $data = $redis->publish('test2', 'test');
- $this->assertGreaterThan(0, $data);
- //
- $data = $redis->pUnSubscribe('test');
- $this->assertTrue(!!$data);
- }
- /**
- * 事务测试
- * testTransaction
- * @author tioncico
- * Time: 下午5:40
- */
- function testTransaction()
- {
- $redis = $this->redis;
- $data = $redis->multi();
- $this->assertTrue($data);
- $this->assertEquals(true, $redis->getTransaction()->isTransaction());
- $redis->del('ha');
- $data = $redis->hset('ha', 'a', 1);
- $this->assertEquals('QUEUED', $data);
- $data = $redis->hset('ha', 'b', '2');
- $this->assertEquals('QUEUED', $data);
- $data = $redis->hset('ha', 'c', '3');
- $this->assertEquals('QUEUED', $data);
- $data = $redis->hGetAll('ha');
- $this->assertEquals('QUEUED', $data);
- $data = $redis->exec();
- $this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3], $data[4]);
- $this->assertEquals(false, $redis->getTransaction()->isTransaction());
- $redis->multi();
- $this->assertEquals(true, $redis->getTransaction()->isTransaction());
- $data = $redis->discard();
- $this->assertEquals(true, $data);
- $this->assertEquals(false, $redis->getTransaction()->isTransaction());
- $data = $redis->watch('a', 'b', 'c');
- $data = $redis->unwatch();
- $this->assertEquals(1, $data);
- }
- /**
- * 管道测试
- * testTransaction
- * @author tioncico
- * Time: 下午5:40
- */
- function testPipe()
- {
- $this->assertEquals(1, 1);
- $redis = $this->redis;
- $redis->get('a');
- $data = $redis->startPipe();
- $this->assertTrue($data);
- $this->assertEquals(true, $redis->getPipe()->isStartPipe());
- $redis->del('ha');
- $data = $redis->hset('ha', "a", "a\r\nb\r\nc");
- $this->assertEquals('PIPE', $data);
- $data = $redis->hset('ha', 'b', '2');
- $this->assertEquals('PIPE', $data);
- $data = $redis->hset('ha', 'c', '3');
- $this->assertEquals('PIPE', $data);
- $data = $redis->hGetAll('ha');
- $this->assertEquals('PIPE', $data);
- $data = $redis->execPipe();
- $this->assertEquals(['a' => "a\r\nb\r\nc", 'b' => 2, 'c' => 3], $data[4]);
- $this->assertEquals(false, $redis->getPipe()->isStartPipe());
- $redis->startPipe();
- $this->assertEquals(true, $redis->getPipe()->isStartPipe());
- $data = $redis->set("a", '1');
- $this->assertTrue($data);
- $this->assertEquals('Set', ($redis->getPipe()->getCommandLog()[0][0]));
- $data = $redis->discardPipe();
- $this->assertEquals(true, $data);
- $this->assertEquals(false, $redis->getPipe()->isStartPipe());
- }
- /**
- * 脚本执行测试
- * testScript
- * @author tioncico
- * Time: 下午5:41
- */
- function testScript()
- {
- $this->assertEquals(1, 1);
- $redis = $this->redis;
- // $data = $redis->eval('s','s','a','1','2','a');
- // $this->assertEquals(1,$data);
- //
- // $data = $redis->evalsha('a','g','g','1','a','a');
- // $this->assertEquals(1,$data);
- //
- // $data = $redis->scriptExists('a','f');
- // $this->assertEquals(1,$data);
- //
- // $data = $redis->scriptFlush();
- // $this->assertEquals(1,$data);
- //
- // $data = $redis->scriptKill();
- // $this->assertEquals(1,$data);
- //
- // $data = $redis->scriptLoad('a');
- // $this->assertEquals(1,$data);
- }
- /**
- * 服务器命令测试
- * testServer
- * @author tioncico
- * Time: 下午5:41
- */
- function testServer()
- {
- $redis = $this->redis;
- $data = $redis->bgRewriteAof();
- $this->assertEquals('Background append only file rewriting started', $data);
- Coroutine::sleep(1);
- $data = $redis->bgSave();
- $this->assertEquals('Background saving started', $data);
- $data = $redis->clientList();
- $this->assertIsArray($data);
- $data = $redis->clientSetName('test');
- $this->assertTrue($data);
- $data = $redis->clientGetName();
- $this->assertEquals('test', $data);
- $data = $redis->clientPause(1);
- $this->assertEquals(1, $data);
- $data = $redis->command();
- $this->assertIsArray($data);
- $data = $redis->commandCount();
- $this->assertGreaterThan(0, $data);
- $data = $redis->commandGetKeys('MSET', 'a', 'b', 'c', 'd');
- $this->assertEquals(['a', 'c'], $data);
- $data = $redis->time();
- $this->assertIsArray($data);
- $data = $redis->commandInfo('get', 'set');
- $this->assertIsArray($data);
- $data = $redis->configGet('*max-*-entries*');
- $this->assertIsArray($data);
- $data = $redis->configSet('appendonly', 'yes');
- $this->assertTrue($data);
- $data = $redis->configRewrite();
- $this->assertTrue($data);
- $data = $redis->configResetStat();
- $this->assertTrue($data);
- $data = $redis->dBSize();
- $this->assertGreaterThanOrEqual(0, $data);
- $redis->set('a', 1);
- $data = $redis->debugObject('a');
- $this->assertIsString($data);
- $data = $redis->flushAll();
- $this->assertTrue($data);
- $data = $redis->flushDb();
- $this->assertTrue($data);
- $data = $redis->info();
- $this->assertIsArray($data);
- $data = $redis->lastSave();
- $this->assertNotFalse($data);
- go(function () {
- $redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- $redis->monitor(function (Redis $redis, $data) {
- $this->assertIsString($data);
- $redis->set('a', 1);
- $redis->setMonitorStop(true);
- });
- });
- go(function () {
- $redis = new Redis(new RedisConfig([
- 'host' => REDIS_HOST,
- 'port' => REDIS_PORT,
- 'auth' => REDIS_AUTH
- ]));
- Coroutine::sleep(1);
- $redis->set('a', 1);
- });
- $data = $redis->save();
- $this->assertTrue($data);
- $data = $redis->clientList();
- $data = $redis->clientKill($data[0]['addr']);
- $this->assertTrue($data);
- try {
- $redis->slowLog('get', 'a');
- }catch (RedisException $exception){
- $this->assertEquals('ERR value is not an integer or out of range',$exception->getMessage());
- }
- }
- /**
- * geohash测试
- * testGeohash
- * @author tioncico
- * Time: 下午6:11
- */
- function testGeohash()
- {
- $redis = $this->redis;
- $key = 'testGeohash';
- $redis->del($key);
- $data = $redis->geoAdd($key, [
- ['118.6197800000', '24.88849', 'user1',],
- ['118.6197800000', '24.88859', 'user2',],
- ['114.8197800000', '25.88849', 'user3'],
- ['118.8197800000', '22.88849', 'user4'],
- ]);
- $this->assertEquals(4, $data);
- $data = $redis->geoAdd($key, [
- ['118.6197800000', '24.88869', 'user5',],
- ]);
- $data = $redis->geoDist($key, 'user1', 'user2');
- $this->assertGreaterThan(10, $data);
- $data = $redis->geoHash($key, 'user1', 'user2');
- $this->assertIsArray($data);
- $data = $redis->geoPos($key, 'user1', 'user2');
- $this->assertIsArray($data);
- $data = $redis->geoRadius($key, '118.6197800000', '24.88849', 100, 'm', false, false, false, null,'desc');
- $this->assertEquals(['user5','user2', 'user1'], $data);
- $data = $redis->geoRadiusByMember($key, 'user1', 100, 'm', false, false, false, 2,'DESC');
- //限制为2,并且desc
- $this->assertEquals(['user5', 'user2'], $data);
- $data = $redis->geoRadiusByMember($key, 'user1', 100, 'm', false, false, false, null,'asc');
- //不限制并且asc
- $this->assertEquals(['user1', 'user2', 'user5'], $data);
- }
- /**
- * bit map
- */
- public function testBitMap()
- {
- $redis = $this->redis;
- $redis->set('w', 'hello');
- // bitcount
- $result = $redis->bitCount('w');
- $this->assertEquals(21, $result);
- $result = $redis->bitCount('w', 0, 0);
- $this->assertEquals(3, $result);
- $result = $redis->bitCount('w', 0, 1);
- $this->assertEquals(7, $result);
- // bitpos
- $result = $redis->bitPos('w',0);
- $this->assertEquals(0, $result);
- $result = $redis->bitPos('w',1);
- $this->assertEquals(1, $result);
- $result = $redis->bitPos('w',1,1,1);
- $this->assertEquals(9, $result);
- $result = $redis->bitPos('w',1,2,2);
- $this->assertEquals(17, $result);
- // bitop
- $redis->set('key1','foobar');
- $redis->set('key2','abcdef');
- $result = $redis->bitOp('AND','dest','key1','key2');
- $this->assertEquals(6, $result);
- $result = $redis->get('dest');
- $this->assertEquals("`bc`ab", $result);
- $result = $redis->bitOp('OR','dest','key1','key2','w');
- $this->assertEquals(6, $result);
- $result = $redis->get('dest');
- $this->assertEquals("ooonov", $result);
- // bitfield
- $redis->del('mykey');
- $result = $redis->bitField('mykey',['INCRBY','i5',100,1,'GET','u4',0]);
- $this->assertEquals([1,0], $result);
- $result = $redis->bitField('mykey',[['INCRBY','i5',100,1,], ['GET','u4',0]]);
- $this->assertEquals([2,0], $result);
- $redis->del('mystring');
- $result = $redis->bitField('mystring',['SET' ,'i8' ,'#0' ,100 ,'SET' ,'i8' ,'#1' ,200]);
- $this->assertEquals([0,0],$result);
- $result = $redis->bitField('mystring',[['SET' ,'i8' ,'#0' ,100 ] ,['SET' ,'i8' ,'#1' ,200]]);
- $this->assertEquals([100,-56],$result);
- $redis->del('mykey');
- $result = $redis->bitField('mykey',['INCRBY','u2',100,1], 'SAT',['INCRBY','u2',102,1]);
- $this->assertEquals([1,1], $result);
- $result = $redis->bitField('mykey',['INCRBY','u2',100,1], 'SAT',[['INCRBY','u2',102,1]]);
- $this->assertEquals([2,2], $result);
- $result = $redis->bitField('mykey',['INCRBY','u2',100,1], 'SAT',[['INCRBY','u2',102,1]]);
- $this->assertEquals([3,3], $result);
- $result = $redis->bitField('mykey',['INCRBY','u2',100,1], 'SAT',[['INCRBY','u2',102,1]]);
- $this->assertEquals([0,3], $result);
- $result = $redis->bitField('mykey',[],'FAIL',[['incrby','u2',102,1]]);
- $this->assertEquals([NULL], $result);
- }
- }
|