NAME
Protocol::Redis::XS - hiredis based parser compatible with Protocol::Redis
SYNOPSIS
use
Protocol::Redis::XS;
my
$redis
= Protocol::Redis::XS->new(
api
=> 1);
$redis
->parse(
"+OK\r\n"
);
my
$message
=
$redis
->get_message;
# create message
$redis
->encode({
type
=>
'*'
,
data
=> [
{
type
=>
'$'
,
data
=>
'string'
},
{
type
=>
'+'
,
data
=>
'OK'
},
]});
DESCRIPTION
This provides a fast parser for the Redis protocol using the code from hiredis and with API compatibility with Protocol::Redis.
(If you've found yourself here just looking to use Redis in Perl: This is a low level parsing module, you probably want to look at the modules mentioned in "SEE ALSO" first.)
METHODS
As per Protocol::Redis, API version 1.
parse
$redis
->parse(
"*2\r\n$4ping\r\n\r\n"
);
Parse a chunk of data (calls "on_message" callback if defined and a complete message is received).
get_message
while
(
my
$message
=
$redis
->get_message) { ... }
Return a message. This is a potentially nested data structure, for example as follows:
{
type
=>
'*'
,
data
=> [
{
type
=>
'$'
,
data
=>
'hello'
}
]
}
on_message
$redis
->on_message(
sub
{
my
(
$redis
,
$message
) =
@_
; ... });
Set callback for "parse".
encode
my
$string
=
$redis
->encode({
type
=>
'*'
,
data
=> [
{
type
=>
'+'
,
data
=>
'test'
},
{
type
=>
'$'
,
data
=>
'test'
},
]});
Encode data into redis message.
THREADS
This module will work on a threaded perl and will work with threads, however instances of Protocol::Redis should not be shared between threads.
SUPPORT
IRC
DEVELOPMENT
See github: https://github.com/dgl/protocol-redis-xs.
AUTHOR
David Leadbeater <dgl@dgl.cx>
With thanks to Sergey Zasenko <undef@cpan.org> for the original Protocol::Redis and defining the API.
COPYRIGHT AND LICENSE
Copyright (C) 2011 David Leadbeater.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
SEE ALSO
Redis, Redis::hiredis, Mojo::Redis, AnyEvent::Redis, Protocol::Redis.