예제 #1
0
파일: redis.c 프로젝트: 4z3/luvit-redis
static void on_redis_response(redisAsyncContext *context, void *reply, void *privdata)
{
  redisReply *redisReply = reply;
  luv_ref_t *ref = privdata;
  int replyArgsCount = 0;

  lua_State *L = ref->L;
  lua_rawgeti(L, LUA_REGISTRYINDEX, ref->r);
  luaL_unref(L, LUA_REGISTRYINDEX, ref->r);
  ref_free(ref);

  if (redisReply == NULL)
  {
    luv_push_async_hiredis_error(L, context, "on_redis_response");
    lua_pushnil(L);
    luv_acall(L, 2, 0, "on_redis_response");
  }
  else
  {
    if (redisReply->type != REDIS_REPLY_ERROR)
    {
      lua_pushnil(L);
      ++replyArgsCount;
    }
    replyArgsCount += push_reply(L, redisReply);
    luv_acall(L, replyArgsCount, 0, "on_redis_response");
  }
}
예제 #2
0
void Trick::delete_trick_map_stl( std::string obj_name , unsigned int stl_id ) {
    char var_declare[128] ;
    REF2 * items_ref ;

    sprintf(var_declare, "%s_%06d_keys" , obj_name.c_str(), stl_id) ;
    items_ref = ref_attributes(var_declare) ;
    if ( items_ref != NULL ) {
        TMM_delete_var_n(var_declare) ;
        ref_free(items_ref) ;
        free(items_ref) ;
    }
    sprintf(var_declare, "%s_%06d_data" , obj_name.c_str(), stl_id) ;
    items_ref = ref_attributes(var_declare) ;
    if ( items_ref != NULL ) {
        TMM_delete_var_n(var_declare) ;
        ref_free(items_ref) ;
        free(items_ref) ;
    }
}
예제 #3
0
Trick::DataRecordBuffer::~DataRecordBuffer() {
    if ( buffer ) {
        free(buffer) ;
    }
    if ( last_value ) {
        free(last_value) ;
    }

    ref_free(ref) ;
    free(ref) ;
}
예제 #4
0
파일: redis.c 프로젝트: 4z3/luvit-redis
static int lua_client_command(lua_State *L)
{
  lua_redis_client_t *lua_redis_client = (lua_redis_client_t *)
                                    luaL_checkudata(L, 1, LUA_REDIS_CLIENT_MT);

  static const char *argv[LUA_REDIS_MAX_ARGS];
  static size_t argvlen[LUA_REDIS_MAX_ARGS];

  int nargs, ltop, i;
  luv_ref_t *ref = NULL;
  int commandStatus;
  redisCallbackFn *redisCallback = NULL;

  if (lua_redis_client->redis_async_context == NULL)
  {
    return luaL_error(L, "RedisAsyncContext is null");
  }

  /* consume callback, if any */
  if (lua_isfunction(L, -1))
  {
    ref = ref_alloc();
    ref->L = L;
    ref->r = luaL_ref(L, LUA_REGISTRYINDEX);
    redisCallback = on_redis_response;
  }

  /* get arguments */
  ltop = lua_gettop(L);
  nargs = 0;
  for (i = 2; i <= ltop; ++i) {
    /* unpack tables of arguments */
    if (lua_istable(L, i)) {
      int j;
      for (j = 1; j <= lua_objlen(L, i); ++j) {
        lua_rawgeti(L, i, j);
        argv[nargs] = lua_tolstring(L, -1, &argvlen[nargs]);
        lua_pop(L, 1);
        if (argv[nargs] == NULL) {
          return luaL_argerror(L, i,
              "expected an array table of string or number values"
            );
        }
        if (++nargs >= LUA_REDIS_MAX_ARGS) {
          return luaL_error(L, "too many arguments");
        }
      }
    } else {
      argv[nargs] = lua_tolstring(L, i, &argvlen[nargs]);
      if (argv[nargs] == NULL) {
        return luaL_argerror(L, i, "expected a string or number value");
      }
      if (++nargs >= LUA_REDIS_MAX_ARGS) {
        return luaL_error(L, "too many arguments");
      }
    }
  }
  if (nargs <= 0) {
    return luaL_error(L, "missing command name");
  }

  commandStatus = redisAsyncCommandArgv(lua_redis_client->redis_async_context,
                                        redisCallback,
                                        ref,
                                        nargs,
                                        argv,
                                        argvlen);

  if (commandStatus != REDIS_OK)
  {
    lua_rawgeti(L, LUA_REGISTRYINDEX, ref->r);
    luaL_unref(L, LUA_REGISTRYINDEX, ref->r);
    ref_free(ref);
    luv_push_async_error_raw(L, NULL, "Redis connection problem", "client_command", NULL);
    lua_pushnil(L);
    lua_call(L, 2, 0);
  }

  return 0;
}