Eredis
NAME
Eredis - NativeCall bindings for the Eulerian Technologies eredis library
SYNOPSIS
use Eredis;
my $e = Eredis.new;
$e.host-add('localhost', 6379); # Add a redis targer, first is 'preferred'
$e.host-file('my-hosts.conf'); # one line per host:port
$e.timeout(200); # Set timeout - default 5000ms, 5 seconds
$e.max-readers(50); # Set max readers - Default 10
$e.retry(1); # Set retry for reader - default 1
start $e.run-thr; # Start eredis managed thread for async writes
my $r = $e.reader; # Create a reader object
$r.cmd('set foo bar'); # Blocking write
my $reply = $r.cmd('get foo'); # Blocking read
say $reply.value; # 'bar'
$r.append-cmd('set foo bar'); # Add pipe-lined read
my $reply = $r.reply; # Get reply from pipe-lined read
$r.release; # Release reader
$e.write('set foo bar'); # Non-blocking write, no reply
$e.shutdown; # Shut down the event loop
$e.free; # Close connections and free memory
DESCRIPTION
Nativecall interface to the Eulerian Technologis eredis library:
Eredis is a C client library built over Hiredis. It is
lightweight, high performance, reentrant and thread-safe. It aims
to provide features for real production environment and keep it
simple.
There are three main classes that correspond with C pointers to objects that get passed into C functions that operate on those objects. They are implemented with three Perl 6 classes with methods that correspond to those C functions.
class Eredis is repr('CPointer')
A Nativecall eredis_t
pointer.
method new()
eredis_new
.
method host-add(Str:D $host, Int:D $port)
eredis_host_add
throws X::Eredis on error
method host-file(Str:D $filename) returns Int
eredis_host_file
returns number of hosts, or -1 on error
method timeout(Int:D $timeout-ms)
eredis_timeout
.
Default is 5000 (5 seconds).
method max-readers(Int:D $max-readers)
eredis_r_max
Default is 10
method retry(Int:D $retry)
eredis_r_retry
Default is 1 retry.
method reader()
eredis_r
Returns an Eredis::Reader
method run()
eredis_run
run eredis event loop (for writes) in blocking mode
The loop will be stopped by a call to 'shutdown' or 'free'.
method run-thr()
eredis_run_thr
run eredis event loop (for writes) in a dedicated thread
Will block until the thread is ready.
multi method write(Str:D $cmd)
eredis_w_cmd
multi method write(*@args)
eredis_w_cmdargv
method write-pending() returns Int
eredis_w_pending
write queue pending commands
method write-wait()
Busy loop until write queue is empty
method shutdown()
eredis_shutdown
Shutdown the write event loop
method free()
Stop eredis and free all resources allocated.
class Eredis::Reader is repr('CPointer')
Wrapper for a struct eredis_reader_t
object.
Created by Eredis.reader()
multi method cmd(Str:D $cmd) returns Eredis::Reply
eredis_r_cmd
Blocking read request.
multi method cmd(*@args) returns Eredis::Reply
eredis_r_cmdargv
Blocking read request
multi method append-cmd(Str:D $cmd)
eredis_r_append_cmd
Pipelining read request
multi method append-cmd(*@args)
eredis_r_append_cmdargv
Pipelining read request
method reply() returns Eredis::Reply
eredis_r_reply
Retrieve reply from a pipelined request
method subscribe() returns Eredis::Reply
eredis_r_subscribe
Read an unrequested reply (for pub/sub)
method reply-detach() returns Eredis::Reply
eredis_r_reply_detach
Returns a detached reply that must be manually free-d.
method clear()
eredis_r_clear
Clear any pending pipelined replies without retrieving them.
method release()
eredis_r_release
Release a reader.
class Eredis::Reply is repr('CPointer')
Wrapper for a eredis_reply_t
pointer.
dump()
eredis_reply_dump
Diagnostic dump of a reply to STDOUT
free()
eredis_reply_free
Free a detached Eredis::Reply. Most of the time this isn't needed.
type() returns REDIS_REPLY
One of: REDIS_REPLY_STRING REDIS_REPLY_ARRAY REDIS_REPLY_INTEGER REDIS_REPLY_NIL REDIS_REPLY_STATUS REDIS_REPLY_ERROR
value()
Grabs the appropriate return type from the reply
SEE ALSO
Eredis can be obtained from https://github.com/EulerianTechnologies/eredis.