vmod_redis(3)

๐Ÿ“ NAME ๐Ÿ“

vmod_redis โ€” ok so it's the Redis VMOD, bestie ๐Ÿ’…โœจ this is the page for vmod_redis(3), from the Library Functions Manual, and we're gonna get you fluent in it fr fr.


โœจ SYNOPSIS โœจ

Lowkey the whole menu, no edits, here it is ๐Ÿซถ

import redis [as name] [from "path"]

VOID subnets(STRING masks)

VOID sentinels(STRING locations, INT period, INT connection_timeout, INT command_timeout, ENUM protocol, BOOL tls, STRING tls_cafile, STRING tls_capath, STRING tls_certfile, STRING tls_keyfile, STRING tls_sni, STRING password)

VOID use(STRING db)

VOID add_server(STRING location, ENUM type, STRING db)

VOID command(STRING name, STRING db)

VOID timeout(INT command_timeout, STRING db)

VOID retries(INT max_command_retries, STRING db)

VOID push(STRING arg, STRING db)

VOID execute(BOOL master, STRING db)

VOID easy_execute(STRING command, [STRING cmd_arg1], [STRING cmd_arg2], [STRING cmd_arg3], [STRING cmd_arg4], [STRING cmd_arg5], [STRING cmd_arg6], [STRING cmd_arg7], [STRING cmd_arg8], [STRING cmd_arg9], [STRING cmd_arg10], [STRING cmd_arg11], [STRING cmd_arg12], [STRING cmd_arg13], [STRING cmd_arg14], [STRING cmd_arg15], [STRING cmd_arg16], [INT timeout], [INT retries], BOOL master, STRING db)

BOOL replied(STRING db)

BOOL reply_is_error(STRING db)

BOOL reply_is_nil(STRING db)

BOOL reply_is_status(STRING db)

BOOL reply_is_integer(STRING db)

BOOL reply_is_boolean(STRING db)

BOOL reply_is_double(STRING db)

BOOL reply_is_string(STRING db)

BOOL reply_is_array(STRING db)

STRING get_reply(STRING db)

STRING get_error_reply(STRING db)

STRING get_status_reply(STRING db)

INT get_integer_reply(STRING db)

BOOL get_boolean_reply(STRING db)

REAL get_double_reply(STRING db)

STRING get_string_reply(STRING db)

INT get_array_reply_length(STRING db)

BOOL array_reply_is_error(INT index, STRING db)

BOOL array_reply_is_nil(INT index, STRING db)

BOOL array_reply_is_status(INT index, STRING db)

BOOL array_reply_is_integer(INT index, STRING db)

BOOL array_reply_is_boolean(INT index, STRING db)

BOOL array_reply_is_double(INT index, STRING db)

BOOL array_reply_is_string(INT index, STRING db)

BOOL array_reply_is_array(INT index, STRING db)

STRING get_array_reply_value(INT index, STRING db)

VOID free(STRING db)

STRING stats(ENUM format, BOOL stream, STRING prometheus_name_prefix, BOOL prometheus_default_labels, STRING prometheus_extra_labels, STRING db)

INT counter(STRING name, STRING db)

