duanjuete9206 2017-04-25 15:40
浏览 170

在redis中设置多个哈希值

I'm using the following library: predis php library. Here's the direct github predis github code

In my code, I'm doing the following:

$st=mysqli_query($dbh,"select somethoing from something");
while($row=mysqli_fetch_assoc($st)){
  $redis->hmset("us-states-data-hash",$row);
}

Unfortunately, the ending result of storing the data in redis is only the last record from the sql query.

How do I get all of the rows into redis with a hash tag of us-states-data-hash

  • 写回答

1条回答 默认 最新

  • duanfang5849 2017-04-25 19:12
    关注

    The HMSET Redis command requires a key (us-states-data-hash in your example) and pairs of field names and values.

    While Predis' documentation is still being revised, its tests appear robust. Of specific interest is the HashSetMultipleTest.php file that shows you how to use hmset.

    Your code is passing an associative array to hmset, whereas it looks like you need to splat it, i.e.:

    $redis->hmset("us-states-data-hash", ...$row);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题