File: 30-scripts.t

package info (click to toggle)
libredis-fast-perl 0.37%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 504 kB
  • sloc: perl: 2,866; makefile: 7
file content (47 lines) | stat: -rwxr-xr-x 1,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!perl

use warnings;
use strict;
use Test::More;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;
use Digest::SHA qw(sha1_hex);

use constant SSL_AVAILABLE => eval { require IO::Socket::SSL };

my ($c, $t, $srv) = redis();
my $use_ssl = $t ? SSL_AVAILABLE : 0;

END {
  $c->() if $c;
  $t->() if $t;
}

my $o = Redis::Fast->new(server => $srv, ssl => $use_ssl, SSL_verify_mode => 0);

## Make sure SCRIPT commands are available
eval { $o->script_flush };
if ($@ && $@ =~ /ERR unknown command 'SCRIPT',/) {
  $c->();
  plan skip_all => 'This redis-server lacks scripting support';
}


## Commands related to Lua scripting

# Specifically, these commands test multi-word commands
ok($o->set(foo => 'bar'), 'set foo => bar');

my $script     = "return 1";
my $script_sha = sha1_hex($script);
my @ret        = $o->script_exists($script_sha);
ok(@ret && $ret[0] == 0, "script exists returns false");
@ret = $o->script_load($script);
ok(@ret && $ret[0] eq $script_sha, "script load returns the sha1 of the script");
ok($o->script_exists($script_sha), "script exists returns true after loading");
ok($o->evalsha($script_sha, 0), "evalsha returns true with the sha1 of the script");
ok($o->eval($script, 0), "eval returns true");

## All done
done_testing();