new xdb = redis.db(STRING location, ENUM type, INT connection_timeout, INT connection_ttl, INT command_timeout, INT max_command_retries, BOOL shared_connections, INT max_connections, ENUM protocol, BOOL tls, STRING tls_cafile, STRING tls_capath, STRING tls_certfile, STRING tls_keyfile, STRING tls_sni, STRING user, STRING password, INT sickness_ttl, BOOL ignore_slaves, INT max_cluster_hops)

    VOID xdb.add_server(STRING location, ENUM type)

    VOID xdb.command(STRING name)

    VOID xdb.timeout(INT command_timeout)

    VOID xdb.retries(INT max_command_retries)

    VOID xdb.push(STRING arg)

    VOID xdb.execute(BOOL master)

    VOID xdb.easy_execute(STRING command, [STRING cmd_arg1], [STRING cmd_arg2], [STRING cmd_arg3], [STRING cmd_arg4], [STRING cmd_arg5], [STRING cmd_arg6], [STRING cmd_arg7], [STRING cmd_arg8], [STRING cmd_arg9], [STRING cmd_arg10], [STRING cmd_arg11], [STRING cmd_arg12], [STRING cmd_arg13], [STRING cmd_arg14], [STRING cmd_arg15], [STRING cmd_arg16], [INT timeout], [INT retries], BOOL master)

    BOOL xdb.replied()

    BOOL xdb.reply_is_error()

    BOOL xdb.reply_is_nil()

    BOOL xdb.reply_is_status()

    BOOL xdb.reply_is_integer()

    BOOL xdb.reply_is_boolean()

    BOOL xdb.reply_is_double()

    BOOL xdb.reply_is_string()

    BOOL xdb.reply_is_array()

    STRING xdb.get_reply()

    STRING xdb.get_error_reply()

    STRING xdb.get_status_reply()

    INT xdb.get_integer_reply()

    BOOL xdb.get_boolean_reply()

    REAL xdb.get_double_reply()

    STRING xdb.get_string_reply()

    INT xdb.get_array_reply_length()

    BOOL xdb.array_reply_is_error(INT index)

    BOOL xdb.array_reply_is_nil(INT index)

    BOOL xdb.array_reply_is_status(INT index)

    BOOL xdb.array_reply_is_integer(INT index)

    BOOL xdb.array_reply_is_boolean(INT index)

    BOOL xdb.array_reply_is_double(INT index)

    BOOL xdb.array_reply_is_string(INT index)

    BOOL xdb.array_reply_is_array(INT index)

    STRING xdb.get_array_reply_value(INT index)

    VOID xdb.free()

    STRING xdb.stats(ENUM format, BOOL stream, STRING prometheus_name_prefix, BOOL prometheus_default_labels, STRING prometheus_extra_labels)

    INT xdb.counter(STRING name)

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

So basically: this VMOD taps into Redis servers from VCL, and it does it using the synchronous hiredis library API. That's the whole vibe. ๐Ÿ”ฅ


๐ŸŽ€ VOID subnets(STRING masks="") ๐ŸŽ€

okay, the arguments ๐Ÿ’…

  • masks โ€” a comma-delimited list of weights + subnet masks, and it's used to pick between the servers associated with a database instance whenever commands get executed. Order matters โ€” do not shuffle it bestie. Only IPv4 addresses are supported, periodt. If you don't hand it over, the value sitting in the VMOD_REDIS_SUBNETS environment variable gets used instead.

This one is literally the move for setups where your Redis instances are deployed across multiple data centers or availability zones. ๐ŸŒโœจ

the description part ๐Ÿฆ‹

Using this function is not mandatory โ€” no pressure, it's optional. But if you do use it, it must be called during vcl_init, before you create any database instance. And here's the catch: if a database instance has already been created, calls to this function are silently ignored. ๐Ÿ’€ (no error, no warning, just vibes gone).


๐Ÿ‘‘ VOID sentinels(STRING locations, INT period, INT connection_timeout, INT command_timeout, ENUM protocol, BOOL tls, STRING tls_cafile, STRING tls_capath, STRING tls_certfile, STRING tls_keyfile, STRING tls_sni, STRING password) ๐Ÿ‘‘

Look at all those defaults tho ๐Ÿ˜ญ

VOID sentinels(
   STRING locations="",
   INT period=60,
   INT connection_timeout=500,
   INT command_timeout=0,
   ENUM {RESP2, RESP3, default} protocol=default,
   BOOL tls=0,
   STRING tls_cafile="",
   STRING tls_capath="",
   STRING tls_certfile="",
   STRING tls_keyfile="",
   STRING tls_sni="",
   STRING password=""
)

the arguments ๐Ÿ“

  • locations โ€” comma-delimited list of Redis Sentinel servers. Only host (IP or DNS name) + port format is allowed, that's the rule bestie. If you don't provide it, the value in the VMOD_REDIS_SENTINELS environment variable gets used.

