Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用Predis查询Redis中的数组_Php_Redis_Predis_Nosql - Fatal编程技术网

Php 用Predis查询Redis中的数组

Php 用Predis查询Redis中的数组,php,redis,predis,nosql,Php,Redis,Predis,Nosql,我想用Predis在Redis中存储和“选择”阵列,我输入的数据如下: $redis->hset("account_id_".$account_id, "access_time", time()); 所以我把这个结构存储在redis中 db0 account_id_1 access_time: 1400901850 ... other values account_id_2 access_time: 1400

我想用Predis在Redis中存储和“选择”阵列,我输入的数据如下:

$redis->hset("account_id_".$account_id, "access_time", time());
所以我把这个结构存储在redis中

db0
    account_id_1
        access_time: 1400901850
        ...
        other values
    account_id_2
        access_time: 1400901862
        ...
        other values
    ...
    other_accounts
我想选择unix时间戳范围内的所有帐户,但到目前为止我还没有找到方法,我怀疑数据结构是否适用于此目的

我怀疑数据结构是否正确

您可以使用散列来存储帐户数据,但如果希望在
access\u time
字段上进行优于O(N)的查找,则需要使用另一种数据结构。也就是说,您应该使用排序集

您的数据库中应该有一个排序集类型的附加键,名为
account:access\u time
。访问帐户时,应运行以下redis命令(当然,应填写适当的变量):

稍后,如果要根据访问时间执行查找,请运行以下操作:

ZRANGEBYSCORE account:access_time $min_access_time $max_access_time

上面的命令将返回一个帐户ID列表,您可以对其执行操作。

非常感谢Tim,这正是我要查找的
ZRANGEBYSCORE account:access_time $min_access_time $max_access_time