Redis 的最大值大小 [英] Max value size for Redis

查看:68
本文介绍了Redis 的最大值大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试制作重播系统.所以基本上当玩家移动时,系统会将他的数据(移动、位置、动画等)保存到 JSON 文件中.在记录的末尾,JSON 文件可能超过 50 MB.我想将此数据保存到具有到期日期(24-48 小时)的 Redis 中.

I've been trying to make replay system. So basically when player moves, system saves his datas(movements, location, animation etc.) into JSON file. In the end of the record, JSON file may be over 50 MB. I'd want to save this data into Redis with expire date (24-48 hours).

我的问题是;

  1. 将超过 50 MB 的数据保存到具有到期日期的 Redis 中是否很糟糕?
  2. Redis 可以在不损失性能的情况下处理多少超过 50 MB 的数据?
  3. 如果玩家在 48 小时内创造了 500 条记录,这对 Redis 会不利吗?
  4. 使用平均 VDS/VPS 从 Redis 获取 50 MB 数据需要多少毫秒?

推荐答案

存储大对象(就大小而言)不是一个好习惯.您可以从此处阅读.问题之一是网络.您需要在一次调用中将 50MB 的有效负载发送到 redis 服务器.此外,如果您将它们保存为一个大对象,那么在检索、更新它(单个字段、元素等)时,您需要从服务器获取 50 MB 并解析它以获得单个字段,更新它后端发送回服务器.就网络而言,这是一个严重的问题.

Storing a large object(in terms of size) is not a good practice. You may read it from here. One of the problem is network. You need to send 50MB payload to a redis server in a single call. Also if you save them as one big object, then while retrieving, updating it (a single field, element etc), you need to get 50 MB back from server and parse it to get a single field, update it back end send back to server. That's a serious problem in terms of network.

根据您的用例,您可能更喜欢 sorted setslists 而不是 redis strings.如果您打算将它们与时间戳一起存储并获取这些时间戳之间的事件范围,那么 sorted sets 可能是您的理想解决方案.它适用于分页等.关键的缺点之一是添加新元素的复杂性是 O(log(N)).

Instead of redis strings, you may prefer sorted sets or lists depending on your use case. If you are going to store them with timestamps and get the range of events between these timestamps, then sorted sets may be an ideal solution for you. It's good for pagination etc. One of the crucial drawback is the complexity of adding a new element is O(log(N)).

lists 也可以为您的案例提供一个很好的平台.您可以使用 LPUSH/RPUSH 将新事件添加到您的列表中,并且由于 Redis 列表 是使用 链表,在列表的开头或结尾添加一条消息都是一样的,O(1),很棒.

lists may also provide a good playground for your case. You may use LPUSH/RPUSH to add new events to your list, and since Redis lists are implemented with linked lists, both adding a message to the beginning or end of the list is same, O(1), which is great.

每当事件发生时,您可以调用 ZADDRPUSH/LPUSH 将事件发送到 redis.如果您需要查询这些,您可以根据您的选择使用诸如 ZRANGEBYSCORELRANGE 等可用函数.

Whenever an event happens, you either call ZADD or RPUSH/LPUSH to send the events to redis. If you need to query those to you may use available functions such as ZRANGEBYSCORE or LRANGE depending on your choice.

在设计您的密钥时,您可以使用诸如用户 ID 之类的标识符,就像您在评论中提到的那样.您不会像 strings 那样遇到列表/排序集的问题.但是,选择哪一个最适合您取决于您​​的读/写用例或业务规则.

While designing your keys you may use an identifier such as user-id just like you mentioned in the comments. You will not have the problems with lists/sorted sets like you will have in strings. But choosing which one is most suitable for your depends on your use case for reads/writes or business rules.

这里有一些有用的链接可供阅读;

Here some useful links to read;

Redis 数据类型介绍

Redis 数据类型

Redis 实验室关于数据类型的文档

这篇关于Redis 的最大值大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