数据库
首页 > 数据库> > 【thinkphp5操作redis系列教程】哈希类型之hKeys

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

作者:互联网

<?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');

        // hKeys() 获取hash表中的keys,以数组形式返回
        $res = $redis->hKeys('h');
        var_dump($res);
        /**
         *
        array(3) {
        [0]=>
        string(2) "k1"
        [1]=>
        string(2) "k2"
        [2]=>
        string(2) "k3"
        }

         */




    }




}

 

标签:hash,string,k2,thinkphp5,redis,hKeys,hSet
来源: https://blog.51cto.com/u_14097531/2973132