### ----------------------------------------------------
### -- Redis
### -- Licenses: Artistic-2.0
### -- Authors: Yecheng Fu, Raku Community
### -- File: t/02-scripting.rakutest
### ----------------------------------------------------
use Test;
use Redis;

use lib "t";
use Test::SpawnRedisServer;

if SpawnRedis() -> $proc {
    LEAVE $proc.kill('INT');

    my $r = Redis.new("127.0.0.1:63790", decode_response => True);
    $r.auth('20bdfc8e73365b2fde82d7b17c3e429a9a94c5c9');
    $r.flushall;

    if $r.info<redis_version> gt "2.6" {
        plan 5;

        $r.set("key", 1);
        is-deeply $r.eval("return redis.call('get', 'key')", 0), "1";

        is-deeply $r.script_flush(), True;

        dies-ok { $r.script_kill() };

        my $sha = $r.script_load("return redis.call('get', 'key')");
        is-deeply $r.script_exists($sha, "unknown"), [1, 0];

        is-deeply $r.evalsha($sha, 0), "1";
    }
    else {
        plan 1;
        skip-rest "scripting not available on this redis-server";
    }
}
else {
    plan 1;
    skip-rest "no redis-server";
}

# vim: expandtab shiftwidth=4


