File: eval.pl

package info (click to toggle)
libanyevent-riperedis-perl 0.48-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,430; makefile: 2
file content (47 lines) | stat: -rwxr-xr-x 755 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
#!/usr/bin/perl

use strict;
use warnings;

use AnyEvent;
use AnyEvent::RipeRedis;

my $cv = AE::cv;

my $redis = AnyEvent::RipeRedis->new(
  host     => 'localhost',
  port     => 6379,
  password => 'redis_pass',

  on_connect => sub {
    print "Connected to Redis server\n";
  },

  on_disconnect => sub {
    print "Disconnected from Redis server\n";
  },
);

# Execute Lua script
$redis->eval_cached( 'return { KEYS[1], KEYS[2], ARGV[1], ARGV[2] }',
    2, 'key1', 'key2', 'first', 'second',
  sub {
    my $reply = shift;
    my $err   = shift;

    if ( defined $err ) {
      warn $err->message . "\n";
      return;
    };

    foreach my $val ( @{$reply}  ) {
      print "$val\n";
    }

    $cv->send;
  }
);

$cv->recv;

$redis->disconnect;