Redis - Perl binding for Redis database
version 1.995
## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379
my $redis = Redis->new;
my $redis = Redis->new(server => 'redis.example.com:8080');
## Set the connection name (requires Redis 2.6.9)
my $redis = Redis->new(
server => 'redis.example.com:8080',
name => 'my_connection_name',
);
my $generation = 0;
my $redis = Redis->new(
server => 'redis.example.com:8080',
name => sub { "cache-$$-".++$generation },
);
## Use UNIX domain socket
my $redis = Redis->new(sock => '/path/to/socket');
## Enable auto-reconnect
## Try to reconnect every 1s up to 60 seconds until success
## Die if you can't after that
my $redis = Redis->new(reconnect => 60, every => 1_000_000);
## Try each 100ms up to 2 seconds (every is in microseconds)
my $redis = Redis->new(reconnect => 2, every => 100_000);
## Enable connection timeout (in seconds)
my $redis = Redis->new(cnx_timeout => 60);
## Enable read timeout (in seconds)
my $redis = Redis->new(read_timeout => 0.5);
## Enable write timeout (in seconds)
my $redis = Redis->new(write_timeout => 1.2);
## Connect via a list of Sentinels to a given service
my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
## Same, but with connection, read and write timeout on the sentinel hosts
my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
sentinels_cnx_timeout => 0.1,
sentinels_read_timeout => 1,
sentinels_write_timeout => 1,
);
## Use all the regular Redis commands, they all accept a list of
## arguments
## See https://redis.io/commands for full list
$redis->get('key');
$redis->set('key' => 'value');
$redis->sort('list', 'DESC');
$redis->sort(qw{list LIMIT 0 5 ALPHA DESC});
## Add a coderef argument to run a command in the background
$redis->sort(qw{list LIMIT 0 5 ALPHA DESC}, sub {
my ($reply, $error) = @_;
die "Oops, got an error: $error\n" if defined $error;
print "$_\n" for @$reply;
});
long_computation();
$redis->wait_all_responses;
## or
$redis->wait_one_response();
## Or run a large batch of commands in a pipeline
my %hash = _get_large_batch_of_commands();
$redis->hset('h', $_, $hash{$_}, sub {}) for keys %hash;
$redis->wait_all_responses;
## Publish/Subscribe
$redis->subscribe(
'topic_1',
'topic_2',
sub {
my ($message, $topic, $subscribed_topic) = @_
## $subscribed_topic can be different from topic if
## you use psubscribe() with wildcards
}
);
$redis->psubscribe('nasdaq.*', sub {...});
## Blocks and waits for messages, calls subscribe() callbacks
## ... forever
my $timeout = 10;
$redis->wait_for_messages($timeout) while 1;
## ... until some condition
my $keep_going = 1; ## other code will set to false to quit
$redis->wait_for_messages($timeout) while $keep_going;
$redis->publish('topic_1', 'message');
Pure perl bindings for https://redis.io/
This version supports protocol 2.x (multi-bulk) or later of Redis available at https://github.com/antirez/redis/.
This documentation lists commands which are exercised in test suite, but additional commands will work correctly since protocol specifies enough information to support almost all commands with same piece of code with a little help of AUTOLOAD
.
Usually, running a command will wait for a response. However, if you're doing large numbers of requests, it can be more efficient to use what Redis calls pipelining: send multiple commands to Redis without waiting for a response, then wait for the responses that come in.
To use pipelining, add a coderef argument as the last argument to a command method call:
$r->set('foo', 'bar', sub {});
Pending responses to pipelined commands are processed in a single batch, as soon as at least one of the following conditions holds:
A non-pipelined (synchronous) command is called on the same connection
A pub/sub subscription command (one of subscribe
, unsubscribe
, psubscribe
, or punsubscribe
) is about to be called on the same connection.
One of "wait_all_responses" or "wait_one_response" methods is called explicitly.
The coderef you supply to a pipelined command method is invoked once the response is available. It takes two arguments, $reply
and $error
. If $error
is defined, it contains the text of an error reply sent by the Redis server. Otherwise, $reply
is the non-error reply. For almost all commands, that means it's undef
, or a defined but non-reference scalar, or an array ref of any of those; but see "keys", "info", and "exec".
Note the contrast with synchronous commands, which throw an exception on receipt of an error reply, or return a non-error reply directly.
The fact that pipelined commands never throw an exception can be particularly useful for Redis transactions; see "exec".
There is no encoding feature anymore, it has been deprecated and finally removed. This module consider that any data sent to the Redis server is a binary data. And it doesn't do anything when getting data from the Redis server.
So, if you are working with character strings, you should pre-encode or post-decode it if needed !
my $r = Redis->new; # $ENV{REDIS_SERVER} or 127.0.0.1:6379
my $r = Redis->new( server => '192.168.0.1:6379', debug => 0 );
my $r = Redis->new( server => '192.168.0.1:6379', encoding => undef );
my $r = Redis->new( sock => '/path/to/sock' );
my $r = Redis->new( reconnect => 60, every => 5000 );
my $r = Redis->new( password => 'boo' );
my $r = Redis->new( on_connect => sub { my ($redis) = @_; ... } );
my $r = Redis->new( name => 'my_connection_name' );
my $r = Redis->new( name => sub { "cache-for-$$" });
my $redis = Redis->new(sentinels => [ '127.0.0.1:12345', '127.0.0.1:23456' ],
service => 'mymaster');
## Connect via a list of Sentinels to a given service
my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
## Same, but with connection, read and write timeout on the sentinel hosts
my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
sentinels_cnx_timeout => 0.1,
sentinels_read_timeout => 1,
sentinels_write_timeout => 1,
);
server
The server
parameter specifies the Redis server we should connect to, via TCP. Use the 'IP:PORT' format. If no server
option is present, we will attempt to use the REDIS_SERVER
environment variable. If neither of those options are present, it defaults to '127.0.0.1:6379'.
Alternatively you can use the sock
parameter to specify the path of the UNIX domain socket where the Redis server is listening.
Alternatively you can use the sentinels
parameter and the service
parameter to specify a list of sentinels to contact and try to get the address of the given service name. sentinels
must be an ArrayRef and service
an Str.
The REDIS_SERVER
can be used for UNIX domain sockets too. The following formats are supported:
/path/to/sock
unix:/path/to/sock
127.0.0.1:11011
tcp:127.0.0.1:11011
reconnect
, every
The reconnect
option enables auto-reconnection mode. If we cannot connect to the Redis server, or if a network write fails, we enter retry mode. We will try a new connection every every
microseconds (1 ms by default), up-to reconnect
seconds.
Be aware that read errors will always thrown an exception, and will not trigger a retry until the new command is sent.
If we cannot re-establish a connection after reconnect
seconds, an exception will be thrown.
conservative_reconnect
conservative_reconnect
option makes sure that reconnection is only attempted when no pending command is ongoing. For instance, if you're doing <$redis-
incr('key')>>, and if the server properly understood and processed the command, but the network connection is dropped just before the server replies : the command has been processed but the client doesn't know it. In this situation, if reconnect is enabled, the Redis client will reconnect and send the incr
command *again*. If it succeeds, at the end the key as been incremented *two* times. To avoid this issue, you can set the conservative_reconnect
option to a true value. In this case, the client will reconnect only if no request is pending. Otherwise it will die with the message: reconnect disabled while responses are pending and safe reconnect mode enabled
.
cnx_timeout
The cnx_timeout
option enables connection timeout. The Redis client will wait at most that number of seconds (can be fractional) before giving up connecting to a server.
sentinels_cnx_timeout
The sentinels_cnx_timeout
option enables sentinel connection timeout. When using the sentinels feature, Redis client will wait at most that number of seconds (can be fractional) before giving up connecting to a sentinel. Default: 0.1
read_timeout
The read_timeout
option enables read timeout. The Redis client will wait at most that number of seconds (can be fractional) before giving up when reading from the server.
sentinels_read_timeout
The sentinels_read_timeout
option enables sentinel read timeout. When using the sentinels feature, the Redis client will wait at most that number of seconds (can be fractional) before giving up when reading from a sentinel server. Default: 1
write_timeout
The write_timeout
option enables write timeout. The Redis client will wait at most that number of seconds (can be fractional) before giving up when reading from the server.
sentinels_write_timeout
The sentinels_write_timeout
option enables sentinel write timeout. When using the sentinels feature, the Redis client will wait at most that number of seconds (can be fractional) before giving up when reading from a sentinel server. Default: 1
password
If your Redis server requires authentication, you can use the password
attribute. After each established connection (at the start or when reconnecting), the Redis AUTH
command will be send to the server. If the password is wrong, an exception will be thrown and reconnect will be disabled.
on_connect
You can also provide a code reference that will be immediately after each successful connection. The on_connect
attribute is used to provide the code reference, and it will be called with the first parameter being the Redis object.
no_auto_connect_on_new
You can also provide no_auto_connect_on_new
in which case new
won't call $obj->connect
for you implicitly, you'll have to do that yourself. This is useful for figuring out how long connection setup takes so you can configure the cnx_timeout
appropriately.
no_sentinels_list_update
You can also provide no_sentinels_list_update
. By default (that is, without this option), when successfully contacting a sentinel server, the Redis client will ask it for the list of sentinels known for the given service, and merge it with its list of sentinels (in the sentinels
attribute). You can disable this behavior by setting no_sentinels_list_update
to a true value.
name
You can also set a name for each connection. This can be very useful for debugging purposes, using the CLIENT LIST
command. To set a connection name, use the name
parameter. You can use both a scalar value or a CodeRef. If the latter, it will be called after each connection, with the Redis object, and it should return the connection name to use. If it returns a undefined value, Redis will not set the connection name.
Please note that there are restrictions on the name you can set, the most important of which is, no spaces. See the CLIENT SETNAME documentation for all the juicy details. This feature is safe to use with all versions of Redis servers. If CLIENT SETNAME
support is not available (Redis servers 2.6.9 and above only), the name parameter is ignored.
debug
The debug
parameter enables debug information to STDERR, including all interactions with the server. You can also enable debug with the REDIS_DEBUG
environment variable.
$r->connect;
Connects to the Redis server. This is done by default when the obect is constructed using new()
, unless no_auto_connect_on_new
has been set. See this option in the new()
constructor.
$r->quit;
Closes the connection to the server. The quit
method does not support pipelined operation.
$r->ping || die "no server?";
The ping
method does not support pipelined operation.
Waits until all pending pipelined responses have been received, and invokes the pipeline callback for each one. See "PIPELINING".
Waits until the first pending pipelined response has been received, and invokes its callback. See "PIPELINING".
When one of "subscribe" or "psubscribe" is used, the Redis object will enter PubSub mode. When in PubSub mode only commands in this section, plus "quit", will be accepted.
If you plan on using PubSub and other Redis functions, you should use two Redis objects, one dedicated to PubSub and the other for regular commands.
All Pub/Sub commands receive a callback as the last parameter. This callback receives three arguments:
The published message.
The topic over which the message was sent.
The subscribed topic that matched the topic for the message. With "subscribe" these last two are the same, always. But with "psubscribe", this parameter tells you the pattern that matched.
See the Pub-Sub notes for more information about the messages you will receive on your callbacks after each "subscribe", "unsubscribe", "psubscribe" and "punsubscribe".
$r->publish($topic, $message);
Publishes the $message
to the $topic
.
$r->subscribe(
@topics_to_subscribe_to,
my $savecallback = sub {
my ($message, $topic, $subscribed_topic) = @_;
...
},
);
Subscribe one or more topics. Messages published into one of them will be received by Redis, and the specified callback will be executed.
$r->unsubscribe(@topic_list, $savecallback);
Stops receiving messages via $savecallback
for all the topics in @topic_list
. WARNING: it is important that you give the same calleback that you used for subscribtion. The value of the CodeRef must be the same, as this is how internally the code identifies it.
my @topic_matches = ('prefix1.*', 'prefix2.*');
$r->psubscribe(@topic_matches, my $savecallback = sub { my ($m, $t, $s) = @_; ... });
Subscribes a pattern of topics. All messages to topics that match the pattern will be delivered to the callback.
my @topic_matches = ('prefix1.*', 'prefix2.*');
$r->punsubscribe(@topic_matches, $savecallback);
Stops receiving messages via $savecallback
for all the topics pattern matches in @topic_list
. WARNING: it is important that you give the same calleback that you used for subscribtion. The value of the CodeRef must be the same, as this is how internally the code identifies it.
if ($r->is_subscriber) { say "We are in Pub/Sub mode!" }
Returns true if we are in Pub/Sub mode.
my $keep_going = 1; ## Set to false somewhere to leave the loop
my $timeout = 5;
$r->wait_for_messages($timeout) while $keep_going;
Blocks, waits for incoming messages and delivers them to the appropriate callbacks.
Requires a single parameter, the number of seconds to wait for messages. Use 0 to wait for ever. If a positive non-zero value is used, it will return after that amount of seconds without a single notification.
Please note that the timeout is not a commitment to return control to the caller at most each timeout
seconds, but more a idle timeout, were control will return to the caller if Redis is idle (as in no messages were received during the timeout period) for more than timeout
seconds.
The "wait_for_messages" call returns the number of messages processed during the run.
When a method returns more than one value, it checks the context and returns either a list of values or an ArrayRef.
Warning: the behaviour of the TRANSACTIONS commands when combined with pipelining is still under discussion, and you should NOT use them at the same time just now.
You can follow the discussion to see the open issues with this.
my @individual_replies = $r->exec;
exec
has special behaviour when run in a pipeline: the $reply
argument to the pipeline callback is an array ref whose elements are themselves [$reply, $error]
pairs. This means that you can accurately detect errors yielded by any command in the transaction, and without any exceptions being thrown.
my @keys = $r->keys( '*glob_pattern*' );
my $keys = $r->keys( '*glob_pattern*' ); # count of matching keys
Note that synchronous keys
calls in a scalar context return the number of matching keys (not an array ref of matching keys as you might expect). This does not apply in pipelined mode: assuming the server returns a list of keys, as expected, it is always passed to the pipeline callback as an array ref.
Hashes in Redis cannot be nested as in perl, if you want to store a nested hash, you need to serialize the hash first. If you want to have a named hash, you can use Redis-hashes. You will find an example in the tests of this module t/01-basic.t
Note that this commands sends the Lua script every time you call it. See "evalsha" and "script_load" for an alternative.
my $info_hash = $r->info;
The info
method is unique in that it decodes the server's response into a hashref, if possible. This decoding happens in both synchronous and pipelined modes.
$r->del(key [key ...])
Delete a key (see https://redis.io/commands/del)
$r->dump(key)
Return a serialized version of the value stored at the specified key. (see https://redis.io/commands/dump)
$r->exists(key)
Determine if a key exists (see https://redis.io/commands/exists)
$r->expire(key, seconds)
Set a key's time to live in seconds (see https://redis.io/commands/expire)
$r->expireat(key, timestamp)
Set the expiration for a key as a UNIX timestamp (see https://redis.io/commands/expireat)
$r->keys(pattern)
Find all keys matching the given pattern (see https://redis.io/commands/keys)
$r->migrate(host, port, key, destination-db, timeout, [COPY], [REPLACE])
Atomically transfer a key from a Redis instance to another one. (see https://redis.io/commands/migrate)
$r->move(key, db)
Move a key to another database (see https://redis.io/commands/move)
$r->object(subcommand, [arguments [arguments ...]])
Inspect the internals of Redis objects (see https://redis.io/commands/object)
$r->persist(key)
Remove the expiration from a key (see https://redis.io/commands/persist)
$r->pexpire(key, milliseconds)
Set a key's time to live in milliseconds (see https://redis.io/commands/pexpire)
$r->pexpireat(key, milliseconds-timestamp)
Set the expiration for a key as a UNIX timestamp specified in milliseconds (see https://redis.io/commands/pexpireat)
$r->pttl(key)
Get the time to live for a key in milliseconds (see https://redis.io/commands/pttl)
$r->randomkey()
Return a random key from the keyspace (see https://redis.io/commands/randomkey)
$r->rename(key, newkey)
Rename a key (see https://redis.io/commands/rename)
$r->renamenx(key, newkey)
Rename a key, only if the new key does not exist (see https://redis.io/commands/renamenx)
$r->restore(key, ttl, serialized-value)
Create a key using the provided serialized value, previously obtained using DUMP. (see https://redis.io/commands/restore)
$r->scan(cursor, [MATCH pattern], [COUNT count])
Incrementally iterate the keys space (see https://redis.io/commands/scan)
$r->sort(key, [BY pattern], [LIMIT offset count], [GET pattern [GET pattern ...]], [ASC|DESC], [ALPHA], [STORE destination])
Sort the elements in a list, set or sorted set (see https://redis.io/commands/sort)
$r->ttl(key)
Get the time to live for a key (see https://redis.io/commands/ttl)
$r->type(key)
Determine the type stored at key (see https://redis.io/commands/type)
$r->append(key, value)
Append a value to a key (see https://redis.io/commands/append)
$r->bitcount(key, [start end])
Count set bits in a string (see https://redis.io/commands/bitcount)
$r->bitop(operation, destkey, key [key ...])
Perform bitwise operations between strings (see https://redis.io/commands/bitop)
$r->bitpos(key, bit, [start], [end])
Find first bit set or clear in a string (see https://redis.io/commands/bitpos)
$r->blpop(key [key ...], timeout)
Remove and get the first element in a list, or block until one is available (see https://redis.io/commands/blpop)
$r->brpop(key [key ...], timeout)
Remove and get the last element in a list, or block until one is available (see https://redis.io/commands/brpop)
$r->brpoplpush(source, destination, timeout)
Pop a value from a list, push it to another list and return it; or block until one is available (see https://redis.io/commands/brpoplpush)
$r->decr(key)
Decrement the integer value of a key by one (see https://redis.io/commands/decr)
$r->decrby(key, decrement)
Decrement the integer value of a key by the given number (see https://redis.io/commands/decrby)
$r->get(key)
Get the value of a key (see https://redis.io/commands/get)
$r->getbit(key, offset)
Returns the bit value at offset in the string value stored at key (see https://redis.io/commands/getbit)
$r->getrange(key, start, end)
Get a substring of the string stored at a key (see https://redis.io/commands/getrange)
$r->getset(key, value)
Set the string value of a key and return its old value (see https://redis.io/commands/getset)
$r->incr(key)
Increment the integer value of a key by one (see https://redis.io/commands/incr)
$r->incrby(key, increment)
Increment the integer value of a key by the given amount (see https://redis.io/commands/incrby)
$r->incrbyfloat(key, increment)
Increment the float value of a key by the given amount (see https://redis.io/commands/incrbyfloat)
$r->mget(key [key ...])
Get the values of all the given keys (see https://redis.io/commands/mget)
$r->mset(key value [key value ...])
Set multiple keys to multiple values (see https://redis.io/commands/mset)
$r->msetnx(key value [key value ...])
Set multiple keys to multiple values, only if none of the keys exist (see https://redis.io/commands/msetnx)
$r->psetex(key, milliseconds, value)
Set the value and expiration in milliseconds of a key (see https://redis.io/commands/psetex)
$r->set(key, value, ['EX', seconds], ['PX', milliseconds], ['NX'|'XX'])
Set the string value of a key (see https://redis.io/commands/set). Example:
$r->set('key', 'test', 'EX', 60, 'NX')
$r->setbit(key, offset, value)
Sets or clears the bit at offset in the string value stored at key (see https://redis.io/commands/setbit)
$r->setex(key, seconds, value)
Set the value and expiration of a key (see https://redis.io/commands/setex)
$r->setnx(key, value)
Set the value of a key, only if the key does not exist (see https://redis.io/commands/setnx)
$r->setrange(key, offset, value)
Overwrite part of a string at key starting at the specified offset (see https://redis.io/commands/setrange)
$r->strlen(key)
Get the length of the value stored in a key (see https://redis.io/commands/strlen)
$r->hdel(key, field [field ...])
Delete one or more hash fields (see https://redis.io/commands/hdel)
$r->hexists(key, field)
Determine if a hash field exists (see https://redis.io/commands/hexists)
$r->hget(key, field)
Get the value of a hash field (see https://redis.io/commands/hget)
$r->hgetall(key)
Get all the fields and values in a hash (see https://redis.io/commands/hgetall)
$r->hincrby(key, field, increment)
Increment the integer value of a hash field by the given number (see https://redis.io/commands/hincrby)
$r->hincrbyfloat(key, field, increment)
Increment the float value of a hash field by the given amount (see https://redis.io/commands/hincrbyfloat)
$r->hkeys(key)
Get all the fields in a hash (see https://redis.io/commands/hkeys)
$r->hlen(key)
Get the number of fields in a hash (see https://redis.io/commands/hlen)
$r->hmget(key, field [field ...])
Get the values of all the given hash fields (see https://redis.io/commands/hmget)
$r->hmset(key, field value [field value ...])
Set multiple hash fields to multiple values (see https://redis.io/commands/hmset)
$r->hscan(key, cursor, [MATCH pattern], [COUNT count])
Incrementally iterate hash fields and associated values (see https://redis.io/commands/hscan)
$r->hset(key, field, value)
Set the string value of a hash field (see https://redis.io/commands/hset)
$r->hsetnx(key, field, value)
Set the value of a hash field, only if the field does not exist (see https://redis.io/commands/hsetnx)
$r->hvals(key)
Get all the values in a hash (see https://redis.io/commands/hvals)
$r->sadd(key, member [member ...])
Add one or more members to a set (see https://redis.io/commands/sadd)
$r->scard(key)
Get the number of members in a set (see https://redis.io/commands/scard)
$r->sdiff(key [key ...])
Subtract multiple sets (see https://redis.io/commands/sdiff)
$r->sdiffstore(destination, key [key ...])
Subtract multiple sets and store the resulting set in a key (see https://redis.io/commands/sdiffstore)
$r->sinter(key [key ...])
Intersect multiple sets (see https://redis.io/commands/sinter)
$r->sinterstore(destination, key [key ...])
Intersect multiple sets and store the resulting set in a key (see https://redis.io/commands/sinterstore)
$r->sismember(key, member)
Determine if a given value is a member of a set (see https://redis.io/commands/sismember)
$r->smembers(key)
Get all the members in a set (see https://redis.io/commands/smembers)
$r->smove(source, destination, member)
Move a member from one set to another (see https://redis.io/commands/smove)
$r->spop(key)
Remove and return a random member from a set (see https://redis.io/commands/spop)
$r->srandmember(key, [count])
Get one or multiple random members from a set (see https://redis.io/commands/srandmember)
$r->srem(key, member [member ...])
Remove one or more members from a set (see https://redis.io/commands/srem)
$r->sscan(key, cursor, [MATCH pattern], [COUNT count])
Incrementally iterate Set elements (see https://redis.io/commands/sscan)
$r->sunion(key [key ...])
Add multiple sets (see https://redis.io/commands/sunion)
$r->sunionstore(destination, key [key ...])
Add multiple sets and store the resulting set in a key (see https://redis.io/commands/sunionstore)
$r->zadd(key, score member [score member ...])
Add one or more members to a sorted set, or update its score if it already exists (see https://redis.io/commands/zadd)
$r->zcard(key)
Get the number of members in a sorted set (see https://redis.io/commands/zcard)
$r->zcount(key, min, max)
Count the members in a sorted set with scores within the given values (see https://redis.io/commands/zcount)
$r->zincrby(key, increment, member)
Increment the score of a member in a sorted set (see https://redis.io/commands/zincrby)
$r->zinterstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
Intersect multiple sorted sets and store the resulting sorted set in a new key (see https://redis.io/commands/zinterstore)
$r->zlexcount(key, min, max)
Count the number of members in a sorted set between a given lexicographical range (see https://redis.io/commands/zlexcount)
$r->zrange(key, start, stop, [WITHSCORES])
Return a range of members in a sorted set, by index (see https://redis.io/commands/zrange)
$r->zrangebylex(key, min, max, [LIMIT offset count])
Return a range of members in a sorted set, by lexicographical range (see https://redis.io/commands/zrangebylex)
$r->zrangebyscore(key, min, max, [WITHSCORES], [LIMIT offset count])
Return a range of members in a sorted set, by score (see https://redis.io/commands/zrangebyscore)
$r->zrank(key, member)
Determine the index of a member in a sorted set (see https://redis.io/commands/zrank)
$r->zrem(key, member [member ...])
Remove one or more members from a sorted set (see https://redis.io/commands/zrem)
$r->zremrangebylex(key, min, max)
Remove all members in a sorted set between the given lexicographical range (see https://redis.io/commands/zremrangebylex)
$r->zremrangebyrank(key, start, stop)
Remove all members in a sorted set within the given indexes (see https://redis.io/commands/zremrangebyrank)
$r->zremrangebyscore(key, min, max)
Remove all members in a sorted set within the given scores (see https://redis.io/commands/zremrangebyscore)
$r->zrevrange(key, start, stop, [WITHSCORES])
Return a range of members in a sorted set, by index, with scores ordered from high to low (see https://redis.io/commands/zrevrange)
$r->zrevrangebylex(key, max, min, [LIMIT offset count])
Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings. (see https://redis.io/commands/zrevrangebylex)
$r->zrevrangebyscore(key, max, min, [WITHSCORES], [LIMIT offset count])
Return a range of members in a sorted set, by score, with scores ordered from high to low (see https://redis.io/commands/zrevrangebyscore)
$r->zrevrank(key, member)
Determine the index of a member in a sorted set, with scores ordered from high to low (see https://redis.io/commands/zrevrank)
$r->zscan(key, cursor, [MATCH pattern], [COUNT count])
Incrementally iterate sorted sets elements and associated scores (see https://redis.io/commands/zscan)
$r->zscore(key, member)
Get the score associated with the given member in a sorted set (see https://redis.io/commands/zscore)
$r->zunionstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
Add multiple sorted sets and store the resulting sorted set in a new key (see https://redis.io/commands/zunionstore)
$r->pfadd(key, element [element ...])
Adds the specified elements to the specified HyperLogLog. (see https://redis.io/commands/pfadd)
$r->pfcount(key [key ...])
Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). (see https://redis.io/commands/pfcount)
$r->pfmerge(destkey, sourcekey [sourcekey ...])
Merge N different HyperLogLogs into a single one. (see https://redis.io/commands/pfmerge)
$r->pubsub(subcommand, [argument [argument ...]])
Inspect the state of the Pub/Sub subsystem (see https://redis.io/commands/pubsub)
$r->discard()
Discard all commands issued after MULTI (see https://redis.io/commands/discard)
$r->exec()
Execute all commands issued after MULTI (see https://redis.io/commands/exec)
$r->multi()
Mark the start of a transaction block (see https://redis.io/commands/multi)
$r->unwatch()
Forget about all watched keys (see https://redis.io/commands/unwatch)
$r->watch(key [key ...])
Watch the given keys to determine execution of the MULTI/EXEC block (see https://redis.io/commands/watch)
$r->eval(script, numkeys, key [key ...], arg [arg ...])
Execute a Lua script server side (see https://redis.io/commands/eval)
$r->evalsha(sha1, numkeys, key [key ...], arg [arg ...])
Execute a Lua script server side (see https://redis.io/commands/evalsha)
$r->script_exists(script [script ...])
Check existence of scripts in the script cache. (see https://redis.io/commands/script-exists)
$r->script_flush()
Remove all the scripts from the script cache. (see https://redis.io/commands/script-flush)
$r->script_kill()
Kill the script currently in execution. (see https://redis.io/commands/script-kill)
$r->script_load(script)
Load the specified Lua script into the script cache. (see https://redis.io/commands/script-load)
$r->auth(password)
Authenticate to the server (see https://redis.io/commands/auth)
$r->echo(message)
Echo the given string (see https://redis.io/commands/echo)
$r->ping()
Ping the server (see https://redis.io/commands/ping)
$r->quit()
Close the connection (see https://redis.io/commands/quit)
$r->select(index)
Change the selected database for the current connection (see https://redis.io/commands/select)
$r->bgrewriteaof()
Asynchronously rewrite the append-only file (see https://redis.io/commands/bgrewriteaof)
$r->bgsave()
Asynchronously save the dataset to disk (see https://redis.io/commands/bgsave)
$r->client_getname()
Get the current connection name (see https://redis.io/commands/client-getname)
$r->client_kill([ip:port], [ID client-id], [TYPE normal|slave|pubsub], [ADDR ip:port], [SKIPME yes/no])
Kill the connection of a client (see https://redis.io/commands/client-kill)
$r->client_list()
Get the list of client connections (see https://redis.io/commands/client-list)
$r->client_pause(timeout)
Stop processing commands from clients for some time (see https://redis.io/commands/client-pause)
$r->client_setname(connection-name)
Set the current connection name (see https://redis.io/commands/client-setname)
$r->cluster_slots()
Get array of Cluster slot to node mappings (see https://redis.io/commands/cluster-slots)
$r->command()
Get array of Redis command details (see https://redis.io/commands/command)
$r->command_count()
Get total number of Redis commands (see https://redis.io/commands/command-count)
$r->command_getkeys()
Extract keys given a full Redis command (see https://redis.io/commands/command-getkeys)
$r->command_info(command-name [command-name ...])
Get array of specific Redis command details (see https://redis.io/commands/command-info)
$r->config_get(parameter)
Get the value of a configuration parameter (see https://redis.io/commands/config-get)
$r->config_resetstat()
Reset the stats returned by INFO (see https://redis.io/commands/config-resetstat)
$r->config_rewrite()
Rewrite the configuration file with the in memory configuration (see https://redis.io/commands/config-rewrite)
$r->config_set(parameter, value)
Set a configuration parameter to the given value (see https://redis.io/commands/config-set)
$r->dbsize()
Return the number of keys in the selected database (see https://redis.io/commands/dbsize)
$r->debug_object(key)
Get debugging information about a key (see https://redis.io/commands/debug-object)
$r->debug_segfault()
Make the server crash (see https://redis.io/commands/debug-segfault)
$r->flushall()
Remove all keys from all databases (see https://redis.io/commands/flushall)
$r->flushdb()
Remove all keys from the current database (see https://redis.io/commands/flushdb)
$r->info([section])
Get information and statistics about the server (see https://redis.io/commands/info)
$r->lastsave()
Get the UNIX time stamp of the last successful save to disk (see https://redis.io/commands/lastsave)
$r->lindex(key, index)
Get an element from a list by its index (see https://redis.io/commands/lindex)
$r->linsert(key, BEFORE|AFTER, pivot, value)
Insert an element before or after another element in a list (see https://redis.io/commands/linsert)
$r->llen(key)
Get the length of a list (see https://redis.io/commands/llen)
$r->lpop(key)
Remove and get the first element in a list (see https://redis.io/commands/lpop)
$r->lpush(key, value [value ...])
Prepend one or multiple values to a list (see https://redis.io/commands/lpush)
$r->lpushx(key, value)
Prepend a value to a list, only if the list exists (see https://redis.io/commands/lpushx)
$r->lrange(key, start, stop)
Get a range of elements from a list (see https://redis.io/commands/lrange)
$r->lrem(key, count, value)
Remove elements from a list (see https://redis.io/commands/lrem)
$r->lset(key, index, value)
Set the value of an element in a list by its index (see https://redis.io/commands/lset)
$r->ltrim(key, start, stop)
Trim a list to the specified range (see https://redis.io/commands/ltrim)
$r->monitor()
Listen for all requests received by the server in real time (see https://redis.io/commands/monitor)
$r->role()
Return the role of the instance in the context of replication (see https://redis.io/commands/role)
$r->rpop(key)
Remove and get the last element in a list (see https://redis.io/commands/rpop)
$r->rpoplpush(source, destination)
Remove the last element in a list, append it to another list and return it (see https://redis.io/commands/rpoplpush)
$r->rpush(key, value [value ...])
Append one or multiple values to a list (see https://redis.io/commands/rpush)
$r->rpushx(key, value)
Append a value to a list, only if the list exists (see https://redis.io/commands/rpushx)
$r->save()
Synchronously save the dataset to disk (see https://redis.io/commands/save)
$r->shutdown([NOSAVE], [SAVE])
Synchronously save the dataset to disk and then shut down the server (see https://redis.io/commands/shutdown)
$r->slaveof(host, port)
Make the server a slave of another instance, or promote it as master (see https://redis.io/commands/slaveof)
$r->slowlog(subcommand, [argument])
Manages the Redis slow queries log (see https://redis.io/commands/slowlog)
$r->sync()
Internal command used for replication (see https://redis.io/commands/sync)
$r->time()
Return the current server time (see https://redis.io/commands/time)
The following persons contributed to this project (random order):
Aaron Crane (pipelining and AUTOLOAD caching support)
Dirk Vleugels
Flavio Poletti
Jeremy Zawodny
sunnavy at bestpractical.com
Thiago Berlitz Rondon
Ulrich Habel
Ivan Kruglov
Steffen Mueller <smueller@cpan.org>
Pedro Melo <melo@cpan.org>
Damien Krotkine <dams@cpan.org>
This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
<pre name="code" class="sql"><pre name="code" class="sql">1.查看安装的redis版本 jrhrpt01:/root# redis-server --version Redis server v=2.8.19 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=1138bcb7ae3eee5
Redis连接测试脚本 1.部署环境 OS: Windows 7 简体中文旗舰版 X64 SP1 Perl: ActivePerl-5.16.2.1602-MSWin32-x86-296513.msi Redis: redis-2.8.19.zip for Windows Perl Redis: Redis-1.966 安装方法:ppm install Redis 2.脚本内容 # redis
#!/usr/bin/perl use strict; use Redis; my $redis = Redis->new(server => '192.168.119.131:8080'); my $num; my $i; for ($i=1;$i<10000000;$i++){ $num = hash($i); $redis->select($num); $redis->se
1. Redis built-in Lua Script Redis支持内建持久化的Lua脚本的执行并返回结果。 使用" SCRIPT LOAD"命令将得到此脚本的SHA1 ID. redis-cli SCRIPT LOAD "$(cat ./myexample.lua) 使用"EVALSHA"命令传入SHA1,KEY和参数便能执行此脚本并返回结果。 “SCRIPT LOAD”详见http://r
Redis-Python redis 提供两个类 Redis 和 StrictRedis, StrictRedis 用于实现大部分官方的命令,Redis 是 StrictRedis 的子类,用于向后兼用旧版本。 redis 取出的结果默认是字节,我们可以设定 decode_responses=True 改成字符串。 import redis # 导入redis 模块 r = redis.Re
redis 常用API(python) 通用 API 使用 keys 查询所有键 keys = redis.keys() 使用 type 查看 结构类型 keys = redis.keys() for key in keys: log.info(redis.type(key)) 使用 dbsize 查看当前有哪些键 log.info(redis.dbsize()) 使用 exists
Redis-Pipeline 一. 概念 Redis客户端和服务端往往部署在不同的机器上,客户端命令的执行分为发送命令,命令排队,执行命令,返回结果四个步骤。其中发送命令和返回结果的时间称为Round Trip Time(RTT 往返时间)。 当客户端有大量的命令时,会有大量的往返时间,如果有N条命令要执行,就会有N个往返时间。因此业界有种说法是Redis的性能瓶颈往往是网络。 Pipeline机
-> 有两种用法,都和解引用有关。 第一种用法,就是解引用。 根据 -> 后面跟的符号的不同,解不同类型的引用, ->[] 表示解数组引用,->{} 表示解散列引用,->() 表示解子程序引用。 例子: $arr_ref = @array; $arr_ref->[0] 访问数组 @array 的第一个元素。 $hash_ref = %hash; $hash_ref->{foo} 访问 %hash
use Redis; use Sys::Hostname; use HTTP::Date qw(time2iso str2time time2iso time2isoz); use Net::SMTP; sub basic() { $host = hostname; @lines=qx|/sbin/ifconfig|; @ip; print "-" x
1.安装Redis mac安装:brew install redis 可以安装redis桌面查看工具:redis-desktop-manager Redis管理及监控工具:http://www.treesoft.cn/dms.html 2.安装redis for erlang驱动 https://github.com/wooga/eredis :redis for erlang https:/
本文转自:http://jiorry.iteye.com/blog/961172 memcached 和 redis 的set命令都有expire参数,可以设置key的过期时间。但是redis是一个可以对数据持久化的key-value database,它的key过期策略还是和memcached有所不同的。梳理,整理如下: redis通过expire命令来设置key的过期时间。 语法:redi
首先安装模块 pip install redis 案例1:连接redis数据库 import redis redis_con = redis.Redis(host='192.168.163.100', port=6379, db=0) # 与redis建立连接 redis_con.set("api_key", "api_value") # 将字符串传入数据库 print(redis_con.
http://blog.chinaunix.net/uid-26000296-id-3333558.html $! 根据上下文内容返回错误号或者错误串 $” 列表分隔符 $# 打印数字时默认的数字输出格式 $$ Perl解释器的进程ID $% 当前输出通道的当前页号 $& 与上个格式匹配的字符串 $( 当前进程的组ID$) 当前进程的有效组ID $* 设置1表示处理多行格式.现在多以/s
一、redis redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持
$a = array("1","2","3"); Redis::pipeline(function($pipe) { for ($i = 0; $i < count($a); $i++) { $pipe->set("key:$a", $a); } }); <<<<<<<<$a undefied 解决方法 $a = array("1","2","3"); Redis::
JDK 1、 解压 tar zxf xxx 2、全局配置 vim /etc/profile JAVA_HOME=/usr/java/jdk1.7.0_79 PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME PATH 3、让修改内容生效 source /etc/profile 4、验证 java -version Re
Perl是一种动态解释型的脚本语言。 最初的设计者为拉里·沃尔(Larry Wall),它于1987年12月18日发表。Perl借取了C、sed、awk、shell scripting 以及很多其他编程語言的特性。其中最重要的特性是他内部集成了正则表达式的功能,以及巨大的第三方代码库 CPAN。 2000年开始,拉里·沃尔着手开发Perl 6来作为Perl的后继,Perl 6语言的语法有很多转变,
主要内容:安装,DBI 接口 API,连接数据库,创建表,INSERT 操作,SELECT 操作,UPDATE 操作,DELETE 操作安装 SQLite3 可使用 Perl DBI 模块与 Perl 进行集成。Perl DBI 模块是 Perl 编程语言的数据库访问模块。它定义了一组提供标准数据库接口的方法、变量及规则。 下面显示了在 Linux/UNIX 机器上安装 DBI 模块的简单步骤: 如果您需要为 DBI 安装 SQLite 驱动程序,那么可按照以下步骤进行安装: DBI 接口 AP
本文向大家介绍Perl parse_line(),包括了Perl parse_line()的使用技巧和注意事项,需要的朋友参考一下 示例 使用parse_line()Text :: ParseWords: 输出:
什么是包裹? 包是一组代码,它们位于自己的命名空间中 命名空间是唯一变量名称的命名集合(也称为符号表)。 命名空间可防止包之间发生变量名冲突 软件包可以构建模块,这些模块在使用时不会破坏模块自身命名空间之外的变量和函数 The Package 语句 package语句将当前命名上下文切换到指定的命名空间(符号表) 如果命名包不存在,则首先创建新的命名空间。 $i = 1; print "$i\n"
囊括了perl程序员必需的编写和调试的所有工具,无论是对新手还是对老手都很合适
Dancer 是一个 Perl 语言的框架,用来快速开发Web应用。该项目参考 Ruby 语言的 Sinatra 项目。Dancer 脚本是一个独立的Web服务器,用它来编写Web应用是非常简单的,如下所示: 示例代码: #!/usr/bin/perluse Dancer;get '/hi' => sub { "Hello World!"};dance;