{"id":16934045,"url":"https://github.com/shogo82148/redis-fast","last_synced_at":"2025-03-17T07:32:16.841Z","repository":{"id":700444,"uuid":"13125836","full_name":"shogo82148/Redis-Fast","owner":"shogo82148","description":"fast perl binding for Redis database","archived":false,"fork":false,"pushed_at":"2024-03-08T16:32:47.000Z","size":937,"stargazers_count":25,"open_issues_count":9,"forks_count":21,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-15T21:17:24.418Z","etag":null,"topics":["amazon-elasticache","perl","redis","redis-database"],"latest_commit_sha":null,"homepage":"https://metacpan.org/release/Redis-Fast","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shogo82148.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-26T15:09:02.000Z","updated_at":"2023-12-27T14:39:14.000Z","dependencies_parsed_at":"2024-03-07T14:56:40.830Z","dependency_job_id":"9f86e1f9-ef7b-4fe6-b370-841c209032c7","html_url":"https://github.com/shogo82148/Redis-Fast","commit_stats":{"total_commits":834,"total_committers":49,"mean_commits":"17.020408163265305","dds":0.5407673860911271,"last_synced_commit":"3af53b65172b739dabe5164df12854f127f6ec48"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shogo82148%2FRedis-Fast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shogo82148%2FRedis-Fast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shogo82148%2FRedis-Fast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shogo82148%2FRedis-Fast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shogo82148","download_url":"https://codeload.github.com/shogo82148/Redis-Fast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852425,"owners_count":20358270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-elasticache","perl","redis","redis-database"],"created_at":"2024-10-13T20:51:10.352Z","updated_at":"2025-03-17T07:32:16.569Z","avatar_url":"https://github.com/shogo82148.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/shogo82148/Redis-Fast/workflows/Test/badge.svg)](https://github.com/shogo82148/Redis-Fast/actions) [![MetaCPAN Release](https://badge.fury.io/pl/Redis-Fast.svg)](https://metacpan.org/release/Redis-Fast)\n# NAME\n\nRedis::Fast - Perl binding for Redis database\n\n# SYNOPSIS\n\n    ## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379\n    my $redis = Redis::Fast-\u003enew;\n\n    my $redis = Redis::Fast-\u003enew(server =\u003e 'redis.example.com:8080');\n\n    ## Set the connection name (requires Redis 2.6.9)\n    my $redis = Redis::Fast-\u003enew(\n      server =\u003e 'redis.example.com:8080',\n      name =\u003e 'my_connection_name',\n    );\n    my $generation = 0;\n    my $redis = Redis::Fast-\u003enew(\n      server =\u003e 'redis.example.com:8080',\n      name =\u003e sub { \"cache-$$-\".++$generation },\n    );\n\n    ## Use Sentinels, possibly with password\n    my $redis = Redis::Fast-\u003enew(\n      sentinels =\u003e [ '10.0.0.1:16379', '10.0.0.2:16379', ],\n      service   =\u003e 'mymaster',\n      sentinels_password =\u003e 'TheB1gS3CR3T', # optional\n    );\n\n    ## Use UNIX domain socket\n    my $redis = Redis::Fast-\u003enew(sock =\u003e '/path/to/socket');\n\n    ## Enable auto-reconnect\n    ## Try to reconnect every 500ms up to 60 seconds until success\n    ## Die if you can't after that\n    my $redis = Redis::Fast-\u003enew(reconnect =\u003e 60, every =\u003e 500_000);\n\n    ## Try each 100ms up to 2 seconds (every is in microseconds)\n    my $redis = Redis::Fast-\u003enew(reconnect =\u003e 2, every =\u003e 100_000);\n\n    ## Disable the automatic utf8 encoding =\u003e much more performance\n    ## !!!! This will be the default after 2.000, see ENCODING below\n    my $redis = Redis::Fast-\u003enew(encoding =\u003e undef);\n\n    ## Use all the regular Redis commands, they all accept a list of\n    ## arguments\n    ## See http://redis.io/commands for full list\n    $redis-\u003eget('key');\n    $redis-\u003eset('key' =\u003e 'value');\n    $redis-\u003esort('list', 'DESC');\n    $redis-\u003esort(qw{list LIMIT 0 5 ALPHA DESC});\n\n    ## Add a coderef argument to run a command in the background\n    $redis-\u003esort(qw{list LIMIT 0 5 ALPHA DESC}, sub {\n      my ($reply, $error) = @_;\n      die \"Oops, got an error: $error\\n\" if defined $error;\n      print \"$_\\n\" for @$reply;\n    });\n    long_computation();\n    $redis-\u003ewait_all_responses;\n    ## or\n    $redis-\u003ewait_one_response();\n\n    ## Or run a large batch of commands in a pipeline\n    my %hash = _get_large_batch_of_commands();\n    $redis-\u003ehset('h', $_, $hash{$_}, sub {}) for keys %hash;\n    $redis-\u003ewait_all_responses;\n\n    ## Publish/Subscribe\n    $redis-\u003esubscribe(\n      'topic_1',\n      'topic_2',\n      sub {\n        my ($message, $topic, $subscribed_topic) = @_\n\n          ## $subscribed_topic can be different from topic if\n          ## you use psubscribe() with wildcards\n      }\n    );\n    $redis-\u003epsubscribe('nasdaq.*', sub {...});\n\n    ## Blocks and waits for messages, calls subscribe() callbacks\n    ##  ... forever\n    my $timeout = 10;\n    $redis-\u003ewait_for_messages($timeout) while 1;\n\n    ##  ... until some condition\n    my $keep_going = 1; ## other code will set to false to quit\n    $redis-\u003ewait_for_messages($timeout) while $keep_going;\n\n    $redis-\u003epublish('topic_1', 'message');\n\n# DESCRIPTION\n\n`Redis::Fast` is a wrapper around Salvatore Sanfilippo's\n[hiredis](https://github.com/redis/hiredis) C client.\nIt is compatible with [Redis.pm](https://github.com/melo/perl-redis).\n\nThis version supports protocol 2.x (multi-bulk) or later of Redis available at\n[https://github.com/antirez/redis/](https://github.com/antirez/redis/).\n\n## Reconnect on error\n\nBesides auto-reconnect when the connection is closed, `Redis::Fast` supports\nreconnecting on the specified errors by the `reconnect_on_error` option.\nHere's an example that will reconnect when receiving `READONLY` error:\n\n    my $r = Redis::Fast-\u003enew(\n      reconnect          =\u003e 1, # The value greater than 0 is required\n      reconnect_on_error =\u003e sub {\n        my ($error, $ret, $command) = @_;\n        if ($error =~ /READONLY You can't write against a read only slave/) {\n          # force reconnect\n          return 1;\n        }\n        # do nothing\n        return -1;\n      },\n    );\n\nThis feature is useful when using Amazon ElastiCache.\nOnce failover happens, Amazon ElastiCache will switch the master\nwe currently connected with to a slave,\nleading to the following writes fails with the error `READONLY`.\nUsing `reconnect_on_error`, we can force the connection to reconnect on this error\nin order to connect to the new master.\nIf your Elasticache Redis is enabled to be set an option for [close-on-slave-write](https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ParameterGroups.Redis.html#ParameterGroups.Redis.2-8-23),\nthis feature might be unnecessary.\n\nThe return value of `reconnect_on_error` should be greater than `-2`. `-1` means that\n`Redis::Fast` behaves the same as without this option. `0` and greater than `0`\nmeans that `Redis::Fast` forces to reconnect and then\nwait for a next force reconnect until this value seconds elapse.\nThis unit is a second, and the type is double. For example, 0.01 means 10 milliseconds.\n\nNote: This feature is not supported for the subscribed mode.\n\n# PERFORMANCE IN SYNCHRONIZE MODE\n\n## Redis.pm\n\n    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...\n       00_ping:  8 wallclock secs ( 0.69 usr +  4.77 sys =  5.46 CPU) @ 5538.64/s (n=30241)\n        10_set:  8 wallclock secs ( 1.07 usr +  4.01 sys =  5.08 CPU) @ 5794.09/s (n=29434)\n      11_set_r:  7 wallclock secs ( 0.42 usr +  4.84 sys =  5.26 CPU) @ 5051.33/s (n=26570)\n        20_get:  8 wallclock secs ( 0.69 usr +  4.82 sys =  5.51 CPU) @ 5080.40/s (n=27993)\n      21_get_r:  7 wallclock secs ( 2.21 usr +  3.09 sys =  5.30 CPU) @ 5389.06/s (n=28562)\n       30_incr:  7 wallclock secs ( 0.69 usr +  4.73 sys =  5.42 CPU) @ 5671.77/s (n=30741)\n     30_incr_r:  7 wallclock secs ( 0.85 usr +  4.31 sys =  5.16 CPU) @ 5824.42/s (n=30054)\n      40_lpush:  8 wallclock secs ( 0.60 usr +  4.77 sys =  5.37 CPU) @ 5832.59/s (n=31321)\n       50_lpop:  7 wallclock secs ( 1.24 usr +  4.17 sys =  5.41 CPU) @ 5112.75/s (n=27660)\n      90_h_get:  7 wallclock secs ( 0.63 usr +  4.65 sys =  5.28 CPU) @ 5716.29/s (n=30182)\n      90_h_set:  7 wallclock secs ( 0.65 usr +  4.74 sys =  5.39 CPU) @ 5593.14/s (n=30147)\n\n## Redis::Fast\n\nRedis::Fast is 50% faster than Redis.pm.\n\n    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...\n       00_ping:  9 wallclock secs ( 0.18 usr +  4.84 sys =  5.02 CPU) @ 7939.24/s (n=39855)\n        10_set: 10 wallclock secs ( 0.31 usr +  5.40 sys =  5.71 CPU) @ 7454.64/s (n=42566)\n      11_set_r:  9 wallclock secs ( 0.31 usr +  4.87 sys =  5.18 CPU) @ 7993.05/s (n=41404)\n        20_get: 10 wallclock secs ( 0.27 usr +  4.84 sys =  5.11 CPU) @ 8350.68/s (n=42672)\n      21_get_r: 10 wallclock secs ( 0.32 usr +  5.17 sys =  5.49 CPU) @ 8238.62/s (n=45230)\n       30_incr:  9 wallclock secs ( 0.23 usr +  5.27 sys =  5.50 CPU) @ 8221.82/s (n=45220)\n     30_incr_r:  8 wallclock secs ( 0.28 usr +  4.91 sys =  5.19 CPU) @ 8092.29/s (n=41999)\n      40_lpush:  9 wallclock secs ( 0.18 usr +  5.06 sys =  5.24 CPU) @ 8312.02/s (n=43555)\n       50_lpop:  9 wallclock secs ( 0.20 usr +  4.84 sys =  5.04 CPU) @ 8010.12/s (n=40371)\n      90_h_get:  9 wallclock secs ( 0.19 usr +  5.51 sys =  5.70 CPU) @ 7467.72/s (n=42566)\n      90_h_set:  8 wallclock secs ( 0.28 usr +  4.83 sys =  5.11 CPU) @ 7724.07/s (n=39470)o\n\n# PERFORMANCE IN PIPELINE MODE\n\n    #!/usr/bin/perl\n    use warnings;\n    use strict;\n    use Time::HiRes qw/time/;\n    use Redis;\n\n    my $count = 100000;\n    {\n        my $r = Redis-\u003enew;\n        my $start = time;\n        for(1..$count) {\n            $r-\u003eset('hoge', 'fuga', sub{});\n        }\n        $r-\u003ewait_all_responses;\n        printf \"Redis.pm:\\n%.2f/s\\n\", $count / (time - $start);\n    }\n\n    {\n        my $r = Redis::Fast-\u003enew;\n        my $start = time;\n        for(1..$count) {\n            $r-\u003eset('hoge', 'fuga', sub{});\n        }\n        $r-\u003ewait_all_responses;\n        printf \"Redis::Fast:\\n%.2f/s\\n\", $count / (time - $start);\n    }\n\nRedis::Fast is 4x faster than Redis.pm in pipeline mode.\n\n    Redis.pm:\n    22588.95/s\n    Redis::Fast:\n    81098.01/s\n\n# AUTHOR\n\nIchinose Shogo \u003cshogo82148@gmail.com\u003e\n\n# SEE ALSO\n\n- [Redis.pm](https://github.com/melo/perl-redis)\n\n# LICENSE\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshogo82148%2Fredis-fast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshogo82148%2Fredis-fast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshogo82148%2Fredis-fast/lists"}