moonlight_function_common

1.1.2 • Public • Published

This is a function from Moonlight

Prerequisite:

Rewquire: moonlight_function_errplace use: npm install moonlight_function_errplace
Require: ioredis use: npm install ioredis

Quick Start

install

npm install moonlight_function_common

Basic Usage

Https

get

get(host, url,function(callback){
    ......
});

post

post data to htpps://host+url (data must be string format)

var host = "qyapi.weixin.qq.com";
var url = "/cgi-bin/user/create?access_token=" + access_token;
var content=JSON.stringify(data);
post(host, url,content,function(resutl){
    console.log(page_name+":the post result: "+result);

});

Mongodb

Method insert

var com=require('moonlight_function_common');
var mongodb = com.mongodb;
mongodb.insert (document)  {
      ......
 }
 mongodb.insert (document , options)  {
      ......
 }
 mongodb.insert (document , function (err,result)  {
      ......
 }
 mongodb.insert (document, options , function (err,result)  {
     ......
}

Redis

var com=require('moonlight_function_common');
var redis=com.redis;

set_key:

redis.setex_key(key,seconds,value);    //Such as redis.setex_key(key,7200,access_token);     // 7200seconds

//put value in redis by key_name key, expire time seconds.

get_key:

get a value from redis by the key_name key, the value callback in the result. if result is NULL, is means that there is not a vaule in redis by the key_name key. Such as:

redis.getkey(key,function(result){
    access_token_callback(result);
});

Package Sidebar

Install

npm i moonlight_function_common

Weekly Downloads

0

Version

1.1.2

License

UNLICENSED

Unpacked Size

1.08 MB

Total Files

61

Last publish

Collaborators

  • menghuiqiang999