Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Last active September 18, 2019 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoff-it/02184cb8a37c470409a97e1560ead37f to your computer and use it in GitHub Desktop.
Save kristoff-it/02184cb8a37c470409a97e1560ead37f to your computer and use it in GitHub Desktop.
// Connection info, a URI with this shape:
// [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]
const REDIS_URI = process.env.REDIS_URI;
// Redis client library
const redis = require('redis');
// Client instance
const r = redis.createClient(REDIS_URI);
// Promisify get and set
const { promisify } = require('util');
const setAsync = promisify(r.set).bind(r);
const getAsync = promisify(r.get).bind(r);
// This is the lambda function:
exports.handler = async function(event, context) {
console.log("EVENT: \n" + JSON.stringify(event, null, 2))
// Set a key
await setAsync("mykey", "hello world");
// Return the value to the caller
return getAsync("mykey");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment