controlled-list

creates lists with a limited number of elements. and deletes the list when the limit is exceeded.

Usage no npm install needed!

<script type="module">
  import controlledList from 'https://cdn.skypack.dev/controlled-list';
</script>

README

Build Status

  • promise supports
  • ttl support

install

npm i controlled-list --save

usage

const cl = require('controlled-list');

(async () => {
  const connector = await cl({
    client: {
      // redis configuration ..
    }
  });

  const list = connector('liiiist', {
    limit: 5,
    ttl: 10
  })

  console.log(await list.add(1)); // true
  console.log(await list.add(2)); // true
  console.log(await list.add(3)); // true
  console.log(await list.check()); // true
  console.log(await list.add(4)); // true
  console.log(await list.check()); // false
  console.log(await list.add(5)); // false

  console.log(await list.length()); // 4
  await list.clear()
  console.log(await list.length()); // 0
})();
  • add adds new element to list

  • length number of elements in the list

  • check checks the list limit. false if the limit is exceeded.

  • clear delete the list