【问题标题】:Is there any way to add Date attribute in GEOADD method on redis serve有没有办法在 redis 服务的 GEOADD 方法中添加 Date 属性
【发布时间】:2018-10-02 06:57:30
【问题描述】:

在跟踪地理添加代码方面需要帮助

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

【问题讨论】:

    标签: node.js redis node-redis


    【解决方案1】:

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

    根据您正在做的事情,您可以通过将时间存储到各种键中来模拟这一点,例如

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

    但随后查询变得更加复杂。

    【讨论】:

    • redis 中是否还有其他方法可用于根据键添加/更新和获取日期属性? Redis-api
    • 真的要看你到底想达到什么效果。
    【解决方案2】:

    虽然GEOADD 不支持这一点,但您可以将日期属性存储在另一个键中,例如像这样:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多