This is useful in setups using non-clustered Redis instances, for two reasons: (1) to keep roles (i.e. master / slave) updated; and (2) to decrease the priority of unreachable servers when creating execution plans. Important: this is not designed for auto-discovery of Redis Servers. Not that. Never that. ๐Ÿ™ˆ

  • period โ€” how frequently (in seconds) Redis Sentinel periodical checks get executed. 0 means disabling periodical checks. โš ๏ธ Beware: (1) proactive checks are also executed anytime the VCL state is changed to warm; and (2) Sentinel Pub/Sub events are listened to and processed even when periodical checks are disabled. So yeah, turning it off doesn't fully turn it off ๐Ÿ˜ญ
  • connection_timeout โ€” connection timeout to the Redis Sentinel servers, in milliseconds. 0 means no timeout.
  • command_timeout โ€” command timeout when executing Redis Sentinel commands, in milliseconds. 0 means no timeout.
  • protocol โ€” the protocol used when talking to the Redis Sentinel servers. โš ๏ธ Beware: switching from RESP2 to RESP3 is only possible since Redis 6.0, and it uses an additional HELLO command when creating new Redis Sentinel connections. Also be careful โ€” RESP3 support is only available since hiredis 0.15.0. ๐Ÿ‘‘
  • tls โ€” if enabled, TLS will be used when establishing connections.
  • tls_cafile โ€” if not empty, this CA certificate file will be used to verify TLS connections.
  • tls_capath โ€” if not empty, this will be the directory storing trusted CA certificates used to verify TLS connections. If neither tls_cafile nor tls_capath are specified, the default system-wide trusted root certs configuration will apply.
  • tls_certfile โ€” if not empty, this certificate file will be used to authenticate TLS connections.
  • tls_keyfile โ€” if not empty, this private key file will be used to authenticate TLS connections.
  • tls_sni โ€” if not empty, this server name indication (i.e. SNI) will be used when establishing TLS connections.
  • password โ€” if not empty, requests for authentication using the AUTH command will be submitted when creating new Redis Sentinel connections. This password will be used for all Redis Sentinel servers. ๐Ÿ”

the description part ๐Ÿงš

Using this function is not mandatory. That's it, that's the whole note. ๐Ÿ’–


๐Ÿ’œ VOID use(STRING db) ๐Ÿ’œ

arguments

  • db โ€” the VCL name of the database instance.

description

