RedCircle
Implementation of an append-only, capped circular buffer using Redis
Available Scripts
In the project directory, you can run:
npm test
Runs the library test suite, and reports the results of each test.
npm build
Builds the library for production to the lib
folder.
It correctly bundles the library in production mode and optimizes the build for the best performance.
npm lint
Lints the project files.
Usage
JavaScript
const Redis = ;const RedCircle = ; // Maximum number of elements allowedconst CAPACITY = 1000; // Time to Live (TTL) in milliseconds, use 0 if you want to keep the list until it is deleted.const EXPIRES = 60000; // Instantiate RedCircleconst rcircle = client 'local:elements' CAPACITY EXPIRES; { // Clear the list await rcircleclear; // Get the size of the buffer const size = await rcirclesize; console; // 0 // Append elements to the buffer await rcircle; // Get the size of the buffer const size = await rcirclesize; console; // 10 // Get all elements in the buffer const elements = await rcircle; console; // ['9', '8', '7', '6', '5', '4', '3', '2', '1', '0'] // Get a range of elements in the buffer const slice = await rcircle; console; // ['9', '8', '7'] // Extend the Time to Live (TTL) if applicable await rcircle; // Clear the list await rcircleclear;}
TypeScript
; // Maximum number of elements allowed; // Time to live (TTL) in milliseconds, use 0 if you want to keep the list until it is deleted.; // Instantiate RedCircle;
License
MIT