sn_session - Implement sessions for Extenso
sn_session_get(key:string[, db: string]);
sn_session_set(key:string,value:string[,exp:string,db:string]);
sn_session_del(keys:string[db:string]);
sn_session_exp([db:string]);
These functions are used to implement a session.
session_set get the current session cookie, the key passed in parameter and the expiration date if any and save the value in the database. If the key already exist, it is replace.
The database right now is mariadb and the table is sn_sessions. If the parameter db is used, than the database will be a key/data database which is at least 5 times faster than mariadb.
session_get retrive a value corresponding to the key and the cookie of the user.
session_del is used to delete keys from the database.
session_exp is used to remove expire keys from the database.
{{ %include "/extenso/functions/sn_session.snc"; }} \{{ sn_session_set("captcha",c[1], exp:"+300s"); sn_session_get("captcha"); sn_session_del("key1","key2"); a=time(); sn_session_exp(db:"/hash/session.db"); key = random(min:1, max:1000, init:true, seed:1); value = sn_session_get(db:"/hash/session.db", key); n=0; for (i=1;i<10000;++i) do key = random(min:1, max:1000); value = sn_session_get(db:"/hash/session.db", key); if value == null then value = random(min:1, max:1000); sn_session_set(key,value,db:"/hash/session.db"); else n++; endif endfor b=time(); d = (b.secs - a.secs) * 1000000; d += (b.msecs - a.msecs) * 1000; d += (b.usecs - a.msecs); s = d / 1000000; tmp = s * 1000000; d = d - tmp; ms = d / 1000; tmp = ms * 1000; d = d - tmp; "test1: "; s; ":"; ms; ":"; d; ","; n; }}
Written by Pierre Laplante
1.0 2014-09-09 21:24:14 laplante@sednove.com