Sets the current database instance to be used by the proxied methods (that's when none is specified with their own db argument). Main character energy โ€” every proxied method that doesn't name a db just follows whoever use() picked. ๐Ÿ’…


๐ŸŒธ VOID add_server(STRING location, ENUM type, STRING db) ๐ŸŒธ

VOID add_server(
   STRING location,
   ENUM {master, slave, auto, cluster} type,
   STRING db=""
)

description

Proxied version of .add_server(). ๐Ÿซถ


โญ VOID command(STRING name, STRING db="") โญ

description

Proxied version of .command().


๐Ÿฆ‹ VOID timeout(INT command_timeout, STRING db="") ๐Ÿฆ‹

description

Proxied version of .timeout().


๐ŸŽ€ VOID retries(INT max_command_retries, STRING db="") ๐ŸŽ€

description

Proxied version of .retries().


โœจ VOID push(STRING arg, STRING db="") โœจ

description

Proxied version of .push().


๐Ÿ”ฅ VOID execute(BOOL master=1, STRING db="") ๐Ÿ”ฅ

description

Proxied version of .execute().


VOID easy_execute(STRING command, [STRING cmd_arg1], [STRING cmd_arg2],
    [STRING cmd_arg3], [STRING cmd_arg4], [STRING cmd_arg5], [STRING
    cmd_arg6], [STRING cmd_arg7], [STRING cmd_arg8], [STRING cmd_arg9],
    [STRING cmd_arg10], [STRING cmd_arg11], [STRING cmd_arg12], [STRING
    cmd_arg13], [STRING cmd_arg14], [STRING cmd_arg15], [STRING cmd_arg16],
    [INT timeout], [INT retries], BOOL master, STRING db)
VOID easy_execute(
   STRING command,
   [STRING cmd_arg1],
   [STRING cmd_arg2],
   [STRING cmd_arg3],
   [STRING cmd_arg4],
   [STRING cmd_arg5],
   [STRING cmd_arg6],
   [STRING cmd_arg7],
   [STRING cmd_arg8],
   [STRING cmd_arg9],
   [STRING cmd_arg10],
   [STRING cmd_arg11],
   [STRING cmd_arg12],
   [STRING cmd_arg13],
   [STRING cmd_arg14],
   [STRING cmd_arg15],
   [STRING cmd_arg16],
   [INT timeout],
   [INT retries],
   BOOL master=1,
   STRING db=""
)

Description: Proxied version of .easy_execute(). it's literally the same energy, just through the proxy. no cap. ๐Ÿ’…

okay so now we've got a whole roster of little helpers that are all just proxied versions of their dot counterparts. each one takes an optional STRING db="" and does exactly what it says on the tin. here's the lineup, bestie:

  • BOOL replied(STRING db="") โ€” Proxied version of .replied(). ๐Ÿซถ
  • BOOL reply_is_error(STRING db="") โ€” Proxied version of .reply_is_error(). ๐Ÿ˜ญ
  • BOOL reply_is_nil(STRING db="") โ€” Proxied version of .reply_is_nil(). ๐Ÿ’€
  • BOOL reply_is_status(STRING db="") โ€” Proxied version of .reply_is_status(). โœจ
  • BOOL reply_is_integer(STRING db="") โ€” Proxied version of .reply_is_integer(). ๐Ÿ”ข
  • BOOL reply_is_boolean(STRING db="") โ€” Proxied version of .reply_is_boolean(). โœ…
  • BOOL reply_is_double(STRING db="") โ€” Proxied version of .reply_is_double(). ๐Ÿ’ฏ
  • BOOL reply_is_string(STRING db="") โ€” Proxied version of .reply_is_string(). ๐ŸŽ€
  • BOOL reply_is_array(STRING db="") โ€” Proxied version of .reply_is_array(). ๐ŸŒˆ
  • STRING get_reply(STRING db="") โ€” Proxied version of .get_reply(). ๐Ÿ’–
  • STRING get_error_reply(STRING db="") โ€” Proxied version of .get_error_reply(). ๐Ÿšจ
  • STRING get_status_reply(STRING db="") โ€” Proxied version of .get_status_reply(). ๐Ÿ“Ÿ
  • INT get_integer_reply(STRING db="") โ€” Proxied version of .get_integer_reply(). ๐Ÿ”ข
  • BOOL get_boolean_reply(STRING db="") โ€” Proxied version of .get_boolean_reply(). โœ…
  • REAL get_double_reply(STRING db="") โ€” Proxied version of .get_double_reply(). ๐Ÿ’ฏ
  • STRING get_string_reply(STRING db="") โ€” Proxied version of .get_string_reply(). ๐ŸŽ€
  • INT get_array_reply_length(STRING db="") โ€” Proxied version of .get_array_reply_length(). ๐Ÿ“
  • BOOL array_reply_is_error(INT index, STRING db="") โ€” Proxied version of .array_reply_is_error(). ๐Ÿ˜ญ
  • BOOL array_reply_is_nil(INT index, STRING db="") โ€” Proxied version of .array_reply_is_nil(). ๐Ÿ’€
  • BOOL array_reply_is_status(INT index, STRING db="") โ€” Proxied version of .array_reply_is_status(). โœจ
  • BOOL array_reply_is_integer(INT index, STRING db="") โ€” Proxied version of .array_reply_is_integer(). ๐Ÿ”ข
  • BOOL array_reply_is_boolean(INT index, STRING db="") โ€” Proxied version of .array_reply_is_boolean(). โœ…
  • BOOL array_reply_is_double(INT index, STRING db="") โ€” Proxied version of .array_reply_is_double(). ๐Ÿ’ฏ
  • BOOL array_reply_is_string(INT index, STRING db="") โ€” Proxied version of .array_reply_is_string(). ๐ŸŽ€
  • BOOL array_reply_is_array(INT index, STRING db="") โ€” Proxied version of .array_reply_is_array(). ๐ŸŒˆ
  • STRING get_array_reply_value(INT index, STRING db="") โ€” Proxied version of .get_array_reply_value(). ๐Ÿ’–
  • VOID free(STRING db="") โ€” Proxied version of .free(). ๐Ÿงน

and then we have the stats one, which is a little more extra:

STRING stats(ENUM format, BOOL stream, STRING prometheus_name_prefix, BOOL
    prometheus_default_labels, STRING prometheus_extra_labels, STRING db)
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="",
   STRING db=""
)

Description: Proxied version of .stats(). it's giving metrics, periodt. ๐Ÿ“Š

  • INT counter(STRING name, STRING db="") โ€” Proxied version of .counter(). ๐Ÿงฎ

and finally, the big one: creating a new database instance. it's giving main character energy. ๐Ÿ‘‘

new xdb = redis.db(STRING location, ENUM type, INT connection_timeout, INT
    connection_ttl, INT command_timeout, INT max_command_retries, BOOL
    shared_connections, INT max_connections, ENUM protocol, BOOL tls, STRING
    tls_cafile, STRING tls_capath, STRING tls_certfile, STRING tls_keyfile,
    STRING tls_sni, STRING user, STRING password, INT sickness_ttl, BOOL
    ignore_slaves, INT max_cluster_hops)
