Store the session data in redis

        :param method callback: The callback method to invoke when done
197864
def save(self):
        
        result = yield gen.Task(RedisSession._redis_client.set,
                                self._key, self.dumps())
        LOGGER.debug('Saved session %s (%r)', self.id, result)
        raise gen.Return(result)
1297173
function getBytes(key, callback) {
	this.redisClient.get(key, function(err, valueBytes) {
		if (err) { return callback(err) }
		if (!valueBytes) { return callback(null, null) }
		callback(null, valueBytes.toString())
	})
}
150164
function (method, result) {

      // result should not be undefined
      if (result === undefined) {
        console.warn('JSON-RPC2 response from method ' + methodName + ' should return a result. (JSON-RPC2 spec)')
        result = ''
      }

      var rpcMessage = {
        jsonrpc: '2.0',
        result: result,
        id: id
      }

      callback(rpcMessage)
      responseHasBeenSent = true

    }
1073383
private void saveSession(Session session) throws UnknownSessionException{
		if(session == null || session.getId() == null){
			logger.error("session or session id is null");
			return;
		}
		
		byte[] key = getByteKey(session.getId());
		byte[] value = SerializeUtils.serialize(session);
		
		
		session.setTimeout(this.getExpire()*1000);		
		
		if(redisTemplate!=null) {
			redisTemplate.opsForValue().set(getKey(session.getId()), value, this.getExpire(), TimeUnit.SECONDS);
		}else {
			this.redisManager.set(key, value, this.getExpire());
		}
		
	}
866347
function(opts, callback) {
  if (callback === undefined) {
    throw new Error('callback undefined in $fh.cache. See documentation of $fh.cache for proper usage');
  }

  if (opts.act === undefined) {
    return callback('No cache actions defined!');
  }

  var fullKey = appname + opts.key;

  if (opts.act === 'save') {
    memcached.set(fullKey, opts.value, opts.expire || 0, function(err) {
      if (err) {
        return callback(err);
      }
      // To keep the same api response as redis implemenation, use 'OK' if successfully saved
      return callback(null, 'OK');
    });
  } else if (opts.act === 'load') {
    memcached.get(fullKey, function(err, data) {
      // To keep the same api response as redis implemenation, use null instead of undefined
      if (err) {
        return callback(err);
      }
      return callback(null, data || null);
    });
  } else if (opts.act === 'remove') {
    memcached.del(fullKey, function(err) {
      if (err) {
        return callback(err);
      }
      // To keep the same api response as redis implementation, use null & 1 if successfully removed
      return callback(null, 1);
    });
  } else {
    return callback("Unknown cache action: " + opts.act);
  }
}
461204
function(callback) {
            var that = this;
            var url = this.paths.login;
            var params = {
                username: this.username,
                password: this.password,
                cookie  : '1'
            };

            callback = callback || function() {};
            var wrappedCallback = function(err, response) {
                // Let's make sure that not only did the request succeed, but
                // we actually got a non-empty session key back.
                var hasSessionKey = !!(!err && response.data && response.data.sessionKey);

                if (err || !hasSessionKey) {
                    callback(err || "No session key available", false);
                }
                else {
                    that.sessionKey = response.data.sessionKey;
                    callback(null, true);
                }
            };

            return this.http.post(
                this.urlify(url),
                this._headers(),
                params,
                this.timeout,
                wrappedCallback
            );
        }
92103
function (when, methodName, record) {
            var callbacks = registry[when][methodName]
            for (var i = 0, l = callbacks.length; i < l; i++) {
                callbacks[i].call(this, record)
            }
        }
1294746
def validate_callback_data(method):
    
    @wraps(method)
    def method_wrapper(*args, **kwargs):
        """

        Parameters
        ----------
        *args
        **kwargs

        Returns
        -------
        method's output
        """
        expected = method.__code__.co_varnames

        # rename curret gam object
        if 'self' in kwargs:
            gam = kwargs['self']
            del(kwargs['self'])
            kwargs['gam'] = gam

        # loop once to check any missing
        missing = []
        for e in expected:
            if e == 'self':
                continue
            if e not in kwargs:
                missing.append(e)
        assert len(missing) == 0, 'CallBack cannot reference: {}'.\
                                  format(', '.join(missing))

        # loop again to extract desired
        kwargs_subset = {}
        for e in expected:
            if e == 'self':
                continue
            kwargs_subset[e] = kwargs[e]

        return method(*args, **kwargs_subset)

    return method_wrapper
604978
def get_session_value(self, name, default=None):
        """"""

        value = self.redis().hget(self._session_key, name) or default
        self._update_session_expiration()
        return value
