pax_global_header00006660000000000000000000000064142461777230014527gustar00rootroot0000000000000052 comment=755a9296178e6438d7f72ffd0001f168eb87eba6 libvmod-redis-7.1-15.1/000077500000000000000000000000001424617772300145205ustar00rootroot00000000000000libvmod-redis-7.1-15.1/.github/000077500000000000000000000000001424617772300160605ustar00rootroot00000000000000libvmod-redis-7.1-15.1/.github/workflows/000077500000000000000000000000001424617772300201155ustar00rootroot00000000000000libvmod-redis-7.1-15.1/.github/workflows/main.yml000066400000000000000000000044041424617772300215660ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: runs-on: ubuntu-20.04 strategy: matrix: cc: - gcc - clang make_target: - check - distcheck configure_flags: - '' include: - cc: gcc make_target: lcov configure_flags: --enable-code-coverage steps: - uses: actions/checkout@v2 - name: Install packages run: | sudo apt-get update -q sudo apt-get install -qq \ automake autotools-dev lcov libedit-dev libeditline-dev libev-dev \ libncurses-dev libpcre2-dev libssl-dev libtool python-docutils \ python3-sphinx - name: Install Varnish Cache run: | wget --no-check-certificate https://varnish-cache.org/_downloads/varnish-7.1.0.tgz tar zxvf varnish-*.tgz pushd varnish-*/ ./autogen.sh CC='${{ matrix.cc }}' ./configure make -sj32 sudo make PREFIX='/usr/local' install sudo ldconfig popd - name: Install hiredis run: | wget --no-check-certificate https://github.com/redis/hiredis/archive/v1.0.2.zip -O hiredis-1.0.2.zip unzip hiredis-*.zip pushd hiredis-*/ make USE_SSL=1 sudo make USE_SSL=1 PREFIX='/usr/local' install sudo ldconfig popd - name: Install Redis run: | wget http://download.redis.io/releases/redis-6.0.10.tar.gz tar zxvf redis-*.tar.gz pushd redis-*/ make BUILD_TLS=yes sudo make BUILD_TLS=yes PREFIX='/usr/local' install sudo ldconfig popd - name: Build & test VMOD run: | ./autogen.sh CC='${{ matrix.cc }}' ./configure --prefix=/usr ${{ matrix.configure_flags }} make -j4 make ${{ matrix.make_target }} -j1 - name: Push code coverage if: ${{ matrix.make_target == 'lcov' }} run: | cp libvmod-redis-*-coverage.info codecov.info bash <(curl -s https://codecov.io/bash) -X gcov -X coveragepy - name: Show test report if: ${{ failure() }} run: | cat src/test-suite.log || exit 0 libvmod-redis-7.1-15.1/.gitignore000066400000000000000000000005211424617772300165060ustar00rootroot00000000000000Makefile Makefile.in .deps/ .libs/ *.o *.lo *.la *~ *.[1-9] *.log *.trs /aclocal.m4 /autom4te.cache/ /build-aux/ /config.h /config.h.in /config.log /config.status /configure /libtool /stamp-h1 /m4/libtool.m4 /m4/ltoptions.m4 /m4/ltsugar.m4 /m4/ltversion.m4 /m4/lt~obsolete.m4 /src/vcc_*_if.c /src/vcc_*_if.h /src/vmod_*rst /.vagrant/ libvmod-redis-7.1-15.1/COPYING000066400000000000000000000002111424617772300155450ustar00rootroot00000000000000Copyright (c) 2014-2022 Carlos Abalde You're free to use and distribute this under terms in the LICENSE file. libvmod-redis-7.1-15.1/LICENSE000066400000000000000000000024061424617772300155270ustar00rootroot00000000000000Copyright (c) 2014-2022 Carlos Abalde Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. libvmod-redis-7.1-15.1/Makefile.am000066400000000000000000000005131424617772300165530ustar00rootroot00000000000000ACLOCAL_AMFLAGS = -I m4 -I ${VARNISHAPI_DATAROOTDIR}/aclocal SUBDIRS = src dist_doc_DATA = README.rst LICENSE # lcov support CODE_COVERAGE_OUTPUT_DIRECTORY = lcov CODE_COVERAGE_IGNORE_PATTERN = "/usr/*" crc16.c sha1.c CODE_COVERAGE_GENHTML_OPTIONS = --prefix $(abs_top_srcdir) @CODE_COVERAGE_RULES@ lcov: check-code-coverage libvmod-redis-7.1-15.1/README.rst000066400000000000000000000240031424617772300162060ustar00rootroot00000000000000 .. image:: https://github.com/carlosabalde/libvmod-redis/workflows/CI/badge.svg?branch=7.1 :alt: GitHub Actions CI badge :target: https://github.com/carlosabalde/libvmod-redis/actions .. image:: https://codecov.io/gh/carlosabalde/libvmod-redis/branch/7.1/graph/badge.svg :alt: Codecov badge :target: https://codecov.io/gh/carlosabalde/libvmod-redis VMOD using the `synchronous hiredis library API `_ to access Redis servers from VCL. Highlights: * **Full support for execution of LUA scripts** (i.e. ``EVAL`` command), including optimistic automatic execution of ``EVALSHA`` commands. * **All Redis reply data types are supported**, including partial support to access to components of simple (i.e. not nested) array replies. * **Redis pipelines are not (and won't be) supported**. LUA scripting, which is fully supported by the VMOD, it's a much more flexible alternative to pipelines for atomic execution and minimizing latency. Pipelines are hard to use and error prone, specially when using the ``WATCH`` command. * **Support for classic Redis deployments** using multiple replicated Redis servers **and for clustered deployments based on Redis Cluster**. * **Support for multiple databases and multiple Redis connections**, local to each Varnish worker thread, or shared using one or more pools. * **Support for smart command execution**, selecting the destination server according with the preferred role (i.e. master or slave) and with distance and healthiness metrics collected during execution. * **Support for Redis Sentinel**, allowing automatic discovery of sick / healthy servers and changes in their roles. Please, check out `the project wiki `_ for some extra information and useful links. Looking for official support for this VMOD? Please, contact `Allenta Consulting `_, a `Varnish Software Premium partner `_. SYNOPSIS ======== import redis; :: ## ## Subnets. ## Function subnets(STRING masks="") ## ## Sentinels. ## Function sentinels( STRING locations="", INT period=60, INT connection_timeout=500, INT command_timeout=0, ENUM { RESP2, RESP3, default } protocol="default", BOOL tls=false, STRING tls_cafile="", STRING tls_capath="", STRING tls_certfile="", STRING tls_keyfile="", STRING tls_sni="", STRING password="") ## ## Proxy. ## # Instance selection. Function VOID use(STRING db) # Proxied methods. Method VOID .add_server(..., STRING db="") Function VOID command(..., STRING db="") Function VOID timeout(..., STRING db="") Function VOID retries(..., STRING db="") ... Method STRING .stats(..., STRING db="") Method INT .counter(..., STRING db="") ## ## Databases. ## # Constructor. Object db( STRING location="", ENUM { master, slave, auto, cluster } type="auto", INT connection_timeout=1000, INT connection_ttl=0, INT command_timeout=0, INT max_command_retries=0, BOOL shared_connections=true, INT max_connections=128, ENUM { RESP2, RESP3, default } protocol="default", BOOL tls=false, STRING tls_cafile="", STRING tls_capath="", STRING tls_certfile="", STRING tls_keyfile="", STRING tls_sni="", STRING user="", STRING password="", INT sickness_ttl=60, BOOL ignore_slaves=false, INT max_cluster_hops=32) Method VOID .add_server( STRING location, ENUM { master, slave, auto, cluster } type) # Command execution. Method VOID .command(STRING name) Method VOID .timeout(INT command_timeout) Method VOID .retries(INT max_command_retries) Method VOID .push(STRING arg) Method VOID .execute(BOOL master=true) # Access to replies. Method BOOL .replied() Method BOOL .reply_is_error() Method BOOL .reply_is_nil() Method BOOL .reply_is_status() Method BOOL .reply_is_integer() Method BOOL .reply_is_boolean() Method BOOL .reply_is_double() Method BOOL .reply_is_string() Method BOOL .reply_is_array() Method STRING .get_reply() Method STRING .get_error_reply() Method STRING .get_status_reply() Method INT .get_integer_reply() Method BOOL .get_boolean_reply() Method REAL .get_double_reply() Method STRING .get_string_reply() Method INT .get_array_reply_length() Method BOOL .array_reply_is_error(INT index) Method BOOL .array_reply_is_nil(INT index) Method BOOL .array_reply_is_status(INT index) Method BOOL .array_reply_is_integer(INT index) Method BOOL .array_reply_is_boolean(INT index) Method BOOL .array_reply_is_double(INT index) Method BOOL .array_reply_is_string(INT index) Method BOOL .array_reply_is_array(INT index) Method STRING .get_array_reply_value(INT index) # Other. Method VOID .free() Method STRING .stats( ENUM { json, prometheus } format="json", BOOL stream=0, STRING prometheus_name_prefix="vmod_redis_", BOOL prometheus_default_labels=1, STRING prometheus_extra_labels="") Method INT .counter(STRING name) EXAMPLES ======== Single server ------------- :: sub vcl_init { # VMOD configuration: simple case, keeping up to one Redis connection # per Varnish worker thread. new db = redis.db( location="192.168.1.100:6379", type=master, connection_timeout=500, shared_connections=false, max_connections=1); } sub vcl_deliver { # Simple command execution. db.command("SET"); db.push("foo"); db.push("Hello world!"); db.execute(); # LUA scripting. db.command("EVAL"); db.push({" redis.call('SET', KEYS[1], ARGV[1]) redis.call('SET', KEYS[2], ARGV[1]) "}); db.push("2"); db.push("foo"); db.push("bar"); db.push("Atomic hello world!"); db.execute(); # Array replies, checking & accessing to reply. db.command("MGET"); db.push("foo"); db.push("bar"); db.execute(); if ((db.reply_is_array()) && (db.get_array_reply_length() == 2)) { set resp.http.X-Foo = db.get_array_reply_value(0); set resp.http.X-Bar = db.get_array_reply_value(1); } } Multiple servers ---------------- :: sub vcl_init { # VMOD configuration: master-slave replication, keeping up to two # Redis connections per Varnish worker thread (up to one to the master # server & up to one to the closest slave server). redis.subnets( masks={" 0 192.168.1.102/32, 1 192.168.1.103/32, 2 0.0.0.0/32 "}); new db = redis.db( location="192.168.1.100:6379", type=master, connection_timeout=500, shared_connections=false, max_connections=2); db.add_server("192.168.1.101:6379", slave); db.add_server("192.168.1.102:6379", slave); db.add_server("192.168.1.103:6379", slave); } sub vcl_deliver { # SET submitted to the master server. db.command("SET"); db.push("foo"); db.push("Hello world!"); db.execute(); # GET submitted to one of the slave servers. db.command("GET"); db.push("foo"); db.execute(false); set req.http.X-Foo = db.get_string_reply(); } Clustered setup --------------- :: sub vcl_init { # VMOD configuration: clustered setup, keeping up to 100 Redis # connections per server, all shared between all Varnish worker threads. # Two initial cluster servers are provided; remaining servers are # automatically discovered. new db = redis.db( location="192.168.1.100:6379", type=cluster, connection_timeout=500, shared_connections=true, max_connections=128, max_cluster_hops=16); db.add_server("192.168.1.101:6379", cluster); } sub vcl_deliver { # SET internally routed to the destination server. db.command("SET"); db.push("foo"); db.push("Hello world!"); db.execute(); # GET internally routed to the destination server. db.command("GET"); db.push("foo"); db.execute(false); set req.http.X-Foo = db.get_string_reply(); } INSTALLATION ============ The source tree is based on autotools to configure the building, and does also have the necessary bits in place to do functional unit tests using the varnishtest tool. **Beware this project contains multiples branches (master, 4.1, 4.0, etc.). Please, select the branch to be used depending on your Varnish Cache version (Varnish trunk → master, Varnish 4.1.x → 4.1, Varnish 4.0.x → 4.0, etc.).** Dependencies: * `hiredis `_ - minimalistic C Redis client library. * `libev `_ - full-featured and high-performance event loop. COPYRIGHT ========= See LICENSE for details. Public domain implementation of the SHA-1 cryptographic hash function by Steve Reid and embedded in this VMOD (required for the optimistic execution of ``EVALSHA`` commands) has been borrowed from `this project `_: * https://github.com/clibs/sha1/blob/master/sha1.c * https://github.com/clibs/sha1/blob/master/sha1.h BSD's implementation of the CRC-16 cryptographic hash function by Georges Menie & Salvatore Sanfilippo and embedded in this VMOD (required for the Redis Cluster slot calculation) has been borrowed from the `Redis project `_: * http://download.redis.io/redis-stable/src/crc16.c Copyright (c) 2014-2022 Carlos Abalde libvmod-redis-7.1-15.1/Vagrantfile000066400000000000000000000045021424617772300167060ustar00rootroot00000000000000# -*- mode: ruby -*- # vi: set ft=ruby : $script = <