• Stars
    star
    23
  • Rank 1,009,023 (Top 21 %)
  • Language
    Perl
  • License
    Other
  • Created almost 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

fast perl binding for Redis database

Actions Status MetaCPAN Release

NAME

Redis::Fast - Perl binding for Redis database

SYNOPSIS

## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379
my $redis = Redis::Fast->new;

my $redis = Redis::Fast->new(server => 'redis.example.com:8080');

## Set the connection name (requires Redis 2.6.9)
my $redis = Redis::Fast->new(
  server => 'redis.example.com:8080',
  name => 'my_connection_name',
);
my $generation = 0;
my $redis = Redis::Fast->new(
  server => 'redis.example.com:8080',
  name => sub { "cache-$$-".++$generation },
);

## Use Sentinels, possibly with password
my $redis = Redis::Fast->new(
  sentinels => [ '10.0.0.1:16379', '10.0.0.2:16379', ],
  service   => 'mymaster',
  sentinels_password => 'TheB1gS3CR3T', # optional
);

## Use UNIX domain socket
my $redis = Redis::Fast->new(sock => '/path/to/socket');

## Enable auto-reconnect
## Try to reconnect every 500ms up to 60 seconds until success
## Die if you can't after that
my $redis = Redis::Fast->new(reconnect => 60, every => 500_000);

## Try each 100ms up to 2 seconds (every is in microseconds)
my $redis = Redis::Fast->new(reconnect => 2, every => 100_000);

## Disable the automatic utf8 encoding => much more performance
## !!!! This will be the default after 2.000, see ENCODING below
my $redis = Redis::Fast->new(encoding => undef);

## Use all the regular Redis commands, they all accept a list of
## arguments
## See http://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');

DESCRIPTION

Redis::Fast is a wrapper around Salvatore Sanfilippo's hiredis C client. It is compatible with Redis.pm.

This version supports protocol 2.x (multi-bulk) or later of Redis available at https://github.com/antirez/redis/.

Reconnect on error

Besides auto-reconnect when the connection is closed, Redis::Fast supports reconnecting on the specified errors by the reconnect_on_error option. Here's an example that will reconnect when receiving READONLY error:

my $r = Redis::Fast->new(
  reconnect          => 1, # The value greater than 0 is required
  reconnect_on_error => sub {
    my ($error, $ret, $command) = @_;
    if ($error =~ /READONLY You can't write against a read only slave/) {
      # force reconnect
      return 1;
    }
    # do nothing
    return -1;
  },
);

This feature is useful when using Amazon ElastiCache. Once failover happens, Amazon ElastiCache will switch the master we currently connected with to a slave, leading to the following writes fails with the error READONLY. Using reconnect_on_error, we can force the connection to reconnect on this error in order to connect to the new master. If your Elasticache Redis is enabled to be set an option for close-on-slave-write, this feature might be unnecessary.

The return value of reconnect_on_error should be greater than -2. -1 means that Redis::Fast behaves the same as without this option. 0 and greater than 0 means that Redis::Fast forces to reconnect and then wait for a next force reconnect until this value seconds elapse. This unit is a second, and the type is double. For example, 0.01 means 10 milliseconds.

Note: This feature is not supported for the subscribed mode.

PERFORMANCE IN SYNCHRONIZE MODE

Redis.pm

Benchmark: running 00_ping, 10_set, 11_set_r, 20_get, 21_get_r, 30_incr, 30_incr_r, 40_lpush, 50_lpop, 90_h_get, 90_h_set for at least 5 CPU seconds...
   00_ping:  8 wallclock secs ( 0.69 usr +  4.77 sys =  5.46 CPU) @ 5538.64/s (n=30241)
    10_set:  8 wallclock secs ( 1.07 usr +  4.01 sys =  5.08 CPU) @ 5794.09/s (n=29434)
  11_set_r:  7 wallclock secs ( 0.42 usr +  4.84 sys =  5.26 CPU) @ 5051.33/s (n=26570)
    20_get:  8 wallclock secs ( 0.69 usr +  4.82 sys =  5.51 CPU) @ 5080.40/s (n=27993)
  21_get_r:  7 wallclock secs ( 2.21 usr +  3.09 sys =  5.30 CPU) @ 5389.06/s (n=28562)
   30_incr:  7 wallclock secs ( 0.69 usr +  4.73 sys =  5.42 CPU) @ 5671.77/s (n=30741)
 30_incr_r:  7 wallclock secs ( 0.85 usr +  4.31 sys =  5.16 CPU) @ 5824.42/s (n=30054)
  40_lpush:  8 wallclock secs ( 0.60 usr +  4.77 sys =  5.37 CPU) @ 5832.59/s (n=31321)
   50_lpop:  7 wallclock secs ( 1.24 usr +  4.17 sys =  5.41 CPU) @ 5112.75/s (n=27660)
  90_h_get:  7 wallclock secs ( 0.63 usr +  4.65 sys =  5.28 CPU) @ 5716.29/s (n=30182)
  90_h_set:  7 wallclock secs ( 0.65 usr +  4.74 sys =  5.39 CPU) @ 5593.14/s (n=30147)

