【thinkphp5操作redis系列教程】哈希类型之hExists

<?php
namespace app\index\controller;
use Redis;
class Index
{
    public function index()
    {
        $redis = new Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->flushAll();

        /**
         * redis hash是一个string类型的field和value映射表,特别适用于存储对象
         */

        // hSet() 添加一个value到hash中
        $redis->hSet('h','k1','v1');
        $redis->hSet('h','k2','v2');
        $redis->hSet('h','k3','v3');

        // hExists() 判断hash表中是否存在指定的key
        $res1 = $redis->hExists('h','k1');
        var_dump($res1); // bool(true)

        $res2 = $redis->hExists('h','k4');
        var_dump($res2); //bool(false)



    }




}

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/82108793