The Data Lab menu
  • Topicsarrow_drop_down
  • Projects
  • Aboutarrow_drop_down
  • Get Connected
  • Machine Learning for Developers
  • Notebooks for Developers
  • Offline First
  • Partners + Data
  • Serverless + Data
  • Working with JSON
  • Team
  • Get Involved
  • Code of Conduct
  • Event Support
  • Projects
  • Topicsarrow_drop_down
  • Aboutarrow_drop_down
  • Get Connected
  • Machine Learning for Developers
  • Notebooks for Developers
  • Offline First
  • Partners + Data
  • Serverless + Data
  • Working with JSON
  • Team
  • Get Involved
  • Code of Conduct
  • Event Support
Serverless + Data / Collection

Serverless + Redis

Functions, the perfect companion to any cache.

Lorna Mitchell
Incurable open source fanatic
More by Lorna Mitchell

When you have a serverless function, but need to stash the results somewhere for a quick moment, where do you turn?

Redis offers flexible levels of persistence and speedy performance. Serverless functions offer scalability without the infrastructure overhead. Together, they complement each other well.

Getting started with serverless

Platforms like Apache OpenWhisk let you write code in the language of your choice. For example, the documentation provides a “Hello World” function in JavaScript:

After installing wsk, the OpenWhisk CLI, you simply need to define your function as an action:

Invoke that action like so:

Using Redis from a serverless function

In my Alexa Project Codename example application, stashing data from a serverless function isn’t that much more involved. First I bundle up my required Node.js modules and my Redis parameters:

Then, I can use the node_redis client’s SET command, with node_redis for added asynchronous operation (as in client.setAsync(...)):

There’s a lot more you can do, so be sure to check these projects for more ideas.

↓ View projects in this collection

Projects

  • Add Redis To Your Serverless Application
    Medium | YouTube

    Use an in-memory datastore for a little light persistence.

    • OpenWhisk
    • Alexa
    • Redis
    • Compose
    • IBM Cloud Functions
    • Serverless
  • Going Serverless with IBM Cloud Functions and Compose Redis
    Compose Articles | GitHub | YouTube

    With OpenWhisk, database connections are simply packages of your favorite language-API combo.

    • Compose
    • Redis
    • OpenWhisk
    • IBM Cloud Functions
    • Serverless
    • Python
    • Alexa
  • Custom Indexers for Cloudant
    GitHub | Medium

    Using JavaScript and Redis for problems that don’t fit Cloudant’s indexing engines.

    • Cloudant
    • Compose
    • Redis
    • Nodejs
    • OpenWhisk
    • IBM Cloud Functions
    • Serverless
© 2017 IBM Watson Data Lab