Redis::Fast

Redis::Fast is 50% faster than Redis.pm.

Benchmark: running 00_ping, 10_set, 11_set_r, 20_get, 21_get_r, 30_incr, 30_incr_r, 40_lpush, 50_lpop, 90_h_get, 90_h_set for at least 5 CPU seconds...
   00_ping:  9 wallclock secs ( 0.18 usr +  4.84 sys =  5.02 CPU) @ 7939.24/s (n=39855)
    10_set: 10 wallclock secs ( 0.31 usr +  5.40 sys =  5.71 CPU) @ 7454.64/s (n=42566)
  11_set_r:  9 wallclock secs ( 0.31 usr +  4.87 sys =  5.18 CPU) @ 7993.05/s (n=41404)
    20_get: 10 wallclock secs ( 0.27 usr +  4.84 sys =  5.11 CPU) @ 8350.68/s (n=42672)
  21_get_r: 10 wallclock secs ( 0.32 usr +  5.17 sys =  5.49 CPU) @ 8238.62/s (n=45230)
   30_incr:  9 wallclock secs ( 0.23 usr +  5.27 sys =  5.50 CPU) @ 8221.82/s (n=45220)
 30_incr_r:  8 wallclock secs ( 0.28 usr +  4.91 sys =  5.19 CPU) @ 8092.29/s (n=41999)
  40_lpush:  9 wallclock secs ( 0.18 usr +  5.06 sys =  5.24 CPU) @ 8312.02/s (n=43555)
   50_lpop:  9 wallclock secs ( 0.20 usr +  4.84 sys =  5.04 CPU) @ 8010.12/s (n=40371)
  90_h_get:  9 wallclock secs ( 0.19 usr +  5.51 sys =  5.70 CPU) @ 7467.72/s (n=42566)
  90_h_set:  8 wallclock secs ( 0.28 usr +  4.83 sys =  5.11 CPU) @ 7724.07/s (n=39470)o

PERFORMANCE IN PIPELINE MODE

#!/usr/bin/perl
use warnings;
use strict;
use Time::HiRes qw/time/;
use Redis;

my $count = 100000;
{
    my $r = Redis->new;
    my $start = time;
    for(1..$count) {
        $r->set('hoge', 'fuga', sub{});
    }
    $r->wait_all_responses;
    printf "Redis.pm:\n%.2f/s\n", $count / (time - $start);
}

{
    my $r = Redis::Fast->new;
    my $start = time;
    for(1..$count) {
        $r->set('hoge', 'fuga', sub{});
    }
    $r->wait_all_responses;
    printf "Redis::Fast:\n%.2f/s\n", $count / (time - $start);
}

Redis::Fast is 4x faster than Redis.pm in pipeline mode.

Redis.pm:
22588.95/s
Redis::Fast:
81098.01/s

AUTHOR

Ichinose Shogo [email protected]

SEE ALSO

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

More Repositories

1

androidbinary

Android binary file parser written in golang
Go
248
star
2

go-sql-proxy

a proxy package is a proxy driver for dabase/sql.
Go
188
star
3

actions-setup-perl

Setup Perl environment Action
Perl
68
star
4

TinySegmenterMaker

Python
67
star
5

web-jjy

