diff --git a/extend/lbson/src/bson.h b/extend/lbson/src/bson.h index 7a8b10b9..4e0ca7bf 100644 --- a/extend/lbson/src/bson.h +++ b/extend/lbson/src/bson.h @@ -183,6 +183,12 @@ namespace lbson { return sprintf(str, "%zd", i); } + void pack_date(lua_State* L) { + lua_getfield(L, -1, "date"); + m_buffer.write(lua_tointeger(L, -1) * 1000); + lua_pop(L, 1); + } + void pack_int64(lua_State* L) { lua_getfield(L, -1, "value"); m_buffer.write(lua_tointeger(L, -1)); @@ -355,6 +361,8 @@ namespace lbson { pack_binary(L); break; case bson_type::BSON_DATE: + pack_date(L); + break; case bson_type::BSON_INT64: case bson_type::BSON_TIMESTAMP: pack_int64(L); @@ -520,7 +528,7 @@ namespace lbson { lua_pushinteger(L, read_val(L, slice)); break; case bson_type::BSON_DATE: - lua_pushinteger(L, read_val(L, slice)); + lua_pushinteger(L, read_val(L, slice) / 1000); break; case bson_type::BSON_INT64: case bson_type::BSON_TIMESTAMP: diff --git a/extend/lbson/src/lbson.cpp b/extend/lbson/src/lbson.cpp index e889ca51..89af3594 100644 --- a/extend/lbson/src/lbson.cpp +++ b/extend/lbson/src/lbson.cpp @@ -28,7 +28,7 @@ namespace lbson { return thread_bson.int64(L, value); } static int date(lua_State* L, int64_t value) { - return thread_bson.date(L, value); + return thread_bson.date(L, value * 1000); } static void init_static_bson() { diff --git a/script/queue/mongo_mq.lua b/script/queue/mongo_mq.lua index 81dd9392..479d52cb 100644 --- a/script/queue/mongo_mq.lua +++ b/script/queue/mongo_mq.lua @@ -59,8 +59,8 @@ end function MongoMQ:send_message(target_id, event, args, ttl) local doc = { args = args, event = event, target_id = target_id, time = quanta.now_ms, uuid = new_guid() } if ttl then - --设置过期ttl字段, 单位毫秒 - doc.ttl = bdate(quanta.now_ms + ttl * 1000) + --设置过期ttl字段 + doc.ttl = bdate(quanta.now + ttl) end local ok = mongo_agent:insert({ self.coll_name, doc }, target_id) if not ok then