How do I work with emacheache memcached using node.js

Hi, I am new to Memcached elastic with AWS. I found this plugin that gives me an array of hosts from the host configuration, but I'm not 100% sure that the best practices dictate. My code is like this ...

var Ecad = require('ecad');
var endpoints = ['memcached.w7sebn.cfg.usw2.cache.amazonaws.com:11211'];
var client = new Ecad({endpoints: endpoints, timeout: 10000});
client.fetch(function(err,hosts){console.log(err);console.log(hosts);});

Where console.log (hosts) outputs an array of nodes that I can probably use. Therefore, I have to implement my own hashing algorithm to determine which of the memcached nodes I connect and use as →

var Ecad = require('ecad');
var endpoints = ['memcached.w7sebn.cfg.usw2.cache.amazonaws.com:11211'];
var client = new Ecad({endpoints: endpoints, timeout: 10000});
client.fetch(function(err,hosts){
    var connectTo = hosts[parseInt(Math.random() * hosts.length)];
    var Memcached = require('memcached');
    // We can throw in options as a second parameter
    // For info please refer to:
    //
    // https://www.npmjs.com/package/memcached
    var memcached = new Memcached(connectTo);
    memcached.set("TestKey", "Memcache Works!", 100, function (err) {
        memcached.get("TestKey", function (err, data) {
            console.log(data);
        });
    });
});

Or is there more?

+4
source share

Source: https://habr.com/ru/post/1624706/


All Articles