This blog will set up a quick Node.js with Redis sample. We will do this the lazy Milky way – simply refactoring the existing OpenShift nodejs/mongodb template to work with Redis instead. This lab is another in the OpenShift MiniLabs series.
You are going to watch and learn how to create your own template.
We are going to need an instance of OpenShift to work with. You can do this using minishift or oc cluster up.
1. Create OpenShift Resources
The following instructions will create a project, import the nodejs-redis template and then create an application based on that template. The template was created by refactoring the nodejs/mongodb sample.
$ oc login -u developer -p developer $ oc delete project poc $ oc new-project poc --display-name='nodejs Redis PoC' --description='nodejs Redis Proof of Concept' $ oc create -f https://bitbucket.org/emergile/nodejs-redis-template/src/master/nodejs-redis-template.json $ oc new-app --template=nodejs-redis-template $ oc status
Wait a while for the build to complete. You can inspect progress by visiting the Console. Then point your Browser to the exposed route at e.g. http://nodejs-redis-example-poc.127.0.0.1.nip.io . The “Page view count” field on the landing page is set/get via Redis. Refresh the page a few times to validate connectivity and that the field is updated correctly, as per screen hot below. Review the Node.js code here.
$ curl http://nodejs-redis-example-poc.127.0.0.1.nip.io/
If the redis container has not been deployed as a result of the “oc new-app” call, visit the Console, select the “redis” and trigger the deployment interactively by clicking the Deploy button.