MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / PythonSessionCtx_Deserialize

Function PythonSessionCtx_Deserialize

plugins/python/redisgears_python.c:927–1025  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925}
926
927static void* PythonSessionCtx_Deserialize(Gears_BufferReader* br, int version, char** err, bool useSessionsDict){
928 if(version > PY_SESSION_TYPE_VERSION){
929 *err = RG_STRDUP("unsupported session version");
930 return NULL;
931 }
932
933 char *id;
934 char *desc = NULL;
935 if (version < PY_SESSION_TYPE_WITH_NAMES) {
936 /* legacy id convert to str */
937 size_t len;
938 id = RedisGears_BRReadBuffer(br, &len);
939 RedisGears_ASprintf(&id, "%.*s-%lld", REDISMODULE_NODE_ID_LEN, id, *(long long*)&id[REDISMODULE_NODE_ID_LEN]);
940 } else {
941 id = RG_STRDUP(RedisGears_BRReadString(br));
942 }
943
944 if (version >= PY_SESSION_TYPE_WITH_DESC) {
945 if (RedisGears_BRReadLong(br)) {
946 // description exists
947 desc = RG_STRDUP(RedisGears_BRReadString(br));
948 }
949 }
950
951 PythonSessionCtx* s = currentSession;
952 if (s) {
953 s = PythonSessionCtx_ShallowCopy(s);
954 }
955 if (!s && useSessionsDict) {
956 s = PythonSessionCtx_Get(id);
957 }
958 bool sessionExists;
959 if(!s){
960 s = PythonSessionCtx_CreateWithId(id, desc, NULL, 0, false);
961 if (useSessionsDict) {
962 PythonSessionCtx_Set(s);
963 }
964 if(!s){
965 *err = RG_STRDUP("Could not create session");
966 return NULL;
967 }
968 sessionExists = false;
969 }else{
970 sessionExists = true;
971 }
972 RG_FREE(id);
973 RG_FREE(desc);
974 size_t withFullReqs = (version < PY_SESSION_TYPE_WITH_REQ_NAMES_ONLY);
975 if (version >= PY_SESSION_TYPE_WITH_OPTIONAL_REQS) {
976 withFullReqs = RedisGears_BRReadLong(br);
977 }
978 size_t requirementsLen = RedisGears_BRReadLong(br);
979 bool requirementsInstalled = false;
980 for(size_t i = 0 ; i < requirementsLen ; ++i){
981 PythonRequirementCtx* req;
982 if(!withFullReqs){
983 const char* reqName = RedisGears_BRReadString(br);
984 if(!sessionExists){

Callers 3

TimeEvent_RDBLoadFunction · 0.85

Tested by

no test coverage detected