592056897b
- aggiunta funzione per ricavare i parametri da stringa di connessione per hiredis.
195 lines
5.7 KiB
C++
195 lines
5.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2025-2025
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_Redis.cpp Data : 17.09.25 Versione : 2.7i3
|
|
// Contenuto : Funzioni per interfacciarsi con server Redis.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 17.09.25 RE Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisConnect( lua_State* L)
|
|
{
|
|
// 1 parametro : sConnection
|
|
string sConnection ;
|
|
LuaCheckParam( L, 1, sConnection)
|
|
LuaClearStack( L) ;
|
|
// Imposto la connessione
|
|
bool bOk = ExeRedisConnect( sConnection) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisDisconnect( lua_State* L)
|
|
{
|
|
// Nessun paramtro
|
|
LuaClearStack( L) ;
|
|
// Imposto la connessione
|
|
bool bOk = ExeRedisDisconnect() ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisSetValFromKey( lua_State* L)
|
|
{
|
|
// 2 parametri : sKey, sVal
|
|
string sKey ;
|
|
LuaCheckParam( L, 1, sKey) ;
|
|
string sVal ;
|
|
LuaCheckParam( L, 2, sVal) ;
|
|
LuaClearStack( L) ;
|
|
// Imposto il valore della chiave
|
|
bool bOk = ExeRedisSetValFromKey( sKey, sVal) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisGetValFromKey( lua_State* L)
|
|
{
|
|
// 1 parametro : sKey
|
|
string sKey ;
|
|
LuaCheckParam( L, 1, sKey)
|
|
LuaClearStack( L) ;
|
|
// Recupero il valore della chiave
|
|
string sVal, sType ;
|
|
bool bOk = ExeRedisGetValFromKey( sKey, sVal) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
LuaSetParam( L, sVal) ;
|
|
return 2 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncConnect( lua_State* L)
|
|
{
|
|
// 1 parametro : sConnection
|
|
string sConnection ;
|
|
LuaCheckParam( L, 1, sConnection)
|
|
LuaClearStack( L) ;
|
|
// Imposto la connessione
|
|
bool bOk = ExeRedisAsyncConnect( sConnection) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncDiconnect( lua_State* L)
|
|
{
|
|
// Nessun parametro
|
|
LuaClearStack( L) ;
|
|
// Imposto la connessione
|
|
bool bOK = ExeRedisAsyncDisconnect() ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOK) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncPublish( lua_State* L)
|
|
{
|
|
// 2 parametri : sChannel, sMessage
|
|
string sChannel ;
|
|
LuaCheckParam( L, 1, sChannel) ;
|
|
string sMessage ;
|
|
LuaCheckParam( L, 2, sMessage) ;
|
|
LuaClearStack( L) ;
|
|
// Pubblico il messaggio sul canale
|
|
bool bOk = ExeRedisAsyncPublish( sChannel, sMessage) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncSubscribe( lua_State* L)
|
|
{
|
|
// 1 parametro : sChannel
|
|
string sChannel ;
|
|
LuaCheckParam( L, 1, sChannel) ;
|
|
LuaClearStack( L) ;
|
|
// Iscrizione al canale
|
|
bool bOk = ExeRedisAsyncSubscribe( sChannel) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncUnsubscribe( lua_State* L)
|
|
{
|
|
// 1 parametro : sChannel
|
|
string sChannel ;
|
|
LuaCheckParam( L, 1, sChannel) ;
|
|
LuaClearStack( L) ;
|
|
// Disiscrizione
|
|
bool bOk = ExeRedisAsyncUnsubscribe( sChannel) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaRedisAsyncSubscribeOneMessage( lua_State* L)
|
|
{
|
|
// 2 parametri : sChannel, dMaxTimeOut
|
|
string sChannel ;
|
|
LuaCheckParam( L, 1, sChannel) ;
|
|
double dMaxTimeOut = 0. ;
|
|
LuaCheckParam( L, 2, dMaxTimeOut) ;
|
|
LuaClearStack( L) ;
|
|
// Disiscrizione
|
|
string sMessage ;
|
|
bool bOk = ExeRedisAsyncSubscribeOneMessage( sChannel, dMaxTimeOut, sMessage) ;
|
|
// Restituisco il risultato
|
|
LuaSetParam( L, bOk) ;
|
|
LuaSetParam( L, sMessage) ;
|
|
return 2 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallRedis( LuaMgr& luaMgr)
|
|
{
|
|
bool bOk = ( &luaMgr != nullptr) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisConnect", LuaRedisConnect) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisDisconnect", LuaRedisDisconnect) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisSetValFromKey", LuaRedisSetValFromKey) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisGetValFromKey", LuaRedisGetValFromKey) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncConnect", LuaRedisAsyncConnect) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncDisconnect", LuaRedisAsyncDiconnect) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncPublish", LuaRedisAsyncPublish) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncSubscribe", LuaRedisAsyncSubscribe) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncUnsubscribe", LuaRedisAsyncUnsubscribe) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtRedisAsyncSubscribeOneMessage", LuaRedisAsyncSubscribeOneMessage) ;
|
|
return bOk ;
|
|
}
|