💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Cleaning up stale Redis sessions > 原文:[https://docs.gitlab.com/ee/administration/operations/cleaning_up_redis_sessions.html](https://docs.gitlab.com/ee/administration/operations/cleaning_up_redis_sessions.html) # Cleaning up stale Redis sessions[](#cleaning-up-stale-redis-sessions "Permalink") 从 6.2 版开始,GitLab 将 Web 用户会话存储为 Redis 中的键值对. 在 GitLab 7.3 之前,用户会话不会自动从 Redis 终止. 如果从 GitLab 7.3 之前开始就一直在运行大型的 GitLab 服务器(成千上万的用户),我们建议在升级到 GitLab 7.3 之后清理陈旧的会话以压缩 Redis 数据库. 您还可以在仍运行 GitLab 7.2 或更早版本的情况下执行清理,但是在这种情况下,清理后新的陈旧会话将再次开始建立. 在 7.3.0 之前的 GitLab 版本中,Redis 中的会话密钥是 16 字节的十六进制值,例如'976aa289e2189b17d7ef525a6702ace9'. 从 GitLab 7.3.0 开始,键的前缀为`session:gitlab:`因此它们看起来像`session:gitlab:976aa289e2189b17d7ef525a6702ace9` . 下面我们描述如何删除旧格式的密钥. **注意:**如果您使用了" [配置文件文档"中](https://gitlab.com/gitlab-org/gitlab/blob/master/config/README.md)概述的高级 Redis 设置,则必须根据您的配置设置修改以下说明. 首先,我们定义具有适当 Redis 连接详细信息的 shell 函数. ``` rcli() { # This example works for Omnibus installations of GitLab 7.3 or newer. For an # installation from source you will have to change the socket path and the # path to redis-cli. sudo /opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.shared_state.socket "$@" } # test the new shell function; the response should be PONG rcli ping ``` 现在,我们进行搜索以查看是否有旧格式的会话密钥供我们清理. ``` # returns the number of old-format session keys in Redis rcli keys '*' | grep '^[a-f0-9]\{32\}$' | wc -l ``` 如果数字大于零,则可以使 Redis 的密钥失效. 如果数字为零,则没有任何清理内容. ``` # Tell Redis to expire each matched key after 600 seconds. rcli keys '*' | grep '^[a-f0-9]\{32\}$' | awk '{ print "expire", $0, 600 }' | rcli # This will print '(integer) 1' for each key that gets expired. ``` 在接下来的 15 分钟内(10 分钟的到期时间加上 5 分钟的 Redis 后台保存间隔),您的 Redis 数据库将被压缩. 如果您仍在使用 GitLab 7.2,则在 10 分钟的有效期内未在 GitLab 中四处点击的用户将退出 GitLab.