Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

326
Vistas
Node running Lua script for Redis. How to return sorted set from Lua script to Node?

This is the Lua script code in file test.lua:

local ips_key = 'production:ips'
local ids = redis.call('ZRANGE', ips_key, 0, '+inf', 'WITHSCORES')
local result = {}
for i, name in ipairs(ids) do
    table.insert(result, name)
end
return js.global:Array(table.unpack(result))

I'm using ioredis, which is a redis npm to eval this lua script. the return value is undefined. What am I doing wrong? Thank you!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are several problems with the above script.

L#2: ZRANGE does not accept +inf (or -inf) as arguments, the input should be indices in the sorted set - replace it with -1 to retrieve the entire range of elements.

L#7: There's no js library in Redis' Lua so that won't work (and isn't needed anyway)

L#7: table.unpack is Lua 5.3, whereas Redis is 5.1 - use unpack instead when needed.

L#7: No need to unpack the result you're returning (if you do, you'll just get the first element in the array back and that's it)

L#1 I understand that this is a test, but always use the KEYS input table to pass your keys to the script - never hardcode/generate key names inside it.

All in all, this should "work" when called with a single key as input:

local ips_key = KEYS[1]
local ids = redis.call('ZRANGE', ips_key, 0, -1, 'WITHSCORES')
local result = {}
for i, name in ipairs(ids) do
    table.insert(result, name)
end
return result

As a final note, the code currently "works" but does nothing - it copies the results of the call to ZRANGE and returns them. Put differently, the reply is the same as just calling ZRANGE regularly w/o Lua.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda