Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MAX_INT = 4294967294 - 2
- local function EXISTS(rec, bin)
- if aerospike:exists(rec)
- and rec[bin] ~= nil
- and type(rec) == "userdata"
- and record.ttl(rec) < (MAX_INT - 60) then
- return true
- end
- return false
- end
- local function UPDATE(rec)
- if aerospike:exists(rec) then
- aerospike:update(rec)
- else
- aerospike:create(rec)
- end
- end
- function LPOP (rec, bin, count)
- if (EXISTS(rec, bin)) then
- local l = rec[bin]
- local new_l = list.drop(l, count)
- rec[bin] = new_l
- UPDATE(rec)
- return list.take(l, count)
- end
- return nil
- end
- function LPUSH(rec, bin, value)
- local l = rec[bin]
- if (l == nil) then
- l = list()
- end
- list.prepend(l, value)
- rec[bin] = l
- local length = #l
- UPDATE(rec)
- return length
- end
- function LSIZE(rec, bin)
- if (EXISTS(rec, bin)) then
- local l = rec[bin]
- return #l
- end
- return nil
- end
- function RPOP (rec, bin, count)
- if (EXISTS(rec, bin)) then
- local l = rec[bin]
- local result_list = nil
- if (#l <= count) then
- result_list = rec[bin]
- rec[bin] = nil
- else
- local start = #l - count
- result_list = list.drop(l, start)
- rec[bin] = list.take(l, start)
- end
- UPDATE(rec)
- if (result_list ~= nil) then
- return result_list
- else
- return list()
- end
- end
- return nil
- end
- function RPUSH (rec, bin, value)
- local l = rec[bin]
- if (l == nil) then
- l = list()
- end
- list.append(l, value)
- rec[bin] = l
- local length = #l
- UPDATE(rec)
- return length
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement