After you've completed this micro-tutorial you'll be making requests to your Redis cache from serverless functions with OpenFaaS. From there it's up to you to build something awesome.
Deploy OpenFaaS and the faas-cli
.
This guide is for OpenFaaS on Kubernetes, but if you're using Swarm that's OK - you'll just have to adapt some of the commands for setting up Redis. The OpenFaaS code will be the same.
helm install stable/redis --name openfaas-redis --namespace openfaas-fn --set usePassword=false --set master.persistence.enabled=false
$ faas-cli new --lang node redis-fn --prefix docker-hub-name
# copy handler.js into ./redis-fn/
# copy package.json into ./redis-fn/
# Append to stack.yml
environment:
redis: openfaas-redis-master
$ faas-cli up
$ echo | faas-cli invoke redis-fn
$ kubectl port-forward --namespace openfaas-fn svc/openfaas-redis-master 6379:6379 &redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> GET mytime
"Thu Nov 01 2018 08:10:46 GMT+0000 (UTC)"
127.0.0.1:6379>
Now you can profit from using Redis from your functions.
You can read the docs about the Redis npm module here or join the OpenFaaS Slack community to boost your serverless journey.
Did you find that useful? Please share on Twitter or Tweet to @alexellisuk
Hi Alex,
Just checking, I think this tutorial is not intended for Arm-based architectures as the Redis helm chart cannot deploy Redis on arm machines if I am not mistaken.
Also, I see stable/redis repository is deprecated and bitnami/redis is encouraged.
Thanks,
Mohammad