有没有办法在Redis服务上的GEOADD方法中添加Date属性

时间:2018-10-02 06:57:31

标签: node.js redis node-redis

在遵循geoadd代码时需要帮助

_ client.geoadd('drivers_locations', coordinates[0], coordinates[1], driverID ,new Date().toString());

2 个答案:

答案 0 :(得分:2)

否,GEOADD没有可用的时间维度。

根据您正在执行的操作,您可以通过将时间分散到各种键中来模拟这一点,例如

const key = `drivers_locations_${Math.floor(+new Date() / 1000 / 60)`;
client.geoadd(key, lon, lat, driverID);

但是查询变得更加复杂。

答案 1 :(得分:0)

虽然GEOADD不支持此功能,但是您可以将date属性存储在另一个键中,例如像这样的东西:

client.geoadd('drivers_locations', coordinates[0], coordinates[1], driverID);
client.hset('driver:' + id, 'date', ,ew Date().toString());
相关问题