new xdb = redis.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=1,
   INT max_connections=128,
   ENUM {RESP2, RESP3, default} protocol=default,
   BOOL tls=0,
   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=0,
   INT max_cluster_hops=32
)

๐ŸŽ€ Arguments ๐ŸŽ€

  • location โ€” Redis connection string. Both host (IP or DNS name) + port and UNIX sockets are supported. Only the IP + port format is allowed when Redis Cluster support is enabled. Do not use DNS names in combination with redis.subnets() or redis.sentinels(). ๐Ÿšซ
  • type โ€” type of the Redis server referenced by location:
    • The auto value enables automatic discovery of the current role of the server on bootstrap time using the ROLE command. ๐Ÿ”
    • The cluster value enables Redis Cluster support, automatically discovering other servers in the cluster and their roles on demand using the CLUSTER SLOTS command. ๐ŸŒ
  • connection_timeout โ€” connection timeout (milliseconds; 0 means no timeout) to the Redis server. โณ
  • connection_ttl โ€” TTL (seconds) of Redis connections (0 means no TTL). Once the TTL of a connection is consumed, the module transparently reestablishes it. See "Client timeouts" in <http://redis.io/topics/clients> for extra information. ๐Ÿ•ฐ๏ธ
  • command_timeout โ€” command timeout (milliseconds; 0 means no timeout) when executing a Redis command. It can be overridden during command execution with .timeout(). โฑ๏ธ
  • max_command_retries โ€” number of retries to be executed after a failed command execution. It can be overridden during command execution with .retries(). ๐Ÿ”„
  • shared_connections โ€” if enabled, Redis connections are not local to Varnish worker threads, but shared by all threads using one or more pools. ๐Ÿค
  • max_connections โ€” When shared_connections is enabled, the VMOD creates one pool of Redis connections per location and database instance. This option sets the maximum number of connections in each pool. All Varnish worker threads using the same database instance will share connections in these pools. Pools are not shared between database instances.

Note that when Redis Cluster support is enabled for a database, each server is the cluster is internally labeled by the VMOD with its location (IP + port).

When shared_connections is disabled, Redis connections are local to each Varnish worker thread. This option sets the maximum number of Redis connections per Varnish worker thread. Each thread keeps up to one connection per location and database instance. If more than one (database, location) pair is available, incrementing this limit allows recycling of Redis connections.

WARNING: when creating multiple database instances, always use the same value in all instances using private connections. Otherwise you may experience inconsistent behavior. โš ๏ธ

  • protocol โ€” protocol to be used when talking to Redis Server servers. Beware switching from RESP2 to RESP3 is only possible since Redis 6.0 and it affects to type conversion rules. Be careful RESP3 support is only available since hiredis 0.15.0. ๐Ÿ˜ฌ
  • tsl โ€” if enabled, TLS will be used when establishing connections. ๐Ÿ”’
  • tls_cafile โ€” if not empty, this CA certificate file will be used to verify TLS connections. ๐Ÿ“œ
  • tls_capath โ€” if not empty, this will be the directory storing trusted CA certificates used to verify TLS connections. If neither tls_cafile nor tls_capath are specified, the default system-wide trusted root certs configuration will apply. ๐Ÿ“
  • tls_certfile โ€” if not empty, this certificate file will be used to authenticate TLS connections. ๐Ÿชช
  • tls_keyfile โ€” if not empty, this private key file will be used to authenticate TLS connections. ๐Ÿ”‘
  • tls_sni โ€” if not empty, this server name indication (i.e. SNI) will be used when establishing TLS connections. ๐ŸŒ
  • user โ€” if not empty and a password is provided, requests for authentication using the AUTH or HELLO command will include both the user name and its password. That enables usage of the Redis ACL system, available since Redis 6.0. ๐Ÿ‘ค
  • password โ€” if not empty, requests for authentication using the AUTH or HELLO command will be submitted when creating new Redis connections. This password will be used for all Redis servers, including discovered servers when Redis Cluster support is enabled. ๐Ÿ”‘
  • sickness_ttl โ€” TTL (seconds) of the sickness flag (0 means no sickness flags) associated to a Redis server. Once a server is flagged as sick and while the flag is not expired the module will lazily drop existing connections to that server and it will try to avoid it as much as possible when creating execution plans. This TTL is overridden when Redis Sentinel servers are configured and some Sentinel discovers an unreachable server. ๐Ÿค’
  • ignore_slaves โ€” okay bestie, if you enable this, slave servers are not considered when executing commands. In other words, enabling this option implicitly forces master == true when you're using the .execute() method. ๐Ÿ’…โœจ No cap.
  • max_cluster_hops โ€” this is the maximum number of redirections (0 means no limit) when executing a command and Redis Cluster support has been enabled. ๐ŸŒ€

