redis lua string split?

1,879 views
Skip to first unread message

Marc Byrd

unread,
Nov 2, 2012, 4:28:54 PM11/2/12
to redi...@googlegroups.com
How does one split a string in lua in redis?  

I'm trying 
  kz = string.split(key,'^')

but getting:
user_script:7: attempt to call field 'split' (a nil value)

if I simply use 
  kz = split(key, '^')
I get 
 Script attempted to access unexisting global variable 'split'

Is there some reference or bundle of examples I could use to answer these sorts of questions? 

Thanks in advance,


m

Tim Lossen

unread,
Nov 2, 2012, 4:35:52 PM11/2/12
to redi...@googlegroups.com
apparently there is no split function in lua, and everybody implements their own:

http://stackoverflow.com/questions/1426954/split-string-in-lua
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

--
http://tim.lossen.de



Julien Ammous

unread,
Nov 5, 2012, 6:40:14 AM11/5/12
to redi...@googlegroups.com
There are many functions you would take for granted in other languages which do not exists in stock lua, I think the main reason is that
it tries to stay minimal and lightweight (and does it well).
Each time I worked with lua I quickly built my own basic library by gathering and building the functions I needed for the project, the wiki
contains many implementations of "standard" functions like split and you can decide which one fits your bill depending on the complexity you require.

It may be seen as an issue but I am not so sure whether I prefer this strategy over the other languages where you get a standard library
which is bigger than the interpreter itself and you don't even know half of it ;)
(Ruby is a good example of that, I am pretty sure I never used even a third of what is in there)

Of course one could argue that split should be part on the core, maybe it is true maybe not :)
Reply all
Reply to author
Forward
0 new messages