<?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表中所有的value,以数组形式返回
$res = $redis->hVals('h');
var_dump($res);
/**
* array(3) {
[0]=>
string(2) "v1"
[1]=>
string(2) "v2"
[2]=>
string(2) "v3"
}
*/
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。