Permalink
Browse files

LUA: changed redis() to alchemy() - ROUND3: test/

  • Loading branch information...
1 parent 8f2f1f3 commit 3a26e30fcbe781fa12403fdb0eae796470ecc112 The X DB committed Feb 28, 2012
@@ -1,19 +1,19 @@
function set(key, val)
--print ('set');
- return redis('set', key, val);
+ return alchemy('set', key, val);
end
function get(key)
--print ('get');
- return redis('get', key);
+ return alchemy('get', key);
end
function subscribe(channel)
print ('subscribe');
- return redis('subscribe', channel);
+ return alchemy('subscribe', channel);
end
function publish(channel, msg)
print ('publish');
- return redis('publish', channel, msg);
+ return alchemy('publish', channel, msg);
end
function print_packages()
@@ -82,7 +82,7 @@ function internal_select_store(clist, tlist, whereclause)
--print ('wc: ' .. wc .. ' cmd: ' .. cmd);
-- 3.) execute select, storing results in a table
- local t = redis('select', clist, "FROM", tlist, "WHERE", wc);
+ local t = alchemy('select', clist, "FROM", tlist, "WHERE", wc);
if (t == nil) then return 0; end
-- 4.) iterate thru results, running "command" on each row
@@ -100,13 +100,13 @@ function internal_select_store(clist, tlist, whereclause)
table.insert(nargv, rcols[i]); -- then add rest of rcols
end
--for k,v in ipairs(nargv) do print('CX_ARGV: ' .. v) end
- redis(unpack(nargv));
+ alchemy(unpack(nargv));
else
for i = 1, #rcols do
table.insert(nargv, rcols[i]); -- add rcols
end
--for k,v in ipairs(nargv) do print('ARGV: ' .. v) end
- redis(unpack(nargv));
+ alchemy(unpack(nargv));
end
end
return #t;
@@ -119,18 +119,18 @@ function internal_run_cmd(cmd)
for token in string.gmatch(cmd, "[^%s]+") do -- poor man's split()
table.insert(argv, token);
end
- return redis(unpack(argv));
+ return alchemy(unpack(argv));
end
function internal_copy_table_from_select(tname, clist, tlist, whereclause)
--print ('internal_copy_table_from_select tname: ' .. tname ..
--' clist: ' .. clist .. ' tlist: ' .. tlist .. ' wc: ' .. whereclause);
local argv = {"SELECT", clist, "FROM", tlist, "WHERE", whereclause};
- local res = redis(unpack(argv));
+ local res = alchemy(unpack(argv));
local inserter = {"INSERT", "INTO", tname, "VALUES", "()" };
for k,v in pairs(res) do
inserter[5] = '(' .. v .. ')';
- redis(unpack(inserter));
+ alchemy(unpack(inserter));
end
return #res;
end
@@ -140,11 +140,11 @@ function internal_cr8tbl_as_command(tname, ascmd)
--print ('internal_cr8tbl_as_command cmd: ' .. cmd);
local res = internal_run_cmd(cmd);
if type(res) == "table" then
- redis("CREATE", "TABLE", tname, "(pk INT, value TEXT)");
+ alchemy("CREATE", "TABLE", tname, "(pk INT, value TEXT)");
local inserter = {"INSERT", "INTO", tname, "VALUES", "()" };
for k,v in pairs(res) do
inserter[5] = '(' .. k .. ',\'' .. v .. '\')';
- redis(unpack(inserter));
+ alchemy(unpack(inserter));
end
else
return res; -- single line responses should be errors
@@ -169,24 +169,24 @@ function internal_cr8tbl_as_dump(tname, dtype, dumpee)
ttype = 3;
end
--print ('cdef: ' .. cdef);
- redis("CREATE", "TABLE", tname, cdef);
+ alchemy("CREATE", "TABLE", tname, cdef);
local inserter = {"INSERT", "INTO", tname, "VALUES", "()" };
res = {};
if (dtype == 'LIST') then
- res = redis("LRANGE", dumpee, 0, -1);
+ res = alchemy("LRANGE", dumpee, 0, -1);
elseif (dtype == 'SET') then
- res = redis("SMEMBERS", dumpee);
+ res = alchemy("SMEMBERS", dumpee);
elseif (dtype == 'ZSET') then
- res = redis("ZRANGE", dumpee, 0, -1, "WITHSCORES");
+ res = alchemy("ZRANGE", dumpee, 0, -1, "WITHSCORES");
elseif (dtype == 'HASH') then
- res = redis("HGETALL", dumpee);
+ res = alchemy("HGETALL", dumpee);
end
local cnt = 1;
if (ttype == 1) then
for k,v in pairs(res) do
local value_string = '(' .. k .. ',\'' .. v .. '\')';
inserter[5] = value_string;
- redis(unpack(inserter));
+ alchemy(unpack(inserter));
cnt = cnt + 1;
--for k,v in pairs(inserter) do print (k .. ': ' .. v); end
end
@@ -205,7 +205,7 @@ function internal_cr8tbl_as_dump(tname, dtype, dumpee)
value_string = value_string .. '\'' .. v .. '\')';
end
inserter[5] = value_string;
- redis(unpack(inserter));
+ alchemy(unpack(inserter));
--for k2,v2 in pairs(inserter) do print (k2 .. ': ' .. v2); end
cnt = cnt + 1;
i = 0;
@@ -13,7 +13,7 @@ char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply);
/* Take a Redis reply in the Redis protocol format and convert it into a
* Lua type. Thanks to this function, and the introduction of not connected
- * clients, it is trvial to implement the redis() lua function.
+ * clients, it is trvial to implement the alchemy() lua function.
*
* Basically we take the arguments, execute the Redis command in the context
* of a non connected client, then take the generated reply and convert it
@@ -149,7 +149,7 @@ int luaRedisCommand(lua_State *lua) {
}
zfree(argv);
luaPushError(lua,
- "Lua redis() command arguments must be strings or integers");
+ "Lua alchemy() command arguments must be strings or integers");
return 1;
}
@@ -2,18 +2,18 @@ module("whitelist", package.seeall);
function set(key, val)
--print ('set');
- return redis('set', key, val);
+ return alchemy('set', key, val);
end
function get(key)
--print ('get');
- return redis('get', key);
+ return alchemy('get', key);
end
function subscribe(channel)
--print ('subscribe');
- return redis('subscribe', channel);
+ return alchemy('subscribe', channel);
end
function publish(channel, msg)
print ('publish');
- return redis('publish', channel, msg);
+ return alchemy('publish', channel, msg);
end
@@ -2,62 +2,62 @@
-- LUA
function luafunc(...)
- return redis('LUAFUNC', ...)
+ return alchemy('LUAFUNC', ...)
end
-- SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL
-- SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL
function create_table(tname, col_defs)
- return redis('CREATE', 'TABLE', tname, "(" .. col_defs .. ")");
+ return alchemy('CREATE', 'TABLE', tname, "(" .. col_defs .. ")");
end
function create_table_as_select(tname, select_command)
- return redis('CREATE', 'TABLE', tname, select_command);
+ return alchemy('CREATE', 'TABLE', tname, select_command);
end
function drop_table(tname)
- return redis('DROP', 'TABLE', tname);
+ return alchemy('DROP', 'TABLE', tname);
end
function desc(tname)
- return redis('DESC', tname);
+ return alchemy('DESC', tname);
end
function dump(tname)
- return redis('DUMP', tname);
+ return alchemy('DUMP', tname);
end
function dump_to_mysql(tname, msname)
if (msname) then
- return redis('DUMP', tname, "TO", "MYSQL", msname);
+ return alchemy('DUMP', tname, "TO", "MYSQL", msname);
else
- return redis('DUMP', tname, "TO", "MYSQL");
+ return alchemy('DUMP', tname, "TO", "MYSQL");
end
end
function dump_to_file(tname, fname)
- return redis('DUMP', tname, "TO", "FILE", fname);
+ return alchemy('DUMP', tname, "TO", "FILE", fname);
end
function create_index(iname, tname, column)
col_w_paren = "(" .. column .. ")";
- return redis('CREATE', "INDEX", iname, "ON", tname, col_w_paren);
+ return alchemy('CREATE', "INDEX", iname, "ON", tname, col_w_paren);
end
function create_unique_index(iname, tname, column)
col_w_paren = "(" .. column .. ")";
- return redis('CREATE', "UNIQUE", "INDEX", iname, "ON", tname, col_w_paren);
+ return alchemy('CREATE', "UNIQUE", "INDEX", iname, "ON", tname, col_w_paren);
end
function drop_index(iname)
- return redis('DROP', 'index', iname);
+ return alchemy('DROP', 'index', iname);
end
function create_luatrigger(trname, tname, ...)
- return redis('CREATE', "LUATRIGGER", trname, "ON", tname, ...);
+ return alchemy('CREATE', "LUATRIGGER", trname, "ON", tname, ...);
end
function drop_luatrigger(trname)
- return redis('DROP', 'LUATRIGGER', trname);
+ return alchemy('DROP', 'LUATRIGGER', trname);
end
function insert(tname, values_list)
- return redis('INSERT', "INTO", tname, "VALUES", "(" .. values_list .. ")");
+ return alchemy('INSERT', "INTO", tname, "VALUES", "(" .. values_list .. ")");
end
function insert_return_size(tname, values_list)
- return redis('INSERT', "INTO", tname, "VALUES", "(" .. values_list .. ")",
+ return alchemy('INSERT', "INTO", tname, "VALUES", "(" .. values_list .. ")",
"RETURN SIZE");
end
@@ -68,41 +68,41 @@ function select(...)
local args = {...};
argCount = #args;
if (argCount == 1) then
- return redis('SELECT', args[1]);
+ return alchemy('SELECT', args[1]);
else
- return redis('SELECT', args[1], "FROM", args[2], "WHERE", args[3]);
+ return alchemy('SELECT', args[1], "FROM", args[2], "WHERE", args[3]);
end
end
function select_count(...)
local args = {...};
- return redis('SELECT', 'COUNT(*)', "FROM", args[1], "WHERE", args[2]);
+ return alchemy('SELECT', 'COUNT(*)', "FROM", args[1], "WHERE", args[2]);
end
function scanselect(...)
local args = {...};
argCount = #args;
if (argCount == 2) then
- return redis('SCANSELECT', args[1], "FROM", args[2]);
+ return alchemy('SCANSELECT', args[1], "FROM", args[2]);
else
- return redis('SCANSELECT', args[1], "FROM", args[2], "WHERE", args[3]);
+ return alchemy('SCANSELECT', args[1], "FROM", args[2], "WHERE", args[3]);
end
end
function scanselect_count(...)
local args = {...};
argCount = #args;
local cnt;
if (argCount == 1) then
- return redis('SCANSELECT', "COUNT(*)", "FROM", args[1]);
+ return alchemy('SCANSELECT', "COUNT(*)", "FROM", args[1]);
else
- return redis('SCANSELECT', "COUNT(*)", "FROM", args[1], "WHERE", args[2]);
+ return alchemy('SCANSELECT', "COUNT(*)", "FROM", args[1], "WHERE", args[2]);
end
end
function delete(tname, where_clause)
- return redis('DELETE', "FROM", tname, "WHERE", where_clause);
+ return alchemy('DELETE', "FROM", tname, "WHERE", where_clause);
end
function update(tname, update_list, where_clause)
- return redis('UPDATE', tname, "SET", update_list, "WHERE", where_clause);
+ return alchemy('UPDATE', tname, "SET", update_list, "WHERE", where_clause);
end
-- TODO bulk_insert & insert_on_duplicate_key_update & replace
@@ -698,6 +698,8 @@ function saveGraphNodes() --print ('saveGraphNodes');
addPropToNode(dumpt, n, prop, value);
end
end
+ end
+ for n in vertices() do
if (n.r ~= nil) then
for rtype, relation in pairs(n.r) do
local pkt = relation[Direction.OUTGOING];
Oops, something went wrong.

0 comments on commit 3a26e30

Please sign in to comment.