Description

Creates a new database instance. โœจ Slay.


๐ŸŽ€ VOID xdb.add_server(STRING location, ENUM type)

VOID xdb.add_server(
      STRING location,
      ENUM {master, slave, auto, cluster} type
)

Arguments

  • location โ€” Redis connection string. Both host (IP or DNS name) + port and UNIX sockets are supported. If Redis Cluster support has been enabled only the IP + port format is allowed. Do not use DNS names in combination with redis.subnets() or redis.sentinels(). ๐Ÿšซ
  • type โ€” type of the Redis server referenced by location:
    • The auto value enables automatic discovery of the current role of the server on bootstrap time using the ROLE command. ๐Ÿ”
    • If Redis Cluster support has been enabled cluster is the only allowed value. ๐Ÿ‘‘

Description

Adds an extra Redis server. ๐ŸŽ‰

If Redis Cluster support has been enabled other servers in the cluster and their roles are automatically discovered by the VMOD using the CLUSTER SLOTS command. In any case, knowing more cluster servers during startup increases the chances of discover the cluster topology if some server is failing. ๐Ÿ’ช Bestie, the more you know, the better.


๐ŸŒŸ VOID xdb.command(STRING name)

Arguments

  • name โ€” name of the Redis command to be executed. ๐Ÿ’ซ

Description

Enqueues a Redis command (only the name of the command) for further execution. Arguments should be enqueued separately calling one or more times to the .push() method. ๐Ÿ“ฅ

