Mojo::Redis2 - (DEPRECATED) Pure-Perl non-blocking I/O Redis driver
0.36
Instead of using this module, you should use Mojo::Redis instead. Because:
It has a connection pool, meaning you don't have to connect all the time.
"pubsub" in Mojo::Redis follows the same API as Mojo::Pg.
The blocking API is explicit and use another instance of Mojo::IOLoop.
Has support for Mojo::Promise.
Provides an easy way for caching complex data structures.
Not confusing if you use BLPOP (or friends) or pubsub commands, since it's always a different connection.
Mojo::Redis2 is a pure-Perl non-blocking I/O Redis driver for the Mojolicious real-time framework.
Mojo::Redis2 has not been maintained for a while, and it has some design flaws that makes it hard to work with. All of this and more is taken care of in Mojo::Redis.
Want to take over Mojo::Redis2? Contact me on github and I'll let you have it.
I encourage everyone to have a look at Mojo::Redis, and I discourage any new codebase from using Mojo::Redis2.
https://github.com/jhthorsen/mojo-redis/issues?utf8=%E2%9C%93&q=is%3Aclosed
https://github.com/jhthorsen/mojo-redis2/issues
I decided to remove the "SYNOPSIS" since I want people to use "Mojo::Redis" instead.
See "DEPRECATED" for more details.
$self->on(connection => sub { my ($self, $info) = @_; ... });
Emitted when a new connection has been established. $info is a hash ref with:
$info
{ group => $str, # basic, blocking, blpop, brpop, brpoplpush, publish, ... id => $connection_id, nb => $bool, # blocking/non-blocking }
Note: The structure of $info is EXPERIMENTAL.
$self->on(error => sub { my ($self, $err) = @_; ... });
Emitted if an error occurs that can't be associated with an operation.
$self->on(message => sub { my ($self, $message, $channel) = @_; });
Emitted when a $message is received on a $channel after it has been subscribed to.
$message
$channel
$self->on(pmessage => sub { my ($self, $message, $channel, $pattern) = @_; });
Emitted when a $message is received on a $channel matching a $pattern, after it has been subscribed to.
$pattern
$str = $self->encoding; $self = $self->encoding('UTF-8');
Holds the character encoding to use for data from/to Redis. Default is UTF-8. Set to undef to disable encoding/decoding data. Without an encoding set, Redis expects and returns bytes.
UTF-8
undef
DEPRECATED! The protocol object cannot be shared in high load environments.
$str = $self->protocol_class; $self = $self->protocol_class('Protocol::Redis::XS');
Holds the class name used to parse/generate Redis messages. Defaults to Protocol::Redis::XS or Protocol::Redis.
Protocol::Redis::XS need to be installed manually.
$url = $self->url;
Holds a Mojo::URL object with the location to the Redis server. Default is MOJO_REDIS_URL or "redis://localhost:6379". The "url" need to be set in constructor. Examples:
MOJO_REDIS_URL
Mojo::Redis2->new(url => "redis://x:$auth_key\@$server:$port/$database_index"); Mojo::Redis2->new(url => "redis://10.0.0.42:6379"); Mojo::Redis2->new(url => "redis://10.0.0.42:6379/1"); Mojo::Redis2->new(url => "redis://x:s3cret\@10.0.0.42:6379/1");
In addition to the methods listed in this module, you can call these Redis methods on $self:
$self
echo, ping
geoadd, geodist, geohash, geopos, georadius, georadiusbymember
hdel, hexists, hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hset, hsetnx, hstrlen, hvals
pfadd, pfcount, pfmerge
del, exists, expire, expireat, keys, move, persist, pexpire, pexpireat, pttl, randomkey, rename, renamenx, sort, ttl, type
lindex, linsert, llen, lpop, lpush, lpushx, lrange, lrem, lset, ltrim, rpop, rpoplpush, rpush, rpushx
publish
eval, evalsha
sadd, scard, sdiff, sdiffstore, sinter, sinterstore, sismember, smembers, smove, spop, srandmember, srem, sunion, sunionstore
zadd, zcard, zcount, zincrby, zinterstore, zlexcount, zrange, zrangebylex, zrangebyscore, zrank, zrem, zremrangebylex, zremrangebyrank, zremrangebyscore, zrevrange, zrevrangebylex, zrevrangebyscore, zrevrank, zscore, zunionstore
append, bitcount, bitop, bitpos, decr, decrby, get, getbit, getrange, getset, incr, incrby, incrbyfloat, mget, mset, msetnx, psetex, set, setbit, setex, setnx, setrange, strlen
See http://redis.io/commands for details.
$self = Mojo::Redis2->new(...);
Object constructor. Makes sure "url" is an object.
$self = $self->blpop(@keys, $timeout, sub { my ($self, $err, $res) = @_; });
This method will issue the BLPOP command on the Redis server, but in its own connection. This means that $self can still be used to run other commands instead of being blocking.
Note: This method will only work in a non-blocking environment.
See also http://redis.io/commands/blpop.
$self = $self->brpop(@keys, $timeout, sub { my ($self, $err, $res) = @_; });
Follows the same API as "blpop". See also http://redis.io/commands/brpop.
$self = $self->brpoplpush($from => $to, $timeout, sub { my ($self, $err, $res) = @_; });
Follows the same API as "blpop". See also http://redis.io/commands/brpoplpush.
$obj = $self->bulk;
Returns a Mojo::Redis2::Bulk object which can be used to group Redis operations.
$self->client->$method(@args);
Run "CLIENT" commands using Mojo::Redis2::Client.
$self->backend->$method(@args);
Run server commands (CONFIG, INFO, SAVE, ...) using Mojo::Redis2::Backend.
$txn = $self->multi;
This method does not perform the "MULTI" Redis command, but returns a Mojo::Redis2::Transaction object instead.
The Mojo::Redis2::Transaction object is a subclass of Mojo::Redis2, which will run all the Redis commands inside a transaction.
$self = $self->psubscribe(\@patterns, sub { my ($self, $err, $res) = @_; ... });
Used to subscribe to channels that match @patterns. Messages arriving over a matching channel name will result in "pmessage" events.
@patterns
See http://redis.io/topics/pubsub for details.
$self = $self->punsubscribe(\@patterns, sub { my ($self, $err, $res) = @_; ... });
The reverse of "psubscribe". See http://redis.io/topics/pubsub for details.
$cur = $self->scan(0, MATCH => 'namesoace*', COUNT => 15); $cur = $self->hscan('hash.key', 0, MATCH => 'pref.*'); $cur = $self->sscan('set.key', 0); $cur = $self->zscan('zset.key', 0); $res = $cur->next();
Methods from SCAN family will return Mojo::Redis2::Cursor object to iterate over elements collection.
SCAN
$self = $self->subscribe(\@channels, sub { my ($self, $err, $res) = @_; ... });
Used to subscribe to @channels. Messages arriving over a channel will result in "message" events.
@channels
$self = $self->unsubscribe(\@channels, sub { my ($self, $err, $res) = @_; ... }); $self = $self->unsubscribe($event); $self = $self->unsubscribe($event, $cb);
The reverse of "subscribe". It will also call "unsubscribe" in Mojo::EventEmitter unless the first argument is an array-ref of @channels.
Copyright (C) 2014, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Andre Parker
Ben Tyler - benjamin.tyler@gmail.com
benjamin.tyler@gmail.com
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
Mike Magowan - mike@magowan.co.uk
mike@magowan.co.uk
To install Mojo::Redis2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Redis2
CPAN shell
perl -MCPAN -e shell install Mojo::Redis2
For more information on module installation, please visit the detailed CPAN module installation guide.