<p>I have generated a list of keyspaces along with their size and ttl (715 keyspaces) and trying to analyze which keyspace is consuming huge memory.
I can see that total memory occupied by the keyspaces is 1.2 MB but my Redis PVC is filled up to 13 GB. So, what is occupying so much memory in Redis container ?</p>
<p>Redis Version: 6.0.9
Image: bitnami/redis:6.0.9-debian-10-r0</p>
<p>Script I used to generate the list:</p>
<pre><code>#!/bin/bash

NAMESPACE=$1
SECRET=$2
POD=$3
CONTAINER=$4

PASSWORD_REDIS=$(kubectl get secrets -n $NAMESPACE $SECRET -o jsonpath='{.data.secret'} | base64 -d )
kubectl exec -it -n $NAMESPACE $POD -c $CONTAINER -- redis-cli -a ${PASSWORD_REDIS} KEYS '*' | tail -n +2 &gt; keylist.csv
    keylist.csv

declare -a KEYS;
arraylen=0;
i=0;
j=0;

test2(){
    arraylen=${#KEYS[@]}
    echo &quot;kubectl exec -i -n ${NAMESPACE} ${POD} -c ${CONTAINER} -- redis-cli -h 127.0.0.1 -a ${PASSWORD_REDIS} MEMORY USAGE ${KEYS[j]}&quot; &gt; keys.sh
    chmod +x keys.sh
    ./keys.sh &gt; size.txt 2&gt; /dev/null

    echo &quot;kubectl exec -i -n ${NAMESPACE} ${POD} -c ${CONTAINER} -- redis-cli -h 127.0.0.1 -a ${PASSWORD_REDIS} TTL ${KEYS[j]}&quot; &gt; ttl.sh
    chmod +x ttl.sh
    ./ttl.sh &gt; ttl.txt 2&gt; /dev/null

    SIZE=$(cat size.txt)
    TTL=$(cat ttl.txt)
    ((j=$j+1))
    echo &quot;$j,${KEYS[j]},${SIZE},${TTL}&quot; &gt;&gt; output.csv
    if [ $j -ge $arraylen ]; then exit
    fi
    test2
}

while IFS=') '  read -r slno line; do
  LINE=${line};
  KEYS+=([i]=$LINE)
  i=$[$i+1]
done &lt; keylist.csv

test2
</code></pre>
<p>Output looks like this (3rd column is size in bytes and 4th column is TTL in ms):
<a href="https://i.stack.imgur.com/hvcpB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hvcpB.png" alt="enter image description here" /></a></p>

<p>Documentation of what is stored in GitLab's redis cache can be found <a href="https://docs.gitlab.com/ee/development/redis.html#redis-instances" rel="nofollow noreferrer">here</a> and <a href="https://gitlab.com/gitlab-com/runbooks/-/blob/master/docs/redis/redis-survival-guide-for-sres.md#what-do-we-store" rel="nofollow noreferrer">here</a>.</p>
<p>It changes over time and depends on the version of GitLab you are using.</p>
<p>It's also worth mentioning that GitLab has built a tool, <a href="https://gitlab.com/gitlab-com/gl-infra/redis-keyspace-analyzer/" rel="nofollow noreferrer">redis-keyspace-analyzer</a> for analyzing the keyspace of GitLab redis instances. You can use this to find the keys taking up the most space. (see also <a href="https://gitlab.com/gitlab-com/gl-infra/redis_bigkeys" rel="nofollow noreferrer">redis-bigkeys</a> and its <a href="https://gitlab.com/gitlab-com/runbooks/-/blob/master/docs/redis/redis-survival-guide-for-sres.md#bigkeys" rel="nofollow noreferrer">infra notes</a>). These tools are built by gitlab.com engineers for use with gitlab.com but should be adaptable to self-hosted gitlab instances.</p>
