How to use the memjs.Client function in memjs

To help you get started, we’ve selected a few memjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AstroCB / AssumeZero-Bot / src / archive.js View on Github external
/*
By default, this file will take all existing group data from the database
and add it to the archive in the file called archive.json.

However, if called with the "--restore" flag, it will instead use the data
stored in the archive to replace the data in the database (in case of memory
loss). This essentially restores the database from backup.
*/
const fs = require("fs");
const credentials = require("./credentials") || process.env;
const mem = require("memjs").Client.create(credentials.MEMCACHIER_SERVERS, {
    username: credentials.MEMCACHIER_USERNAME,
    password: credentials.MEMCACHIER_PASSWORD
});

if (process.argv[2] == "--restore") { // Check command-line arguments
    // Restore database from archive
    console.log("Restoring...");
    fs.readFile("archive.json", (err, stored) => {
        if (!err) {
            mem.set("groups", stored.toString(), {}, (err) => {
                if (!err) {
                    console.log(`Data restored from backup:`, JSON.parse(stored));
                } else {
                    console.log(`Error: ${err}`);
                }
                process.exit();
github AstroCB / AssumeZero-Bot / src / logout.js View on Github external
var credentials;
try {
    // Login creds from local dir
    credentials = require("./credentials");
} catch (e) {
    // Deployed to Heroku or config file is missing
    credentials = process.env;
}

// External storage API (Memcachier) (requires credentials)
const mem = require("memjs").Client.create(credentials.MEMCACHIER_SERVERS, {
    "username": credentials.MEMCACHIER_USERNAME,
    "password": credentials.MEMCACHIER_PASSWORD
});

mem.delete("appstate", err => {
    if (err) {
        console.log(`Error logging out: ${err}`);
    } else {
        console.log("Logged out successfully.");
    }
    process.exit();
});
github AstroCB / AssumeZero-Bot / src / login.js View on Github external
const messenger = require("facebook-chat-api"); // Chat API
const fs = require("fs");
const config = require("./config");
var credentials;
try {
    // Login creds from local dir
    credentials = require("./credentials");
} catch (e) {
    // Deployed to Heroku or config file is missing
    credentials = process.env;
}

// External storage API (Memcachier) (requires credentials)
const mem = require("memjs").Client.create(credentials.MEMCACHIER_SERVERS, {
    "username": credentials.MEMCACHIER_USERNAME,
    "password": credentials.MEMCACHIER_PASSWORD
});

exports.login = (callback) => {
    function withAppstate(appstate, callback) {
        console.log("Logging in with saved appstate...");
        messenger({
            appState: JSON.parse(appstate)
        }, (err, api) => {
            if (err) {
                withCreds(callback);
            } else {
                callback(err, api);
            }
        });
github AstroCB / AssumeZero-Bot / src / main.js View on Github external
const utils = require("./utils"); // Utility functions
const commands = require("./commands"); // Command documentation/configuration
const runner = require("./runcommand"); // For command handling code
const _ = require("./server"); // Server configuration (just needs to be loaded)
const easter = require("./easter"); // Easter eggs
const passive = require("./passive"); // Passive messages
let credentials;
try {
    // Login creds from local dir
    credentials = require("./credentials");
} catch (e) {
    // Deployed to Heroku or config file is missing
    credentials = process.env;
}
// External storage API (Memcachier) (requires credentials)
const mem = require("memjs").Client.create(credentials.MEMCACHIER_SERVERS, {
    "username": credentials.MEMCACHIER_USERNAME,
    "password": credentials.MEMCACHIER_PASSWORD
});
var gapi; // Global API for external functions (set on login)
var stopListening; // Global function to call to halt the listening process

// Log in
if (require.main === module) { // Called directly; login immediately
    console.log(`Bot ${config.bot.id} logging in ${process.env.EMAIL ? "remotely" : "locally"} with trigger "${config.trigger}".`);
    botcore.login.login(credentials, main);
}

// Listen for commands
function main(err, api) {
    if (err) return console.error(err);
    console.log(`Successfully logged in to user account ${api.getCurrentUserID()}.`);
github ello / webapp / src / server / iso.js View on Github external
console.log(error.stack)
    throw error
  }
}
process.on('uncaughtException', handleZlibError)

// load env vars first
require('dotenv').load({ silent: process.env.NODE_ENV === 'production' })
global.ENV = require('./../../env')

updateTimeAgoStrings({ about: '' })

const app = express()
const preRenderTimeout = (parseInt(process.env.PRERENDER_TIMEOUT, 10) || 15) * 1000
const memcacheDefaultTTL = (parseInt(process.env.MEMCACHE_DEFAULT_TTL, 10) || 300)
const memcacheClient = memjs.Client.create(null, { expires: memcacheDefaultTTL })
const queue = kue.createQueue({ redis: process.env[process.env.REDIS_PROVIDER] })

// Set up CORS proxy
const proxy = httpProxy.createProxyServer({
  target: process.env.AUTH_DOMAIN,
  changeOrigin: true,
})

// Honeybadger "before everything" middleware
app.use(Honeybadger.requestHandler);

// Log requests with Heroku's logfmt
app.use(logfmt.requestLogger({ immediate: false }, (req, res) => {
  const data = logfmt.requestLogger.commonFormatter(req, res)
  data.useragent = req.headers['user-agent']
  return data
github AstroCB / AssumeZero-Bot / src / configutils.js View on Github external
// Utility functions for config file
var credentials;
try {
    // Login creds from local dir
    credentials = require("./credentials");
} catch (e) {
    // Deployed to Heroku or config file is missing
    credentials = process.env;
}
const fs = require("fs");
const mem = require("memjs").Client.create(credentials.MEMCACHIER_SERVERS, {
    username: credentials.MEMCACHIER_USERNAME,
    password: credentials.MEMCACHIER_PASSWORD
});

exports.getRegexFromMembers = (names) => {
    let regstr = "(";
    for (let i = 0; i < names.length; i++) {
        regstr += names[i];
        regstr += "|";
    }
    regstr += "me)" // Include "me" for current user
    // Final format: (user1|user2|user3|usern|me)
    return regstr;
}

// Returns whether the passed user ID is in the members object
github open-city / recycling / routes / reports.js View on Github external
var async = require('async')
  , cache = require('memjs').Client.create()
  , Location = require('../models/Location')
  , Report = require('../models/Report')
  ;


exports.index = function(req, res){
  var query = {};
  var location = req.query.location;
  if(location){
    query = {'location': location };
  }
  Report.find(query, function(err, reports){
    res.json({'reports': reports});
  })
};
github msfidelis / boreal / src / libs / cache / strategies / memcached.js View on Github external
var connection = function (server, port) {
    return memjs.Client.create(server + ":" + port)
}
github ForgeRock / node-openam-agent / lib / cache.js View on Github external
function MemcachedCache(options) {
    options = options || {};

    this.client = memjs.Client.create(options.url || 'http://localhost/11211');
    this.expireAfterSeconds = options.expireAfterSeconds || 60;
}
github open-city / recycling / models / Ward.js View on Github external
var mongoose = require('mongoose')
  , Schema = mongoose.Schema
  , async = require('async')
  , cache = require('memjs').Client.create()
  ;


var WardSchema = new Schema({

  number: {
    type: Number,
    index: true,
    required: true
  },

  centroid: {
    type: "Mixed",
    required: true,
    index: '2dsphere'
  },

memjs

A memcache client for node using the binary protocol and SASL authentication

MIT
Latest version published 12 months ago

Package Health Score

70 / 100
Full package analysis