bool TSessionRedisStore::store(TSession &session) { QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << *static_cast<const QVariantMap *>(&session); data = qCompress(data, 1).toBase64(); #ifndef TF_NO_DEBUG { QByteArray badummy; QDataStream dsdmy(&badummy, QIODevice::ReadWrite); dsdmy << *static_cast<const QVariantMap *>(&session); TSession dummy; dsdmy.device()->seek(0); dsdmy >> *static_cast<QVariantMap *>(&dummy); if (dsdmy.status() != QDataStream::Ok) { tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized."); } } #endif TRedis redis; tSystemDebug("TSessionRedisStore::store id:%s", session.id().data()); return redis.setEx('_' + session.id(), data, lifeTimeSecs()); }
bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); #ifndef TF_NO_DEBUG { QByteArray badummy; QDataStream dsdmy(&badummy, QIODevice::ReadWrite); dsdmy << *static_cast<const QVariantMap *>(&session); TSession dummy; dsdmy.device()->seek(0); dsdmy >> *static_cast<QVariantMap *>(&dummy); if (dsdmy.status() != QDataStream::Ok) { tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized."); } } #endif QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantMap *>(&session); if (ds.status() != QDataStream::Ok) { tSystemError("Failed to store session. Must set objects that can be serialized."); return false; } if (so.isNull()) { so.id = session.id(); return so.create(); } return so.update(); }