| 5805 | } |
| 5806 | |
| 5807 | static Record* RedisGearsPy_PyCallbackReducer(ExecutionCtx* rctx, char* key, size_t keyLen, Record *records, void* arg){ |
| 5808 | RedisModule_Assert(RedisGears_RecordGetType(records) == RedisGears_GetListRecordType()); |
| 5809 | |
| 5810 | PythonSessionCtx* sctx = RedisGears_GetFlatExecutionPrivateData(rctx); |
| 5811 | RedisModule_Assert(sctx); |
| 5812 | |
| 5813 | PythonExecutionCtx pectx = PythonExecutionCtx_New(sctx, rctx); |
| 5814 | RedisGearsPy_Lock(&pectx); |
| 5815 | |
| 5816 | PyObject* obj = PyList_New(0); |
| 5817 | for(size_t i = 0 ; i < RedisGears_ListRecordLen(records) ; ++i){ |
| 5818 | Record* r = RedisGears_ListRecordGet(records, i); |
| 5819 | RedisModule_Assert(RedisGears_RecordGetType(r) == pythonRecordType); |
| 5820 | PyObject* element = PyObjRecordGet(r); |
| 5821 | PyList_Append(obj, element); |
| 5822 | } |
| 5823 | PyObject* reducer = arg; |
| 5824 | PyObject* pArgs = PyTuple_New(2); |
| 5825 | PyObject* keyPyObj = PyUnicode_FromString(key); |
| 5826 | PyTuple_SetItem(pArgs, 0, keyPyObj); |
| 5827 | PyTuple_SetItem(pArgs, 1, obj); |
| 5828 | if (RedisGears_ProfileEnabled()) { |
| 5829 | // start profiling |
| 5830 | PyObject_CallFunction(profileStartFunction, "O", sctx->profiler); |
| 5831 | } |
| 5832 | PyObject* ret = PyObject_CallObject(reducer, pArgs); |
| 5833 | if (RedisGears_ProfileEnabled()) { |
| 5834 | // start profiling |
| 5835 | PyObject_CallFunction(profileStopFunction, "O", sctx->profiler); |
| 5836 | } |
| 5837 | GearsPyDecRef(pArgs); |
| 5838 | |
| 5839 | if(ret && PyCoro_CheckExact(ret)){ |
| 5840 | GearsPyDecRef(ret); |
| 5841 | RedisGears_SetError(rctx, RG_STRDUP("coroutine are not allow on reduce")); |
| 5842 | RedisGearsPy_Unlock(&pectx); |
| 5843 | RedisGears_FreeRecord(records); |
| 5844 | return NULL; |
| 5845 | } |
| 5846 | |
| 5847 | if(!ret){ |
| 5848 | fetchPyError(rctx); |
| 5849 | |
| 5850 | RedisGearsPy_Unlock(&pectx); |
| 5851 | RedisGears_FreeRecord(records); |
| 5852 | return NULL; |
| 5853 | } |
| 5854 | Record* retRecord = PyObjRecordCreate(); |
| 5855 | PyObjRecordSet(retRecord, ret); |
| 5856 | |
| 5857 | RedisGearsPy_Unlock(&pectx); |
| 5858 | RedisGears_FreeRecord(records); |
| 5859 | return retRecord; |
| 5860 | } |
| 5861 | |
| 5862 | static Record* RedisGearsPy_ToPyRecordMapperInternal(ExecutionCtx* rctx, Record *record, void* arg){ |
| 5863 | Record* res = PyObjRecordCreate(); |
nothing calls this directly
no test coverage detected