skip to Main Content

I am using perl Redis.pm for all the sys jobs with redis
All standard redis commands are available in the module

But for a custom load module , how can I use that in perl

For eg Redisbloom

On command line this works

127.0.0.1:6379> bf.add names tom
(integer) 1

I am not sure what I can do is a perl script. This does not work

my $n = $redis->cmd("bf.add","names","tom");

2

Answers


  1. The Redis module does not support calling custom commands, as far as I can tell. Mojo::Redis does.

    use strict;
    use warnings;
    use Mojo::Redis;
    my $redis = Mojo::Redis->new('redis://127.0.0.1:6379/0')->encoding(undef);
    $redis->db->call('bf.add', 'names', 'tom');
    

    Note that the encoding attribute is set to undef here to match the behavior of the Redis module – if you will be dealing with any non-ascii text data and want it to be automatically encoded and decoded for storage, you can leave it at the default of UTF-8.

    Login or Signup to reply.
  2. I’d try:

    use Redis;
    my $redis = Redis->new;
    my $n = $redis->__std_cmd("bf.add", "names", "tom");
    

    The Perl client makes using periods in commmand names an impossibility – this seems to work around that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search