npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-contentful

v2.2.5

Published

A tiny library to map Contentful ☁️ space into Redis ⚡️

Downloads

42

Readme

Redis Contentful npm license

A tiny library to map Contentful ☁️ space into Redis ⚡️

Why should I care?

Say your marketing team loves to update content without you being involved? Great! That is why you should use Contentful CMS. But wait, there is a catch. Contentful API sometimes takes ~800ms. And this is really a hit when you're having fancy SSR implemented to boost the performance of your Node JS app. As the creator of Gmail, Paul Buchheit had said "Every interaction should be faster than 100ms. Why? Because 100ms is the threshold where interactions feel instantaneous".

This is where redis will help you crunch the rendering speed. It's really, really fast! A few ms is all it needs to get your data. By few, I mean less than 100ms 🚀

redis-contentful maps your Contentful space's content types and their published records into your Redis server. It also maintains the schema of your Contentful space. All content types are stored in Redis as hashes. Under a particular hash, the record is stored as a key value pair with id being the record's key.

You can sync the data manually by calling the sync method on redis-contentful instance manually or you can add a webhook in Contentful by exposing an endpoint on your server which will internally call sync. In this way, you always have the latest content from Contentful right in your Redis. So let's get started!

Installation

npm install redis-contentful --save

Usage

Create an instance of redis-contentful by passing contentful space ID & access token.

import RedisContentful from 'redis-contentful';

const client = new RedisContentful({
  redis: {
    database: 0, // Optional param, default - 0
    host: '', // Optional param, default - 127.0.0.1
    port: '', // Optional param, default - 6379
  },
  contentful: {
    space: '',
    accessToken: '',
    locale: '', // Optional param, default - en-US
    identifier: '', // Identifier for searching custom keys,
    environment: '', // contentful environment, default is master
  },
});

API

sync

Syncs the latest space content from Contentful and dumps it in your Redis server 🎉

await client.sync();

Send an optional boolean param to sync if you want to reset your redis cache ♻️

await client.sync(true);

get - directly from Redis 🚀

Gets all data

await client.get();

Pass specific content type. It's an optional parameter.

await client.get('about');

Pass an array specifying the required content types

await client.get(['about', 'title']);

Pass an object to narrow down search

await client.get({
  // Content type, it can also be an array
  type: '',

  // This will search identifier key for specified value
  search: '',
});

You'll get an object with your content type ID's as keys and their values as array of content objects. If you specify a specific key, only that key will be returned in the final object.

{
    "<a-key>": [{}, {}, {}],
    "<yet-another-key>": [{}, {}]
}

Custom keys in Redis

Set, get & delete your custom key - value pairs in Redis

await client.setCustom('avengers', '🤯');
/* can set expire time in seconds. Third parameter is optional */
await client.setCustom('Hulk', "I'm Hulk!", 60);
await client.getCustom('avengers'); // 🤯
await client.deleteCustom('avengers');

Changing Redis DB

// Sets DB to specified value, default is 0
await client.setDB();

close

Closes the connection to redis client.

await client.close();

Redis Store

In Redis, the keys (entries) will be prefixed with their respective content type 🤓

License

MIT ❤