{"name":"@redis/time-series","version":"6.3.1","keywords":["redis","RedisTimeSeries"],"license":"MIT","_id":"@redis/time-series@6.3.1","maintainers":[{"name":"dmaier-redislabs","email":"david.maier@redis.com"},{"name":"pavelpashov","email":"pavel.pashov@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":"a5afcae70455603e5f8f9a9ce1f8836f7859d1e1","tarball":"http://registry-npm.ywwl.com/@redis/time-series/download/@redis/time-series-6.3.1.tgz","fileCount":186,"integrity":"sha512-MNDgrm+i63M/1a+XA+HcDsScwt4uBh/fGGJ84swTQZTFK5K5wMmxdlTRa4ZgmNJzjxMaszW/ipPScMUGV3aAMg==","signatures":[{"sig":"MEUCIQCrr60pOV/jS1+oOoVeNB7uCANw3KgCAdifBB+9p66YGAIgY0aUJq3qv7X4/1YVAEJcnKW6pH7bph9WOIEmOrK89dQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDxkEdYZCvsCTRu+8FfTV+v2DBiqLqPl+VI5Y/dCgim5AIhAP2MXYqVQ8bFNVzC3NW+u6uKue4i2JGjhFIQdxwh99uT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@redis%2ftime-series@6.3.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":552903,"size":63127,"noattachment":false,"key":"/@redis/time-series/-/@redis/time-series-6.3.1.tgz"},"main":"./dist/lib/index.js","types":"./dist/lib/index.d.ts","engines":{"node":">= 20.0.0"},"gitHead":"63a9b6d90a9d1518c3bab44c1b889c64522c6099","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":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"c6fd0e27-4386-4220-b25d-e95706c7bf9b"}},"repository":{"url":"git://github.com/redis/node-redis.git","type":"git"},"_npmVersion":"11.21.1","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.4","_hasShrinkwrap":false,"devDependencies":{"@redis/test-utils":"*"},"peerDependencies":{"@redis/client":"^6.3.1"},"_npmOperationalInternal":{"tmp":"tmp/time-series_6.3.1_1793265529263_0.048448976883771255","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":1793265529349,"_cnpm_publish_time":1793265529349,"dist-tags":{"beta":"6.4.0-beta.0","latest":"6.3.1","next":"5.0.0-next.7"}}