Hi team I saw this line in a Java Project, here a java class will do session management for web users, this class call is requested by frontend to server, the session which is provided by server front end holds in a cookie for 30 min , and server also hold it for 30 min this session?
so my question is what Redis realtimeDataStats is doing here ? is is this going to provide a UI tool where we can saw the requested count of sessions something like ?
ContextSessionManagement.jedisPool = RedisConfigs.load().get("realtimeDataStats").getShardedJedisPool();
and how can we achieve this same thing in Python ?
Comment From: sundb
@prk2331 I'm not sure i can follow you. This code just gets the jredis connection pool. Perhaps you shall ask this question to the project you saw.
Comment From: prk2331
@sundb thanks for your giving me your time to reply (So this is only for developing the connection with redis) that project is not developing anymore by the contributors, I am going to developed it further but I'm stuck only in Redis concepts.
public static ContextSession initSession(final HttpServerRequest req, final MultiMap params, final DeviceInfo device) {
final String ip = RequestParamUtil.getRemoteIP(req);
// Trying to get remote IP from requested URL
final RedisCommand<ContextSession> cmd = new RedisCommand<ContextSession>(ContextSessionManagement.jedisPool) {
protected ContextSession build() throws JedisException {
ContextSession ctxSession = null;
final DateTime dateTime = new DateTime();
final String dateTimeKey = ContextSession.getSessionDateTimeKey(dateTime);
ctxSession = ContextSessionManagement.createWebContextSession(ip, params, device, dateTime, dateTimeKey);
if (ctxSession != null) {
final String newSessionKey = ctxSession.getSessionKey();
final String sessionJson = new Gson().toJson((Object)ctxSession);
final Pipeline p = this.jedis.pipelined();
p.set(newSessionKey, sessionJson);
p.expire(newSessionKey, 1800);
p.sync();
}
return ctxSession;
}
};
return (ContextSession)cmd.execute();
}
this is the guidance require that what above function do for us ? this is going to make the API faster we are maintaining everything it into the Pool is this is the correct understanding with Redis ? and what is this realtimeDataStats keyword used in this ?
Comment From: sundb
1) This code mainly creates a new session, and then uses SET command to store the sessionJson as a string to the newSessionKey, and sets the expiration time of newSessionKey to 1800 seconds (or perhaps some other unit).
2) If I'm right, realtimeDataStats is just the name of the connection pool, you can get the corresponding connection pool according to this name, and there may be other connection pools exist.