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

Function atomicEnter

plugins/python/redisgears_python.c:2115–2135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2113} PyAtomic;
2114
2115static PyObject* atomicEnter(PyObject *self, PyObject *args){
2116 PythonThreadCtx* ptctx = GetPythonThreadCtx();
2117 if(ptctx->flags & PythonThreadCtxFlag_InsideAtomic){
2118 PyErr_SetString(GearsError, "Already inside an atomic block");
2119 return NULL;
2120 }
2121 ptctx->flags |= PythonThreadCtxFlag_InsideAtomic;
2122 PyAtomic* pyAtomic = (PyAtomic*)self;
2123 RedisGears_LockHanlderAcquire(pyAtomic->ctx);
2124 if (redisVersion->redisMajorVersion < 7) {
2125 /* Before Redis 7 we need to manually wrap the atomic
2126 * execution with multi exec to make sure the replica
2127 * will also perform the commands atomically.
2128 * On Redis 7 and above, thanks to this PR:
2129 * https://github.com/redis/redis/pull/9890
2130 * It is not needed anymore. */
2131 RedisModule_Replicate(pyAtomic->ctx, "multi", "");
2132 }
2133 Py_INCREF(self);
2134 return self;
2135}
2136
2137static PyObject* atomicExit(PyObject *self, PyObject *args){
2138 PythonThreadCtx* ptctx = GetPythonThreadCtx();

Callers

nothing calls this directly

Calls 1

GetPythonThreadCtxFunction · 0.85

Tested by

no test coverage detected