Skip to content

Instantly share code, notes, and snippets.

@thoughtspeed7
Created September 5, 2021 12:39
Show Gist options
  • Save thoughtspeed7/3da2cb4d437d60a21870e132bbf302e0 to your computer and use it in GitHub Desktop.
Save thoughtspeed7/3da2cb4d437d60a21870e132bbf302e0 to your computer and use it in GitHub Desktop.
Connect To Redis Memorystore From Cloud Functions, Cloud Run and App Engine Using Serverless VPC Access | Google Cloud
// om namah shivaya
const { promisify } = require('util');
const redis = require('redis');
// replace 127.0.0.1 with your redis instance ip
const redisHost = '127.0.0.1';
const client = redis.createClient({
host: redisHost,
});
const incrAsync = promisify(client.incr).bind(client);
async function main(req, res) {
res.send(`counter: ${await incrAsync('counter')}`);
}
module.exports = {
main,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment