该命令用于在 key 存在是删除 key。

    删除指定的键。

    Parameters:
    array|int|string $key1 一个键数组,或一个未定义数量的参数,每个键:key1 key2 key3…keyN
    int|string $otherKeys
    Returns:
    删除的键数

    Declared in: Redis
    Links: https://redis.io/commands/del
    Source:
    S:/Software/JetBrains/PHPStorm/App/PhpStorm-2020.2.1.win/plugins/php/lib/php.jar!/stubs/redis/Redis.php
    del on redis.io

    1. <?php
    2. //连接本地的 Redis 服务
    3. $redis = new Redis();
    4. $redis->connect('10.1.3.15', 6379);
    5. $redis->auth('kuaicdn_redis_passwd');
    6. $redis->flushAll();
    7. $ret['exec'][]=$redis->mset(array(
    8. 'list_test1'=>'value1',
    9. 'list_test2'=>'value2',
    10. 'list_test3'=>'value3',
    11. ));
    12. $ret['ret'][]=$redis->mget(array(
    13. 'list_test1',
    14. 'list_test2',
    15. 'list_test3'
    16. ));
    17. $ret['exec'][]=$redis->del('list_test2');
    18. $ret['ret'][]=$redis->mget(array(
    19. 'list_test1',
    20. 'list_test2',
    21. 'list_test3'
    22. ));
    23. print_r($ret);
    24. ?>

    返回值:

    1. Array
    2. (
    3. [exec] => Array
    4. (
    5. [0] => 1
    6. [1] => 1
    7. )
    8. [ret] => Array
    9. (
    10. [0] => Array
    11. (
    12. [0] => value1
    13. [1] => value2
    14. [2] => value3
    15. )
    16. [1] => Array
    17. (
    18. [0] => value1
    19. [1] =>
    20. [2] => value3
    21. )
    22. )
    23. )