PHP array is actually a hash table, Redis does not seem to support two-dimensional arrays, but you can use Hmset to save the PHP array as a hash type of data, using Hmget to read a one-dimensional key is no problem, reading two-dimensional multidimensional keys return false.
$hset = Array (
' wust ' => ' WUHAN SI ',
' birth ' =>1031,
' Marray ' =>array ' (
' apple ' => ' apples '),
' orange ' => ' org ',)
;
Dump ($redis->hmset (' Tuntun ', $hset))//save array as hash type
dump ($redis->hmget (' Tuntun ', Array (' birth ')) ;//Fetch the value of an array birth, OK
dump ($redis->hmget (' Tuntun ', Array (' Marry ', ' apple '));//Remove the value of apple from the two-dimensional array marray. return False
Even if you use the Hgetall method:
Dump ($redis->hgetall (' Hset_tuntun '));
The results are as follows:
Array (3) {
["Wust"] => string (8) "WUHAN SI"
["Birth"] => string (4) "1031"
["Marray"] => string (5) "Array"
}
Two-dimensional arrays cannot be displayed. So Redis does not support access to multidimensional arrays of PHP.
The solution is: if you want to use Redis to save multidimensional arrays, you can convert the array json_encode into JSON-type data, stored in string style. Read the time again Json_decode back.