{"name":"@redis/time-series","version":"6.2.0","keywords":["redis","RedisTimeSeries"],"license":"MIT","_id":"@redis/time-series@6.2.0","maintainers":[{"name":"dmaier-redislabs","email":"david.maier@redis.com"},{"name":"nkaradzhov","email":"nkaradzhov89@gmail.com"}],"homepage":"https://github.com/redis/node-redis/tree/master/packages/time-series","bugs":{"url":"https://github.com/redis/node-redis/issues"},"dist":{"shasum":"57b2df20e1653c5a225afce3f681d72754593dda","tarball":"http://registry-npm.ywwl.com/@redis/time-series/download/@redis/time-series-6.2.0.tgz","fileCount":186,"integrity":"sha512-/H/eE/lnhZLZYpHGpI+ZN7TePb7isEaub8b07oQcTDQptPslVKdUFwNhUm+hQHks781oh+F1Leiip1WHh4HfWw==","signatures":[{"sig":"MEUCIBU/hcAsJR2/QTDBt9afV3YegF9hnScskD8pB8owr/N/AiEA/1tJIJ0rD6oyDl/wbVgFH5Pl9O7Ne8XQWgRq1QzafPE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIF7Dgp6COwi30oWrpSUT+GHYKojTbSE/cC/MX/PWjQcXAiAbvUyw1ComjGjSfB4kHy5TfKgwxmhDzBFnvovP5epMDA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":552831,"size":63130,"noattachment":false,"key":"/@redis/time-series/-/@redis/time-series-6.2.0.tgz"},"main":"./dist/lib/index.js","types":"./dist/lib/index.d.ts","engines":{"node":">= 20.0.0"},"gitHead":"2dde5df0577afd4d550d4f42bcbe46799dee4114","scripts":{"test":"nyc -r text-summary -r lcov mocha -r tsx --reporter mocha-multi-reporters --reporter-options configFile=mocha-multi-reporter-config.json --exit  './lib/**/*.spec.ts'","release":"release-it"},"_npmUser":{"name":"dmaier-redislabs","email":"david.maier@redis.com"},"repository":{"url":"git://github.com/redis/node-redis.git","type":"git"},"_npmVersion":"10.9.8","description":"This package provides support for the [RedisTimeSeries](https://redis.io/docs/data-types/timeseries/) module, which adds a time series data structure to Redis.","directories":{},"_nodeVersion":"22.23.1","_hasShrinkwrap":false,"devDependencies":{"@redis/test-utils":"*"},"peerDependencies":{"@redis/client":"^6.2.0"},"_npmOperationalInternal":{"tmp":"tmp/time-series_6.2.0_1785527863485_0.7314957755489822","host":"s3://npm-registry-packages-npm-production"},"readme":"# @redis/time-series\n\nThis package provides support for the [RedisTimeSeries](https://redis.io/docs/data-types/timeseries/) module, which adds a time series data structure to Redis.\n\nShould be used with [`redis`/`@redis/client`](https://github.com/redis/node-redis).\n\n:warning: To use these extra commands, your Redis server must have the RedisTimeSeries module installed.\n\n## Usage\n\nFor a complete example, see [`time-series.js`](https://github.com/redis/node-redis/blob/master/examples/time-series.js) in the Node Redis examples folder.\n\n### Creating Time Series data structure in Redis\n\nThe [`TS.CREATE`](https://oss.redis.com/redistimeseries/commands/#tscreate) command creates a new time series.\n\nHere, we'll create a new time series \"`temperature`\":\n\n```javascript\n\nimport { createClient } from 'redis';\nimport { TimeSeriesDuplicatePolicies, TimeSeriesEncoding, TIME_SERIES_AGGREGATION_TYPE } from '@redis/time-series';\n\n...\nconst created = await client.ts.create('temperature', {\n  RETENTION: 86400000, // 1 day in milliseconds\n  ENCODING: TimeSeriesEncoding.UNCOMPRESSED, // No compression - When not specified, the option is set to COMPRESSED\n  DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK, // No duplicates - When not specified: set to the global DUPLICATE_POLICY configuration of the database (which by default, is BLOCK).\n});\n\nif (created === 'OK') {\n  console.log('Created timeseries.');\n} else {\n  console.log('Error creating timeseries :(');\n  process.exit(1);\n}\n```\n\n### Adding new value to a Time Series data structure in Redis\n\nWith RedisTimeSeries, we can add a single value to time series data structure using the [`TS.ADD`](https://redis.io/commands/ts.add/) command and if we would like to add multiple values we can use the [`TS.MADD`](https://redis.io/commands/ts.madd/) command.\n\n```javascript\n\nlet value = Math.floor(Math.random() * 1000) + 1; // Random data point value\nlet currentTimestamp = 1640995200000; // Jan 1 2022 00:00:00\nlet num = 0;\n\nwhile (num < 10000) {\n  // Add a new value to the timeseries, providing our own timestamp:\n  // https://redis.io/commands/ts.add/\n  await client.ts.add('temperature', currentTimestamp, value);\n  console.log(`Added timestamp ${currentTimestamp}, value ${value}.`);\n\n  num += 1;\n  value = Math.floor(Math.random() * 1000) + 1; // Get another random value\n  currentTimestamp += 1000; // Move on one second.\n}\n\n// Add multiple values to the timeseries in round trip to the server:\n// https://redis.io/commands/ts.madd/\nconst response = await client.ts.mAdd([{\n  key: 'temperature',\n  timestamp: currentTimestamp + 60000,\n  value: Math.floor(Math.random() * 1000) + 1\n}, {\n  key: 'temperature',\n  timestamp: currentTimestamp + 120000,\n  value: Math.floor(Math.random() * 1000) + 1\n}]);\n```\n\n### Retrieving Time Series data from Redis\n\nWith RedisTimeSeries, we can retrieve the time series data using the [`TS.RANGE`](https://redis.io/commands/ts.range/) command by passing the criteria as follows:\n\n```javascript\n// Query the timeseries with TS.RANGE:\n// https://redis.io/commands/ts.range/\nconst fromTimestamp = 1640995200000; // Jan 1 2022 00:00:00\nconst toTimestamp = 1640995260000; // Jan 1 2022 00:01:00\nconst rangeResponse = await client.ts.range('temperature', fromTimestamp, toTimestamp, {\n  // Group into 10 second averages.\n  AGGREGATION: {\n    type: TIME_SERIES_AGGREGATION_TYPE.AVG,\n    timeBucket: 10000\n  }\n});\n\nconsole.log('RANGE RESPONSE:');\n// rangeResponse looks like:\n// [\n//   { timestamp: 1640995200000, value: 356.8 },\n//   { timestamp: 1640995210000, value: 534.8 },\n//   { timestamp: 1640995220000, value: 481.3 },\n//   { timestamp: 1640995230000, value: 437 },\n//   { timestamp: 1640995240000, value: 507.3 },\n//   { timestamp: 1640995250000, value: 581.2 },\n//   { timestamp: 1640995260000, value: 600 }\n// ]\n```\n\nFor multiple aggregations in one command, use the dedicated `*MultiAggr` methods:\n\n```javascript\nconst multiRangeResponse = await client.ts.rangeMultiAggr('temperature', fromTimestamp, toTimestamp, {\n  AGGREGATION: {\n    types: [\n      TIME_SERIES_AGGREGATION_TYPE.MIN,\n      TIME_SERIES_AGGREGATION_TYPE.MAX,\n      TIME_SERIES_AGGREGATION_TYPE.AVG\n    ],\n    timeBucket: 10000\n  }\n});\n\n// multiRangeResponse looks like:\n// [\n//   { timestamp: 1640995200000, values: [120, 580, 356.8] },\n//   ...\n// ]\n```\n\nEquivalent multi-aggregation helpers are also available for reverse and multi-key variants:\n`revRangeMultiAggr`, `mRangeMultiAggr`, `mRevRangeMultiAggr`, `mRangeWithLabelsMultiAggr`,\n`mRevRangeWithLabelsMultiAggr`, `mRangeSelectedLabelsMultiAggr`, and `mRevRangeSelectedLabelsMultiAggr`.\n\n### Altering Time Series data Stored in Redis\n\nRedisTimeSeries includes commands that can update values in a time series data structure.\n\nUsing the [`TS.ALTER`](https://redis.io/commands/ts.alter/) command, we can update time series retention like this:\n\n```javascript\n// https://redis.io/commands/ts.alter/\nconst alterResponse = await client.ts.alter('temperature', {\n  RETENTION: 0 // Keep the entries forever\n});\n```\n\n### Retrieving Information about the timeseries Stored in Redis\n\nRedisTimeSeries also includes commands that can help to view the information on the state of a time series.\n\nUsing the [`TS.INFO`](https://redis.io/commands/ts.info/) command, we can view timeseries information like this:\n\n```javascript\n// Get some information about the state of the timeseries.\n// https://redis.io/commands/ts.info/\nconst tsInfo = await client.ts.info('temperature');\n\n// tsInfo looks like this:\n// {\n//   totalSamples: 1440,\n//   memoryUsage: 28904,\n//   firstTimestamp: 1641508920000,\n//   lastTimestamp: 1641595320000,\n//   retentionTime: 86400000,\n//   chunkCount: 7,\n//   chunkSize: 4096,\n//   chunkType: 'uncompressed',\n//   duplicatePolicy: 'block',\n//   labels: [],\n//   sourceKey: null,\n//   rules: []\n// }\n```\n","publish_time":1785527863569,"_cnpm_publish_time":1785527863569,"dist-tags":{"beta":"6.4.0-beta.0","latest":"6.3.1","next":"5.0.0-next.7"}}