redis.smembers broken?

145 views
Skip to first unread message

Brandon Cook

unread,
Oct 21, 2014, 2:59:33 PM10/21/14
to websc...@googlegroups.com
Hi I'm playing around with various redis commands. Everything works great so far except for the SMEMBERS command. I'm new to Lua so forgive me if it's something obvious.

local members = redis.smembers("set_key")
log(members) -- set(["item1", "item2"])
log(typeof(members)) -- userdata

Steve Marx

unread,
Oct 21, 2014, 5:59:55 PM10/21/14
to Brandon Cook, websc...@googlegroups.com
Those methods are undocumented for a reason. :-) (How'd you learn about them?)

It looks like the issue here is marshaling back and forth between Python and Lua objects. Does the set work, though? Can you enumerate the values in Lua?


--
You received this message because you are subscribed to the Google Groups "Webscript.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webscriptio...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Cook

unread,
Oct 21, 2014, 7:16:50 PM10/21/14
to websc...@googlegroups.com, phy...@gmail.com
I didn't find any webscript documentation for Redis I just reference http://redis.io/commands

> It looks like the issue here is marshaling back and forth between Python and Lua objects. Does the set work, though? Can you enumerate the values in Lua?
The set definitely doesn't work which was unexpected since LRANGE works. Both LRANGE and SMEMBERS return an array from Redis so I'm not sure why they would return different values in Lua.

local theSet = redis.smembers("set_key")
for i, v in ipairs(theSet) do -- 6: bad argument #1 to 'ipairs' (table expected, got userdata)
    log(i)
    log(v)
end

Steve Marx

unread,
Oct 21, 2014, 10:25:42 PM10/21/14
to Brandon Cook, websc...@googlegroups.com
Thanks for letting us know!

As I said, these are undocumented for a reason... we may simply pull them, or perhaps we'll officially ship these in the future. In the mean time, be careful. :-) (Still not sure how you found these!)

"Both LRANGE and SMEMBERS return an array from Redis so I'm not sure why they would return different values in Lua"

Well, one is a sequence and one is a set. Under the hood, we use the "redis" library in Python to access Redis, and it seems to be doing the right thing in that it treats the return value of smembers as a set. The automatic marshaling we do between Python objects and Lua tables evidently doesn't handle sets, so that's why this doesn't work.

Brandon Cook

unread,
Oct 22, 2014, 1:08:01 AM10/22/14
to Steve Marx, websc...@googlegroups.com
> Thanks for letting us know!
Of course, I’m glad to help :)

> we may simply pull them, or perhaps we'll officially ship these in the future. In the mean time, be careful
Please do ship them - I need them. Why isn’t the fact that the full redis command set isn’t supported documented on your website? I certainly wouldn’t be paying for this service had I known. I expected to pay for a fully-featured Redis backend (within reason, I didn’t expect pub/sub). Why would you NOT expose the full Redis feature set? Hashes and lists are OK but sets and sorted sets aren’t?

> Still not sure how you found these!
It’s not magic: you’ve establish a naming convention consistent with the Redis command set. GET key == redis.get(key), SET key value == redis.set(key, value)…
There’s nothing to find

> Well, one is a sequence and one is a set
Actually if you look at the links in the previous email you’ll see both LRANGE and SMEMBERS return "Array reply: …” which is why I expected redis.lrange() and redis.smembers() to return a Lua table with integer keys and values that I would receive in a normal Redis command from redis-cli

> it seems to be doing the right thing in that it treats the return value of smembers as a set
It’s doing the wrong thing. It returns a Lua type that is “userdata” (which I can’t manipulate http://www.lua.org/manual/5.2/manual.html#2.1) not “table”. I’m operating on a set but the return value should be an array according to Redis which should map to a Lua table with integer keys just as LRANGE does. In any case one command works and the other doesn’t, violating the principle of least astonishment.

I would certainly appreciate it if you could expose the full redis command set (again, within reason. I expect all the basic data structures to be at my disposal). The ones that didn’t work I really need are all of the set (http://redis.io/commands#set), sorted set (http://redis.io/commands#sorted_set), and KEYS (http://redis.io/commands/keys) commands.

Thanks for the time you’ve spent chatting with me! webscript.io is a really nice service and I’d like to be able to continue to use it :)

Steve Marx

unread,
Oct 22, 2014, 1:20:40 AM10/22/14
to Brandon Cook, Steve Marx, websc...@googlegroups.com
> Why isn’t the fact that the full redis command set isn’t supported documented on your website?

We don't tend to document features that don't exist. :-)

> It’s not magic: you’ve establish a naming convention consistent with the Redis command set. GET key == redis.get(key), SET key value == redis.set(key, value)…
> There’s nothing to find

Where did you see "redis.get(key)" and "redis.set(key, value)"? To my knowledge, those aren't documented anywhere.

>> it seems to be doing the right thing in that it treats the return value of smembers as a set
> It’s doing the wrong thing.

Sorry for the confusion. The "it" I was referring to was the Python "redis" module. I expect it to return a Python set because that's semantically what is being returned. The marshaling to Lua is what's wrong here.

"I expected to pay for a fully-featured Redis backend"

I'm still not sure where this expectation came from, since we don't offer any Redis support at all, but we'd be happy to give you a refund! Please email sup...@webscript.io and let us know.


Reply all
Reply to author
Forward
0 new messages