Giter Site home page Giter Site logo

pomelo-sync-redis's Introduction

#pomelo-sync-redis ##pomelo-sync

data sync module is simple sync memory data into store engine like mysql,redis,file.

As we known, updating data is very frequently in game application. Especial in MMORPG kind game. User game data,such as location,flood,equipment,etc. almost always change as time going. For the purpose of avoid such update action cost, we decide to keep a copy data in memory. And keep synchronized with a timer and log;

Data sync can support both timer call and instance invoke for the different
situation. Most of time the developer don't pay attention to it;

Data sync also can support memory operation like NOSQL database such as
redis,mongodb etc. most of time developer can seem as a memory database without
transaction.

Data sync features include timer sync,set,get,mset,mget,hset,hget,incr,decr,flush,merger,showdown,info,etc. and the developer can extend it very easily.

##Differenc from pomelo-sync pomelo-sync-redis is modified from pomelo-sync, there are serveral differences:

  1. pomelo-sync use javascript object to merger data, pomelo-sync-redis use a hash in redis to merger data.
  2. pomelo-sync use a self implement queue to store flush data, pomelo-sync-redis use a set in redis to store flush data.
  3. every pomelo-sync instace will execute sync job, pomelo-sync-redis can set which instance to execute sync job. and every instace can add job, which is like pomelo-sync.
  4. each pomelo-sync instance will not share data with other, pomelo-sync-redis can share and merger data through redis.
  5. pomelo-sync-redis can flush a part of data in mergerMap immediately. (through flushByUid method)

##Installation

npm install pomelo-sync-redis

##Usage

var opt = opt || {};

var updateUser = function(dbclient,val) {
    console.info('mock save %j',val);
}

var dbclient = {};//db connection etc;
var id = 10001;
var optKey = 'updateUser';
var mapping = {optKey:updateUer}; //key function mapping 
opt.mapping = mapping; 
opt.client = dbclient; // store engine client
opt.interval = 2000; // exec sync interval
opt.port = 6379; // redis server port
opt.host = "127.0.0.1" // redis server ip
var redisKeys = {
    MERGER_MAP_KEY: "POMELO:SYNC:MERGER:MAP", 
    USER_SET_KEY: "POMELO:SYNC:%s:SET", 
    FLUSH_SET_KEY: "POMELO:SYNC:FLUSH:SET"
    } // keys will used in redis
opt.keys = keys
opt.isSyncer = true // if ture, this pomelo sync instance will execute sync job at interval, default is false. At least one pomelo-sync-redis is set to syncer !!
var Sync = require('pomelo-sync-redis');
var sync = new Sync(opt) ;
sync.exec(optKey,id,{name:'hello'});

##API ###sync.exec(key,uid,id,val,cb) Add an object to sync for timer exec. ####Arguments

  • key - the key function mapping for wanted to call back,it must be unique.
  • uid - an id to identify group of data. [optional]
  • id - object primary key for merger operation.
  • val - the object wanted to synchronized.
  • cb - the function call back when the job is add (not executed !). [optional]

###sync.flush(key,uid,id,val,cb) immediately synchronized the memory data without waiting timer and will remove waiting queue data; ####Arguments

  • key - the key function mapping for wanted to call back,it must be unique.
  • uid - an id to identify group of data. [optional]
  • id - object primary key for merger operation.
  • val - the object wanted to synchronized.
  • cb - the function call back when timer exec. [optional]

###sync.isDone get the db sync status when the queue is empty,it should return true;otherwise return false;

###sync.flushByUid(uid,cb) immediately synchronized the memory data, which added from exec method with uid argument, without waiting timer and will remove waiting queue data; ####Arguments

  • uid - the uid used in exec and flush method
  • cb - callback function when all the sync job with uid is done. this modules do not support,user should realize it self.

##ADD for more usage detail , reading source and benchmark and test case from source is recommended;

pomelo-sync-redis's People

Contributors

jiangzhuo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.