在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

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