<?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映射表,特别适用于存储对象 */ $redis->hSet('h','k1','v1'); $redis->hSet('h','k2','v2'); $redis->hSet('h','k3','v3'); // hMget() 批量取得hash表中的value $res = $redis->hMget('h',array('k1','k2','k3')); var_dump($res); /** * array(3) { ["k1"]=> string(2) "v1" ["k2"]=> string(2) "v2" ["k3"]=> string(2) "v3" } */ } }