Interactive analytics dashboards serve several purposes. They allow you to share data and provide you with all those vital information to make game-changing decisions at a faster pace. Building a real-time dynamic dashboard using a traditional relational database might require a complex set of queries. By using a NoSQL database like Redis, you can build a powerful interactive and dynamic dashboard with a small number of Redis commands.
Redis is an open source, in-memory, key-value data store most commonly used as a primary database, cache, message broker, and queue. Redis cache delivers sub-millisecond response times, enabling fast and powerful real-time applications in industries such as gaming, fintech, ad-tech, social media, healthcare, and IoT. This tutorial shows a basic analytics dashboard app writen in NodeJS (JavaScript) that uses the Redis Bitmap data type.
git clone https://github.com/redis-developer/basic-analytics-dashboard-redis-bitmaps-nodejsFirst we will be setting up some environment variables.
Go to /server folder (cd ./server) and then execute the following command:
cp .env.example .env npm install docker network create global
docker-compose up -d --buildYou may need to preface the docker command with sudo. If you don't want to use sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.
Once the Redis database is up and running, you can connect to it using the redis-cli command.
npm run devGo to /client folder (cd ./client) and then:
cp .env.example .env npm install npm run serveThe event data is stored in various keys and various data types.
For each of time spans:
and for each of scopes:
and for each of data types (types):
Is generated key like:
rab:{type}[:custom:{customName}][:user:{userId}][:source:{source}][:action:{action}][:page:{page}]:timeSpan:{timeSpan}where values in [] are optional.
INCR rab:count:action:addToCart:timeSpan:2015-12/3For each generated key like: rab:set:*, data is stored like: SADD {key} {userId} Example:
SADD rab:set:action:addToCart:timeSpan:2015-12/3 8For each generated key like rab:bitmap:*, data is stored like: SETBIT {key} {userId} 1. Example:
SETBIT rab:bitmap:action:addToCart:timeSpan:2015-12/3 8 1December:Â BITCOUNT rab:bitmap:custom:global:timeSpan:2015-12Â X week of December:Â BITCOUNT rab:bitmap:custom:global:timeSpan:2015-12/{X}Â Example:
BITCOUNT rab:bitmap:custom:global:timeSpan:2015-12/3December: BITCOUNT rab:bitmap:action:visit:page:{page}:timeSpan:2015-12Example:
BITCOUNT rab:bitmap:action:visit:page:homepage:timeSpan:2015-12BITCOUNT rab:bitmap:action:visit:page:{page}:timeSpan:2015-12/{X}Example:
BITCOUNT rab:bitmap:action:visit:page:product1:timeSpan:2015-12/2December:
BITCOUNT rab:bitmap:source:{source}:timeSpan:2015-12Example:
BITCOUNT rab:bitmap:source:referral:timeSpan:2015-12BITCOUNT rab:bitmap:source:{source}:timeSpan:2015-12/{X}Example:
BITCOUNT rab:bitmap:source:google:timeSpan:2015-12/1BITCOUNT rab:bitmap:action:visit:{page}:timeSpan:2015-12-01 to BITCOUNT rab:bitmap:action:visit:{page}:timeSpan:2015-12-31 BITCOUNT rab:bitmap:action:visit:homepage:timeSpan:2015-12-29 => BITCOUNT rab:bitmap:action:visit:homepage:timeSpan:2015-12-30 => BITCOUNT rab:bitmap:action:visit:homepage:timeSpan:2015-12-31GET rab:count:action:buy:timeSpan:2015-12 GET rab:count:action:buy:timeSpan:2015-12/{X} Example: GET rab:count:action:buy:timeSpan:2015-12/1December: GET rab:count:action:addToCart:timeSpan:2015-12 X week of December: GET rab:count:action:addToCart:timeSpan:2015-12/{X} Example:
GET rab:count:action:addToCart:timeSpan:2015-12/1December:Â GET rab:count:action:buy:page:{productPage}:timeSpan:2015-12Â Example:
GET rab:count:action:buy:page:product3:timeSpan:2015-12X week of December:Â GET rab:count:action:buy:page:{productPage}:timeSpan:2015-12/{X}Â Example:
GET rab:count:action:buy:page:product1:timeSpan:2015-12/2SMEMBERS rab:set:action:buy:page:{productPage}:timeSpan:2015-12Example:
SMEMBERS rab:set:action:buy:page:product2:timeSpan:2015-12SINTER rab:set:action:buy:page:product1:timeSpan:anytime rab:set:action:buy:page:product2:timeSpan:anytime