Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // memcached set up
- var nMemcached = require('memcached');
- var memcached = new nMemcached(['192.168.200.3:11211']);
- // original data structure
- var room_tokens = {};
- // some initial game value
- var appinfo = 'poker'
- , token = 'ABCDEFGHI'
- , slots = 4
- , joining_time = 30000
- , display = 'display_' + token;
- // register to room_tokens to find it later & init room properties
- // INTENT TO DO
- room_tokens[token] = {
- slot_available: slots,
- slot_left: slots,
- joining_time_left: joining_time,
- user_list: {},
- game_state: 0//0: selection; 1: game started
- };
- // MEMCACHED APPROACH
- memcached.set(
- appinfo + '_' + token, {
- slot_available: slots,
- slot_left: slots,
- joining_time_left: joining_time,
- user_list: {},
- game_state: 0//0: selection; 1: game started
- },
- 10000,
- function(err, result){
- if(err) {
- console.error(err);
- }
- console.dir(result);
- }
- );
- // register display to the room for later fast duplicate name indexing
- // INTENT TO DO
- room_tokens[token]['user_list'][user_name] = display;
- // MEMCACHED APPROACH. This will result the object got wipe out to only user_list sub-object
- memcached.set(
- appinfo + '_' + token, {
- user_list: { ''+user_name: display }
- },
- 10000,
- function(err, result){
- if(err) {
- console.error(err);
- }
- console.dir(result);
- }
- );
- // note that I could memcached.get() then memcached.set() to do the updating,
- // but have to do it every time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement