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

<?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中,如果field不存在
        $res1 = $redis->hSetNx('h','k1','v1');
        $res2 = $redis->hSetNx('h','k1','v2');
        var_dump($res1);//bool(true)
        var_dump($res2);//bool(false)






    }




}

猜你喜欢

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