TSLASTN

AttentionThis page documents an earlier version. Go to the latest (v2.1)version.

Synopsis

TSLASTN key NThis command fetches the latest N entries in the time series that is specified by the given key.The elements are returned in ascending order of timestamps.

  • If the given key is associated with non-timeseries data, an error is raised.
  • If the given N is not a positive 32 bit integer, an error is raised.

Return Value

Returns a list of timestamp, value pairs for the latest N entries in the time series.

Examples

You can do this as shown below.

  1. $ TSADD ts_key 10 v1 20 v2 30 v3 40 v4 50 v5
  1. "OK"
  1. $ TSLASTN ts_key 2
  1. 1) "40"
  2. 2) "v4"
  3. 3) "50"
  4. 4) "v5"
  1. $ TSLASTN ts_key 3
  1. 1) "30"
  2. 2) "v3"
  3. 3) "40"
  4. 4) "v4"
  5. 5) "50"
  6. 6) "v5"
  1. $ TSLASTN ts_key 9999999999
  1. (error) ERR tslastn: limit field 9999999999 is not within valid bounds
  1. $ TSLASTN ts_key 0
  1. (error) ERR tslastn: limit field 0 is not within valid bounds
  1. $ TSLASTN ts_key -1
  1. (error) ERR tslastn: limit field -1 is not within valid bounds

See Also

tsadd, tsget, tsrem,tsrangebytime, tsrangebytime, tscard