Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wavii is using LUA in Redis to implement extremely simple single object atomic consistency. Some but not all of the Redis data structure types support "do XYZ only if the key exists". For example lists support LPUSHX but there is no "X" equivalent for sorted sets. With LUA I can add the ZADDX command in about 4 lines of LUA and 4 lines of Ruby in my Redis driver. We have lots of sorted sets backed by the database. Suppose we add an item to the set. If the set is in Redis we want to do the O(logN) ZADD, if it is not in Redis we need to do an O(N) reload from the DB. The use of ZADDX + transactions in our DB lets multiple writers contend on adding an item to a sorted set and guarantee that at the end all the items are in the sorted set while doing O(logN) operations almost all the time.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: