Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

using lambda for elasticache node.js

// npm i redis
// upload code from zip in lambda
const redis = require("redis");

const client = redis.createClient({
    host: 'YOUR REDIS HOST',
    port: 6379
});

export.handler = async () => {
    await storeValue('sampleKey', 'sampleValue');
    const value = await getValue('sampleKey');
    return value;
}

const getValue = key => {
    return new Promise((resolve, reject) => {
        client.get(key, (error, response) => {
            if (error)
                reject(error);
            else
                resolve(response);
        });
    });
}

const storeValue = (key, value) => {
    return new Promise((resolve, reject) => {
        client.set(key, value, (error, response) => {
            if (error)
                reject(error);
            else
                resolve(response);
        });
    });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #lambda #elasticache
ADD COMMENT
Topic
Name
5+1 =