+ return response_handler(client, res)
+ end
+end
+
+function response.status(client, data)
+ local sub = data:sub(2)
+ if sub == protocol.ok then return true else return sub end
+end
+
+function response.error(client, data)
+ local err_line = data:sub(2)
+
+ if err_line:sub(1, 3) == protocol.err then
+ error("Redis error: " .. err_line:sub(5))
+ else
+ error("Redis error: " .. err_line)
+ end
+end
+
+function response.bulk(client, data)
+ local str = data:sub(2)
+ local len = tonumber(str)
+
+ if not len then
+ error('Cannot parse ' .. str .. ' as data length.')
+ else
+ if len == -1 then return nil end
+ local next_chunk = network.read(client, len + 2)
+ return next_chunk:sub(1, -3);
+ end
+end
+
+function response.multibulk(client, data)
+ local str = data:sub(2)
+
+ -- TODO: add a check if the returned value is indeed a number
+ local list_count = tonumber(str)
+
+ if list_count == -1 then
+ return nil
+ else
+ local list = {}
+
+ if list_count > 0 then
+ for i = 1, list_count do
+ table.insert(list, i, response.bulk(client, network.read(client)))
+ end
+ end
+
+ return list