[JJY](http://jjy.nict.go.jp/) emulator with web audio
JavaScript
65
star
6

actions-upload-release-asset

Yet Another Upload Release Asset Action
TypeScript
54
star
7

actions-goveralls

Coveralls GitHub Action with Go integration powered by mattn/goveralls
TypeScript
51
star
8

go-mecab

MeCab binding for Golang
Go
38
star
9

igo-javascript

Morphological analyzer for Node.js
JavaScript
37
star
10

svg2css

An Inkscape Plugin which converts SVG to HTML+CSS.
Python
34
star
11

actions-setup-mysql

TypeScript
28
star
12

MiniMessagePack

MiniMessagePack decodes and encodes MessagePack binaries. Handy for parsing MessagePack from inside Unity3d. It is possible to easily replace the MiniJSON.
C#
23
star
13

actions-setup-redis

Setup Redis database Action
TypeScript
22
star
14

zipjs

pure JavaScript ใง ZIPใ‚’ๅฑ•้–‹
JavaScript
22
star
15

p5-aws-lambda

AWS Lambda Layer for Perl5
Perl
22
star
16

actions-mutex

A GitHub Action for exclusive control
TypeScript
22
star
17

go-nginx-oauth2-adapter

Add oauth2 authentication layer with ngx_http_auth_request_module
Go
21
star
18

assets-life

Go
20
star
19

go-shuffle

Go
18
star
20

genjyuugothic-subsets

Shell
18
star
21

qrcode

Go
17
star
22

Grongish

ๆ—ฅๆœฌ่ชžใจใ‚ฐใƒญใƒณใ‚ฎ่ชžใฎ็›ธไบ’ๅค‰ๆ›ใ‚นใ‚ฏใƒชใƒ—ใƒˆ
Python
17
star
23

holidays-jp

Simple API that provides public holidays information in Japan
Go
16
star
24

go-gracedown

Go
16
star
25

acme-cert-updater

Python
15
star
26

go-retry

Go
14
star
27

txmanager

Go
12
star
28

go-webntp

ntp service via WebSocket
Go
12
star
29

go-tail

go-tail is an implementation of tail -F
Go
10
star
30

letscount

ใ€Œใใ‚Œใงใ‚‚ใญใ€‚็งใฏใฟใ‚“ใชใซใ€Œ็ต„ใฟๅˆใ‚ใ›็ˆ†็™บใฎใ™ใ”ใ•ใ€ใ‚’ๆ•™ใˆใŸใ„ใฎ๏ผๆญขใ‚ใชใ„ใง๏ผใ€
TypeScript
10
star
31

pointer

Pointer Utility Functions for Golang
Go
9
star
32

JO_RI_bot

็‹ผใจใƒœใƒƒใƒˆ
Python
9
star
33

actions-create-release

Yet Another Create Release Action
TypeScript
8
star
34

go-mysql-pool

create MySQL database for testing
Go
8
star
35

go-prove

Go
8
star
36

goa-v1

fork of https://github.com/goadesign/goa version 1
Go
8
star
37

myddlmaker

Go
7
star
38

go2xs

Go
7
star
39

IgoIME

Pure Javascript IME
JavaScript
7
star
40

aws-xray-yasdk-go

Yet Another AWS X-Ray SDK for Go
Go
7
star
41

TinySVM

Unofficial fork of TinySVM
C++
7
star
42

s3cli-mini

Golang port for AWS Command Line Interface S3 subcommand.
Go
7
star
43

ridgenative

AWS Lambda HTTP Proxy integration event bridge to Go net/http.
Go
6
star
44

docker-lambda

A fork of lambci/docker-lambda: Docker images and test runners that replicate the live AWS Lambda environment
Dockerfile
6
star
45

mecab

Unofficial fork of taku910/mecab (Yet another Japanese morphological analyzer)
C++
6
star
46

s3ftpgateway

Go
5
star
47

lambtrip

AWS Lambda wrapper for http.RoundTripper
Go
5
star
48

go-webtail

go porting for webtail(https://github.com/r7kamura/webtail)
Go
4
star
49

schemalex-deploy

database migration tool for mysql
Go
4
star
50

dotfiles

Setting files
Shell
4
star
51

fluent-bit-rpm

Shell
4
star
52

server-starter

Yet Another Go port of start_server utility (a.k.a. Server::Starter)
Go
4
star
53

git-dump-index

convert .git/index file into human readable format
C
4
star
54

actions-cfn-lint

GitHub Action of https://github.com/aws-cloudformation/cfn-python-lint/
Shell
4
star
55

Redis-Namespace

Perl
4
star
56

WaveZutaZutaJS

JavaScript
4
star
57

rdsmysql

The rdsmysql package is a SQL driver for Amazon RDS.
Go
4
star
58

op-sync

sync secrets from 1password
Go
4
star
59

cfn-mackerel-macro

Go
4
star
60

go-sfv

Go implementation for RFC 8941 Structured Field Values for HTTP
Go
4
star
61

mackerel-cloudwatch-forwarder

Forward metrics of AWS CloudWatch to Mackerel
Go
4
star
62

goat

Go Authentication Toolkit
Go
3
star
63

Iedenwa

ใ‚คใ‚จใƒ‡ใƒณใƒฏ New Twitter Client
3
star
64

go-weaktyping

go-weaktyping is a go package for weakly-typed-JSON
Go
3
star
65

jisx4061

Go
3
star
66

go-rgba4444

RGBA4444 image format for golang
Go
3
star
67

go-clockwork-base32

An Implementation Clockwork-Base32 for Go
Go
3
star
68

memoize

https://pkg.go.dev/golang.org/x/sync/singleflight with expiration.
Go
3
star
69

twopy

PythonistaใฎใŸใ‚ใฎ2chใƒฉใ‚คใƒ–ใƒฉใƒช"twopy"
Python
3
star
70

codebuild-golang

Golang Docker Image for CodeBuild
Dockerfile
3
star
71

std

Go
3
star
72

yaraus

Yaraus is Yet Another Ranged Unique id Supplier
Go
3
star
73

p5-AnySan-Provider-Slack

AnySan::Provider::Slack - AnySan provider for Slack
Perl
3
star
74

go-rerand

Generate random strings based on regular expressions.
Go
3
star
75

ape-slack

Slack porting of IRC reaction bot framework [ape](https://github.com/m0t0k1ch1/ape)
Go
3
star
76

go-deploy-shrine

Golang implementation of deploy shrine (https://github.com/MacoTasu/deploy-shrine)
Go
2
star
77

go-container

Go experimental containers library using generics
Go
2
star
78

oembed_tag

A Liquid tag for Jekyll sites that allows embedding website supporting oEmbed
Ruby
2
star
79

cfn-json-string-macro

A CloudFormation Macro that converts a JSON to a string
Python
2
star
80

actions-check-permissions

A GitHub Action for checking the permissions of GITHUB_TOKEN
Shell
2
star
81

ctxio

Go
2
star
82

jsheap

Heap(Priority Queue) for JavaScitpt
JavaScript
2
star
83

actions-github-app-token

Go
2
star
84

p5-Redis-Script

Perl
2
star
85

mecab-docker

Dockerfile for MeCab
Dockerfile
2
star
86

s3protocol

the RoundTripper interface for Amazon S3
Go
2
star
87

randsrc

collection of math/rand.Source implementations
Go
2
star
88

ssm-sign-proxy

A proxy which signs requests using AWS System Manager Parameter Store.
Go
2
star
89

cloudwatch-logs-agent-lite

Lightweight log forwarder with CloudWatch
Go
2
star
90

Ondulish-dict

Perl
1
star
91

ksl-cookbook

Cookbooks of Chef for KSLAB
Ruby
1
star
92

fakentpd

Golang fork of Fake Leap Second SNTP server written in Perl http://jjy.nict.go.jp/tsp/link/leap.html
Go
1
star
93

go-imageflux

URL builder for ImageFlux
Go
1
star
94

tweetsanalyzer

tweets.zipใ‚’่งฃๆžใ—ใŸใ„
JavaScript
1
star
95

contests

ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใ‚ณใƒณใƒ†ใ‚นใƒˆใฎๅ›ž็ญ”้›†
C++
1
star
96

oortcloud

simple web-socket/sever-sent-event to http proxy
Go
1
star
97

letscount-magic-square

ใ€Žใใ‚Œใงใ‚‚ใญใ€‚็งใฏใฟใ‚“ใชใซใ€Œ็ต„ใฟๅˆใ‚ใ›็ˆ†็™บใฎใ™ใ”ใ•ใ€ใ‚’ๆ•™ใˆใŸใ„ใฎ๏ผๆญขใ‚ใชใ„ใง๏ผใ€
JavaScript
1
star
98

hi

Go
1
star
99

pyimedic

Python module for handling dictionaries of IME
Python
1
star
100

aarm

AWS App Runner Manager
Go
1
star