BackendSession()

new BackendSession()

BackendSession is the proxy for the frontend internal session passed to handlers and it helps to keep the key/value pairs for the server locally. Internal session locates in frontend server and should not be accessed directly. The mainly operation on backend session should be read and any changes happen in backend session is local and would be discarded in next request. You have to push the changes to the frontend manually if necessary. Any push would overwrite the last push of the same key silently and the changes would be saw in next request. And you have to make sure the transaction outside if you would push the session concurrently in different processes. See the api below for more details.

Methods

bind(uid, cb)

Bind current session with the user id. It would push the uid to frontend server and bind uid to the frontend internal session.
Parameters:
Name Type Description
uid Number | String user id
cb function callback function

export()

Export the key/values for serialization.

get(key) → {Object}

Get the value from backend session by key.
Parameters:
Name Type Description
key String key
Returns:
Object - value

push(key, cb)

Push the key/value in backend session to the front internal session.
Parameters:
Name Type Description
key String key
cb function callback function

pushAll(cb)

Push all the key/values in backend session to the frontend internal session.
Parameters:
Name Type Description
cb function callback function

set(key, value)

Set the key/value into backend session.
Parameters:
Name Type Description
key String key
value Object value

unbind(uid, cb)

Unbind current session with the user id. It would push the uid to frontend server and unbind uid from the frontend internal session.
Parameters:
Name Type Description
uid Number | String user id
cb function callback function