740171
function callEntityMethod(req, res, next) {
  var payload = req.payload;
  var method = req.serversideMethod;

  if (req.hasCallback) {

    debug('Transforming callback function');
    payload[req.clientCallbackIndex] = function(err) {
      if (err) {
        return next(err);
      }

      var values = Array.prototype.slice.call(arguments).slice(1);

      debug('Callback function called. Values are:', values);

      res.entityResponse = values;

      next();
    };
  }

  debug('Calling ' + req.path + ' with arguments:', payload);

  var context = {
    req: req,
    xhr: true,
    setCookie: res.cookie.bind(res),
    clearCookie: res.clearCookie.bind(res)
  };

  var ret;

  // Calls the requested serverside method.
  // Applies the payload, and provides a context for validation purposes.
  // Caches errors in the method's scope, and sends it to the next error handler.
  try {
    ret = method.apply(context, payload);
  } catch(err) {
    return next(err);
  }

  if (util.isPromise(ret)) {
    ret.then(function(resolved) {
      res.entityResponse = [resolved];
      next();
    })
    .catch(function(err) {
      next(err);
    });
  }

  // If the request is not expecting the response from the entity,
  // send a generic 'Ok' response.
  else if (!req.hasCallback) {
    res.entityResponse = [ret];
    debug('Not asynchronous. Returning value: ', res.entityResponse);
    next();
  }
}
53811
function queue(task, done) {
    var storage = this,
        key = this.keygen(task);

    // store task as JSON serialized string
    task = JSON.stringify(task);

    // first add the key to the queue
    this.redis().rpush(this.queueKey(), key, function(err) {
        if (err) done(err);

        // now store task data
        else storage.redis().set(key, task, function(err) {
            if (err) done(err);
            else done(null, key);
        });
    });
}
57124
private <T> T execute(RedisCallBack<T> redisCallBack, List<RedisClient> clients, Object key, boolean isRead) {
        for (int i = 0; i < getRetryTimes(); i++) {
            boolean result = redisCallBack.doInRedis(clients, isRead, key);
            if (result) {
                return redisCallBack.getResult();
            }
        }

        Throwable e = redisCallBack.getException();
        if (e != null) {
            logger.error("Return null because exception occurs: " + e.getMessage(), e);
        }
        return null;
    }
242782
function(callback){
        callback = callback || noop;

        if(!this._client){
            return callback();
        }
        this._client.shutdown(function(err){
            if(!this._define_connection){
                return callback(err);
            }
            this._define_connection.shutdown(function(derr){
                callback(err || derr);
            });
        }.bind(this));
    }
175263
def set_session_value(self, name, value):
        """"""

        self.redis().hset(self._session_key, name, value)
        self._update_session_expiration()
1056756
function(err, results) {

        if (!err) {

          self.sessionSubscriber = new SessionSubscriber(
            self.conf && self.conf.redis && self.conf.redis ? self.conf.redis : undefined,
            self.serverName,
            function(err) {
              if (!err) {

                console.info(' (init) REDIS     is connected  (for pub/sub)');
                console.info('        REDIS     is subscribed (C-' + self.serverName + ')');

                self._startup(server, io);

                if (cb) cb();

              } else {
                console.error(err);
                process.exit(1);
              }
            }
          );

        } else {

          for (var errNum in results) {
            if (results.hasOwnProperty(errNum) && results[errNum]) {
              console.error('  - ' + results[errNum] + '\n');
            }
          }
          process.exit(1);
        }
      }
973372
function initRedis(config, callback) {

  var self = this;

  protos.util.checkLocalPort(config.port, function(err) {

    if (err) {
      app.log("RedisTransport [%s:%s] %s", config.host, config.port, err.code);
    } else {

      // Set redis client
      self.client = redis.createClient(config.port, config.host, self.options);

      // Handle error event
      self.client.on('error', function(err) {
        callback.call(self, err);
      });

      // Authenticate if password provided
      if (typeof config.password == 'string') {
        self.client.auth(config.password, function(err, res) {
          if (err) {
            app.log("RedisTransport: [%s:%s] %s", config.host, config.port, err.code);
          } else if (typeof config.db == 'number' && config.db !== 0) {
            self.client.select(config.db, function(err, res) {
              if (err) callback.call(self, err);
              else callback.call(self, null);
            });
          } else {
            callback.call(self, null);
          }
        });
      } else if (typeof config.db == 'number' && config.db !== 0) {
        self.client.select(config.db, function(err, res) {
          callback.call(self, err);
        });
      } else {
        callback.call(self, null);
      }

    }
  });

}
516182
function(prevHandler, connection, parsed, data, callback) {
            if (hasCondstoreOption(parsed.attributes && parsed.attributes[1], parsed.attributes, 1)) {
                connection.sessionCondstore = true;
            } else if ('sessionCondstore' in connection) {
                connection.sessionCondstore = false;
            }
            prevHandler(connection, parsed, data, callback);
        }