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

Function PythonRecord_SendReply

plugins/python/redisgears_python.c:6945–6988  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6943}
6944
6945static int PythonRecord_SendReply(Record* r, RedisModuleCtx* rctx){
6946 PyObject* obj = PyObjRecordGet(r);
6947 if(PyList_Check(obj)){
6948 size_t listLen = PyList_Size(obj);
6949 Record* rgl = RedisGears_ListRecordCreate(listLen);
6950 for(int i = 0 ; i < listLen ; ++i){
6951 Record* temp = PyObjRecordCreate();
6952 PyObject* pItem = PyList_GetItem(obj, i);
6953 PyObjRecordSet(temp, pItem);
6954 Py_INCREF(pItem);
6955 RedisGears_ListRecordAdd(rgl, temp);
6956 }
6957 RedisGears_RecordSendReply(rgl, rctx);
6958 RedisGears_FreeRecord(rgl);
6959 }else if(PyLong_Check(obj)) {
6960 RedisModule_ReplyWithLongLong(rctx, PyLong_AsLongLong(obj));
6961 }else if(PyFloat_Check(obj)){
6962 double d = PyFloat_AsDouble(obj);
6963 RedisModuleString* str = RedisModule_CreateStringPrintf(NULL, "%lf", d);
6964 RedisModule_ReplyWithString(rctx, str);
6965 RedisModule_FreeString(NULL, str);
6966 }else if(PyUnicode_Check(obj)) {
6967 size_t len;
6968 char* str = (char*)PyUnicode_AsUTF8AndSize(obj, &len);
6969 if(len > 1){
6970 if(str[0] == '+'){
6971 RedisModule_ReplyWithSimpleString(rctx, str + 1);
6972 return REDISMODULE_OK;
6973 }else if(str[0] == '-'){
6974 RedisModule_ReplyWithError(rctx, str + 1);
6975 return REDISMODULE_OK;
6976 }
6977 }
6978 RedisModule_ReplyWithStringBuffer(rctx, str, len);
6979 }else if(PyBytes_Check(obj)) {
6980 size_t len;
6981 char* str;
6982 PyBytes_AsStringAndSize(obj, &str, &len);
6983 RedisModule_ReplyWithStringBuffer(rctx, str, len);
6984 }else{
6985 RedisModule_ReplyWithStringBuffer(rctx, "PY RECORD", strlen("PY RECORD"));
6986 }
6987 return REDISMODULE_OK;
6988}
6989
6990static int PythonRecord_Serialize(ExecutionCtx* ectx, Gears_BufferWriter* bw, Record* base){
6991 PythonRecord* r = (PythonRecord*)base;

Callers

nothing calls this directly

Calls 3

PyObjRecordGetFunction · 0.85
PyObjRecordCreateFunction · 0.85
PyObjRecordSetFunction · 0.85

Tested by

no test coverage detected