On execution time, EVAL commands are internally replace by EVALSHA commands, which fallback to the original EVAL command if the Redis server returns a NOSCRIPT error (see http://redis.io/commands/eval). ๐Ÿ”„


โฐ VOID xdb.timeout(INT command_timeout)

Arguments

  • command_timeout โ€” command timeout (milliseconds; 0 means no timeout) to be used when executing a specific Redis command. โณ

Description

Allows overriding the default command timeout provided when calling .db(). ๐Ÿ”ง


๐Ÿ” VOID xdb.retries(INT max_command_retries)

Arguments

  • max_command_retries โ€” number of retries to be executed after a failed command execution. ๐Ÿ”„

Description

Allows overriding the default number of retries provided when calling .db(). ๐ŸŽ›๏ธ


๐Ÿ“ค VOID xdb.push(STRING arg)

Arguments

  • arg โ€” argument of a previously enqueued Redis command. ๐Ÿ“Ž

Description

Provides an argument to a previously enqueued Redis command. โž•


๐Ÿš€ VOID xdb.execute(BOOL master=1)

Arguments

  • master โ€” when enabled slave servers are not considered for execution. ๐Ÿ‘‘

Return value

VOID ๐Ÿ’€

Description

Executes a previously enqueued Redis command. ๐ŸŽฌ

When more than one Redis server is available, the destination server is selected according with master and with the list of weights + subnet masks provided when calling redis.subnets(). ๐Ÿ—บ๏ธ

WARNING: allowing execution of commands in slave servers (i.e. master == false) must be carefully used: โš ๏ธ
  • When Redis Cluster support is disabled, sending a read-write command to a read-only slave server will result in an error reply. โŒ
  • It's safe to send read-only LUA scripts using EVAL or EVALSHA commands to a read-only slave server when Redis Cluster support is disabled. Being a read-only slave server does not block writes in the script cache. โœ…
  • When Redis Cluster support is enabled, sending a read-write command to a slave server will result in a redirection to the right master server. This kind of redirections trigger an internal rediscovery of the cluster topology. The client side won't notice the redirection, but triggering such an expensive operation on every command is a terrible idea. ๐Ÿ’ธ
  • It's not safe to send read-only LUA scripts using EVAL or EVALSHA commands to a slave server when Redis Cluster support is enabled. Redis Cluster handles EVAL and EVALSHA1 command as write operations that must be redirected to a master server. Therefore, this would result on a rediscovery of the cluster topology on every command execution. The VMOD internally forces master == true when Redis Cluster support is enabled and EVAL or EVALSHA command are submitted in order to avoid this counterintuitive scenario. ๐Ÿšซ

โœจ VOID xdb.easy_execute(STRING command, [STRING cmd_arg1], [STRING cmd_arg2], [STRING cmd_arg3], [STRING cmd_arg4], [STRING cmd_arg5], [STRING cmd_arg6], [STRING cmd_arg7], [STRING cmd_arg8], [STRING cmd_arg9], [STRING cmd_arg10], [STRING cmd_arg11], [STRING cmd_arg12], [STRING cmd_arg13], [STRING cmd_arg14], [STRING cmd_arg15], [STRING cmd_arg16], [INT timeout], [INT retries], BOOL master)

VOID xdb.easy_execute(
      STRING command,
      [STRING cmd_arg1],
      [STRING cmd_arg2],
      [STRING cmd_arg3],
      [STRING cmd_arg4],
      [STRING cmd_arg5],
      [STRING cmd_arg6],
      [STRING cmd_arg7],
      [STRING cmd_arg8],
      [STRING cmd_arg9],
      [STRING cmd_arg10],
      [STRING cmd_arg11],
      [STRING cmd_arg12],
      [STRING cmd_arg13],
      [STRING cmd_arg14],
      [STRING cmd_arg15],
      [STRING cmd_arg16],
      [INT timeout],
      [INT retries],
      BOOL master=1
)

Arguments

The command argument is mandatory, followed with up to 16 arguments, optionally ending with timeout (as passed to .timeout()) and/or retries (as passed to .retries()) and/or master (.execute()). For example: db.easy_command("set", "foo", "hello", retries=3, master=true); ๐Ÿ“

Return value

VOID ๐Ÿ’€

Description

Equivalent to calling .command(), .push() (possibly multiple times), .timeout(), .retries() then finally .execute() using a single command. ๐ŸŽฏ It's literally a shortcut, bestie.


๐Ÿ“ฌ BOOL xdb.replied()

Return value

TRUE if a previously executed Redis command using .execute() returned any reply. Not returning a reply usually means a failed connection, a connection timeout, etc. ๐Ÿ“ญ


โŒ BOOL xdb.reply_is_error()

Return value

TRUE if a previously executed Redis command using .execute() returned an error reply. ๐Ÿšจ


๐Ÿ•ณ๏ธ BOOL xdb.reply_is_nil()

Return value

TRUE if a previously executed Redis command using .execute() returned a nil reply. ๐Ÿ’จ


โœ… BOOL xdb.reply_is_status()

Return value

TRUE if a previously executed Redis command using .execute() returned a status reply. ๐Ÿท๏ธ


๐Ÿ”ข BOOL xdb.reply_is_integer()

Return value

TRUE if a previously executed Redis command .execute() returned an integer reply. ๐Ÿงฎ


๐ŸŽฒ BOOL xdb.reply_is_boolean()

Return value

TRUE if a previously executed Redis command .execute() returned an boolean reply. ๐ŸŸข


๐ŸŽฏ BOOL xdb.reply_is_double()

Return value

TRUE if a previously executed Redis command .execute() returned an double reply. ๐ŸŽฏ


๐Ÿงต BOOL xdb.reply_is_string()

Return value

TRUE if a previously executed Redis command .execute() returned a string or verbatim reply. ๐Ÿ“œ


๐Ÿ“š BOOL xdb.reply_is_array()

Return value

TRUE if a previously executed Redis command using .execute() returned an array, map or set reply. ๐Ÿ—‚๏ธ


๐Ÿ“ STRING xdb.get_reply()

Return value

A string representation of the reply of a previously executed Redis command using .execute(). ๐Ÿ“„

Description

Do not use this function to access to array, map or set replies. ๐Ÿšซ


๐Ÿšซ STRING xdb.get_error_reply()

Return value

If a previously executed Redis command using .execute() returned an error reply, this function returns a string representation of that reply. ๐Ÿ“›


๐Ÿท๏ธ STRING xdb.get_status_reply()

Return value

If a previously executed Redis command using .execute() returned a status reply, this function returns a string representation of that reply. ๐Ÿ“‹


๐Ÿ”ข INT xdb.get_integer_reply()

Return value

If a previously executed Redis command using .execute() returned an integer reply, this function returns an integer representation of that reply. ๐Ÿงฎ


๐ŸŽฒ BOOL xdb.get_boolean_reply()

Return value

If a previously executed Redis command using .execute() returned an boolean reply, this function returns an boolean representation of that reply. ๐ŸŸข


๐ŸŽฏ REAL xdb.get_double_reply()

Return value

If a previously executed Redis command using .execute() returned an double reply, this function returns an double representation of that reply. ๐ŸŽฏ


๐Ÿงต STRING xdb.get_string_reply()

Return value

If a previously executed Redis command using .execute() returned a string or verbatim reply, this function returns a string representation of that reply. ๐Ÿ“œ


๐Ÿ“ INT xdb.get_array_reply_length()

Return value

If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns the number of elements in that reply. ๐Ÿ”ข


โŒ BOOL xdb.array_reply_is_error(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value

If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is an error reply (nested responses are not supported). ๐Ÿšจ


๐Ÿ•ณ๏ธ BOOL xdb.array_reply_is_nil(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value

If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is a nil reply (nested responses are not supported). ๐Ÿ’จ


๐Ÿท๏ธ BOOL xdb.array_reply_is_status(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value

If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is a status reply (nested responses are not supported). โœ…

BOOL xdb.array_reply_is_integer(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is an integer reply (nested responses are not supported). ๐Ÿ’–


BOOL xdb.array_reply_is_boolean(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is a boolean reply (nested responses are not supported). ๐Ÿ’–


BOOL xdb.array_reply_is_double(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is a double reply (nested responses are not supported). ๐Ÿ’–


BOOL xdb.array_reply_is_string(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is a string or verbatim reply (nested responses are not supported). ๐Ÿ’–


BOOL xdb.array_reply_is_array(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns TRUE if the nth element in that reply is an array, map or set reply (nested responses are not supported). ๐Ÿ’–


STRING xdb.get_array_reply_value(INT index)

Arguments

  • index โ€” index in the array reply. ๐Ÿ“

Return value If a previously executed Redis command using .execute() returned an array, map or set reply, this function returns a string representation of the nth element in that reply (nested responses are not supported). โœจ


VOID xdb.free()

Description Frees memory internally used by Redis commands and replies. It's recommended to use this function, but if not called this will be handled automatically during the next call to .command() using the same object. ๐Ÿงน


STRING xdb.stats(ENUM format, BOOL stream, STRING prometheus_name_prefix, BOOL prometheus_default_labels, STRING prometheus_extra_labels)

Full signature

STRING xdb.stats(
      ENUM {json, prometheus} format=json,
      BOOL stream=0,
      STRING prometheus_name_prefix="vmod_redis_",
      BOOL prometheus_default_labels=1,
      STRING prometheus_extra_labels=""
)

Arguments

  • format โ€” format of the output string. ๐Ÿ“Š
  • stream โ€” if enabled, the response object will be streamed as a synthetic response. ๐ŸŒŠ
  • prometheus_name_prefix โ€” prefix to be used in all Prometheus metric names. It's used as a raw value; no validations or transformations at all. ๐Ÿท๏ธ
  • prometheus_default_labels โ€” if enabled, some default Prometheus labels will be added to all stats. ๐Ÿท๏ธ
  • prometheus_extra_labels โ€” extra Prometheus labels to be added to all stats. It's used as a raw value; no validations or transformations at all. ๐Ÿท๏ธ

Description Returns internal stats represented as a string. ๐Ÿ“ˆ

If called during vcl_synth or vcl_backend_error with the stream argument enabled, this function will return an empty string and behave as a call to the synthetic VCL function with the response object as input. This highly reduces the amount of required workspace memory. ๐Ÿง 


INT xdb.counter(STRING name)

Arguments

  • name โ€” name of the counter. ๐Ÿงฎ

Description Returns internal counter. ๐Ÿ”ข


Copyright (c) Carlos Abalde <carlos.abalde@gmail.com>

You're free to use and distribute this under terms in the LICENSE file.


okay bestie that's literally the whole page ๐Ÿ’… the footer says vmod_redis(3) and the date is right there too โ€” go forth and slay some Redis commands! โœจ๐Ÿ’–๐Ÿฆ‹๐ŸŒธ๐ŸŽ€

๐Ÿ“ฆ where this page comes from