在列表的主元值之前或之后插入值。参数选项指定插入的位置(之前或之后)。如果列表不存在,或者主元不存在,则不插入值。
使用该函数相当于搜索插入
Parameters:
string $key
int $position Redis::BEFORE | Redis::AFTER
string $pivot
mixed|string $value
Returns:
列表中的元素数,如果主元素不存在,则为-1。
Declared in: Redis
Links: https://redis.io/commands/linsert
Source:
S:/Software/JetBrains/PHPStorm/App/PhpStorm-2020.2.1.win/plugins/php/lib/php.jar!/stubs/redis/Redis.phplInsert on redis.io
<?php//连接本地的 Redis 服务$redis = new Redis();$redis->connect('10.1.3.15', 6379);$redis->auth('kuaicdn_redis_passwd');$redis->flushAll();$ret['exec'][]=$redis->rPush('list_test','value1');$ret['exec'][]=$redis->rPush('list_test','value2');$ret['exec'][]=$redis->rPush('list_test','value3');$ret['exec'][]=$redis->rPush('list_test','value4');$ret['exec'][]=$redis->rPush('list_test','value5');$ret['cmd']['BEFORE']=$redis->lInsert('list_test',Redis::BEFORE,"value3",'BEFORE');$ret['cmd']['AFTER']=$redis->lInsert('list_test','AFTER',"value3",'AFTER');$ret['cmd']['NONE']=$redis->lInsert('list_test','BEFORE',"value6",'NONE');$ret['src'][]=$redis->lRange('list_test',0,-1);print_r($ret);?>
返回值:
Array([exec] => Array([0] => 1[1] => 2[2] => 3[3] => 4[4] => 5)[cmd] => Array([BEFORE] => 6[AFTER] => 7[NONE] => -1)[src] => Array([0] => Array([0] => value1[1] => value2[2] => BEFORE[3] => value3[4] => AFTER[5] => value4[6] => value5)))
