This tutorial shows how to build a histogram API with Redis.
1
Create a Redis (Upstash) Database2
Serverless Project Setupnpm install -g serverless
In any folder run serverless
as below:
serverless.yml
as below. Copy your Redis URL from console and
replace below:
3
Codeget
takes name
as parameter and
loads a list from Redis. Then builds a histogram using the values in the list.
The record
function takes name
and values
as parameters. It adds the
values
to the Redis List with name name
.
The get
function calculates the histogram over the latest 10000 latency
records. Update the SIZE parameter to change this number.
The fixUrl
is a helper method which corrects the Redis url format.
4
Deploy and Try the APIperf-test-1
:
perf-test-1
: