Skip to content

Instantly share code, notes, and snippets.

@Bluenix2
Last active November 18, 2022 14:58
Show Gist options
  • Save Bluenix2/cc23b63cf6bfd61b0da0161f1e359442 to your computer and use it in GitHub Desktop.
Save Bluenix2/cc23b63cf6bfd61b0da0161f1e359442 to your computer and use it in GitHub Desktop.
Discord Redis Cache Specification (DRC)

Discord Redis Cache Specification

This specification aims to provide interoperability between Discord cache implementations by defining the structure of the keys and type of value stored. The benefit of which is that multi-serviced bots can all take advantage of the same cache. Additionally, new implementations do not need to figure out how to structure the data as this is the defined in this specification.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Redis Key format

All Redis keys MUST use a colon (:) as a delimitor between the parts defined in this specification.

All Redis keys MUST BE prefixed with a custom prefix defined hereafter - this is done as to not cause collisions with other keys the user stores in the same Redis database. The custom prefix MUST be easily configured by the user and MUST NOT be an empty string. It MAY contain the delimitor character.

The prefix MAY be required by implementations but if there is a default it MUST be a unique and representative name of the implementation. The representative name MUST be easily recognizable by the user, as the implementation it is used by. In the examples of this specification drc will be used.

After the custom prefix - with a delimitor between - there MUST be the major version of this specification used, with a v in front of it. This allows slow rollouts of breaking changes without migrations. See more at Breaking changes.

Key TTL and Expiry

All redis keys used SHOULD have a TTL set to allow old keys to expire, since the information may no longer be up-to-date. This also ensures that the cache does not keep around data for guilds it no longer has access to and that keys for a previous major version are automatically discarded.

The expiries defined in this specification are RECOMMENDATIONS unless explicitly stated otherwise. Implementations SHOULD use these as defaults and MAY allow the user to change these.

Resources

This section defines the keys each Discord resource uses and the value stored. Implementations are not required to implement all of them but MUST strictly adhere to their definitions and MUST NOT provide a mechanism for users to configure them as that would cause incompatibilities.

Channels

  • drc:v1:channels:{channel.id}
  • 7 days (604 800 seconds)
  • String

This key MUST be set to the channel data serialized as JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment