我知道如何将数据存储到REDIS中,不幸的是,我不知道如何读回数据并将它们存储到数组中。
以下是我要达到的目标的一个示例:
首先使用HMSET
将数据存储到REDIS:
HMSET product order01 "Red Shoes" price "5USD" quantity "2" time "02/02/2019"
HMSET product order02 "Green Shoes" price "4.99USD" quantity "1" time "03/02/2019"
HMSET product order03 "Yellow Shoes" price "4.99USD" quantity "3" time "04/02/2019"
HMSET product order04 "Pink Shoes" price "4.99USD" quantity "2" time "05/02/2019"
然后,我不知道如何将它们存储回PHP数组中。
使用此命令:
HGETALL product
返回的结果:
1) "order01"
2) "Red Shoes"
3) "price"
4) "4.99USD"
5) "quantity"
6) "2"
7) "time"
8) "05/02/2019"
9) "order02"
10) "Green Shoes"
11) "order03"
12) "Yellow Shoes"
13) "order04"
14) "Pink Shoes"
我们在这里可以看到缺少许多键和值,尤其是对于order02、03和04。(我怀疑我没有使用正确的命令?因为我的目标是将具有完整信息的每一行存储到一个键中)
我将在REDIS中返回所有存储的结果,但是会逐行显示它们,在一行中键入并在另一行中显示值...为此,我迷失了如何检索它们的结果。
有关信息,我正在使用以下代码连接到PHP中的REDIS:
require 'classes/redis/src/Autoloader.php';
Predis\Autoloader::register();
$redis = new Predis\Client([
'read_write_timeout' => 5
]);
$redis->hmset("product", "order01", "Red Shoes", "price", "5USD", "quantity", "2", "time", "02/02/2019");
//............ with other lines here
$redis->expire('product', 3600);
您的帮助将不胜感激。