Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
added client side support for Redisql's embedded LUA
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy committed Nov 3, 2010
1 parent 1ab7200 commit 6f31174
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions examples/redisql_example_functions.rb
Expand Up @@ -323,3 +323,9 @@ def jstore_worker_location_table(r)
p r.dump("w_c_tbl")
puts
end

def lua_test(r)
p r.lua('return client("SET", "lua_R", 5*5);');
p r.lua('return client("GET", "lua_R");');
end

4 changes: 4 additions & 0 deletions lib/redis.rb
Expand Up @@ -482,6 +482,10 @@ def normalize(main_wildcard, secondary_wildcard_list)
def denormalize(tname, main_wildcard)
@client.call(:denorm, tname, main_wildcard)
end

def lua(cmd)
@client.call(:lua, cmd)
end
# REDISQL END

def hset(key, field, value)
Expand Down
38 changes: 31 additions & 7 deletions test/commands_on_sql_test.rb
Expand Up @@ -21,9 +21,9 @@
test "102 INSERT" do |r|
r.changedb 12
r.insert("new_table", "(1,ONE)");
assert "ONE" == r.select("val", "new_table", "id = 1")
assert ["ONE"] == r.select("val", "new_table", "id = 1")
assert "INFO: BYTES: [ROW: 8 BT-DATA: 16 BT-TOTAL: 4161 INDEX: 0]" == r.insert_and_return_size("new_table", "(2,TWO)");
assert "2" == r.select("id", "new_table", "id = 2")
assert ["2"] == r.select("id", "new_table", "id = 2")
end

test "103 RANGE_QUERY" do |r|
Expand All @@ -36,9 +36,9 @@
r.create_table("join_table", "(id INT, val TEXT)")
assert "table" == r.type("join_table")
r.insert("join_table", "(1,J_ONE)");
assert "J_ONE" == r.select("val", "join_table", "id = 1")
assert ["J_ONE"] == r.select("val", "join_table", "id = 1")
r.insert("join_table", "(2,J_TWO)");
assert "2" == r.select("id", "join_table", "id = 2")
assert ["2"] == r.select("id", "join_table", "id = 2")
assert ["ONE,J_ONE", "TWO,J_TWO"] == r.select("new_table.val,join_table.val", "new_table,join_table", "new_table.id = join_table.id AND new_table.id BETWEEN 1 AND 2")
r.drop_table("join_table");
assert "none" == r.type("join_table")
Expand All @@ -61,7 +61,7 @@
test "107 UPDATE" do |r|
r.changedb 12
r.update("new_table", "val=two", "id = 2")
assert "two" == r.select("val", "new_table", "id = 2")
assert ["two"] == r.select("val", "new_table", "id = 2")
end

test "108 DELETE" do |r|
Expand Down Expand Up @@ -89,7 +89,7 @@
assert ["5.000000"] == r.select("zvalue", "z_table", "zkey = z5")

r.create_table_as("x_table", "ZRANGE", "zset", "0 1 WITHSCORES")
assert "2" == r.select("value", "x_table", "pk = 4")
assert ["2"] == r.select("value", "x_table", "pk = 4")

r.select_store("zkey,zvalue", "z_table", "zkey BETWEEN z2 AND z4", "HSET", "z_hash")
assert "4.000000" == r.hget("z_hash", "z4")
Expand Down Expand Up @@ -147,7 +147,31 @@
assert({"name" => "bill", "age" => "33", "status" => "member"}) == r.hgetall("user:1")
end

test "111 FLUSHDB 12" do |r|
test "111 LUA" do |r|
r.changedb 12
r.set("user:1:name", "TED");
r.set("user:10:name", "KENNY");
r.del("set1", "set2");
r.sadd("set1", 1);
r.sadd("set1", 10);
r.sadd("set1", 20);
r.sadd("set2", 1);
r.sadd("set2", 10);
lua_cmd = '
a = client("SINTER", "set1", "set2");
t = {};
i = 1;
for k,v in pairs(a) do
u = "user:" .. v .. ":name";
b = client("GET", u);
t[i] = b;
i = i + 1;
end
return t;'
assert ["KENNY", "TED"] == r.lua(lua_cmd);
end

test "112 FLUSHDB 12" do |r|
r.changedb 12
r.flushdb()
end

0 comments on commit 6f31174

Please sign in to comment.