亚马逊DynamoDB - 基于友谊设计表 [英] Amazon DynamoDB - Designing tables based on friendships

查看:234
本文介绍了亚马逊DynamoDB - 基于友谊设计表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的测试项目中,我试图模拟一个小型的社交网络,它允许用户发布个人状态信息。

In my test project, I'm trying to simulate a small social network that allows the users to post a personal status message.

我会使用DynamoDB的状态消息和MySQL用户的友谊。 我的疑问是:我怎么能设计我的发电机表来存储状态信息,并获取用户朋友的只有状态

I would to use DynamoDB for status message and MySQL for the user friendships. My doubt is: how can I design my dynamo table to store status message and fetch only the status of friends users?

例如,我要取我的朋友下令由迪纳摩创立至今的所有状态。我已经与这个指标想到了一个表:

For example, I need to fetch all the statuses of my friends ordered by creation date from Dynamo. I've thought of a table with this indexes:

  • HashKey:USER_ID
  • RangeKey:CREATION_DATE
  • ATTRIBUTE1:信息
  • Attribute2:....

不过,我可以过滤我的朋友只有状态这个表上?

But, can I filter only the statuses of my friends on this table?

推荐答案

现在的问题是,一个用户可以有好友列表。给定一个用户,我们希望得到所有他/她的朋友(姓名+在线/离线状态)。我们如何做到这一点DynamoDB?

The question is, a user can have a list of friends. Given a user, we want to get all his/her friends (name + online/offline status). How do we do this in DynamoDB?

首先为每个用户需要分配为user_id。这将是唯一的标识符为该用户,换言之,一个指针。

First for each user you need to assign a user_id. That will be the unique identifier for that user, in other words, a pointer.

您可以使用哈希范围表来存储友谊数据。既此表的混杂键和范围密钥将被user_id说明。在DynamoDB每个哈希键可以有多个范围键。散列键将是一个用户,我们可以将所有她的朋友的用户ID范围内的关键。

You can use a Hash-Range table to store the friendship data. Both the hash key and range key of this table will be user_id. In DynamoDB each hash key can have multiple range keys. The hash key will be one user and we can store all her friends's user id in the range key.

假设USER_1是朋友与user_2和user_3

assuming user_1 is friend with user_2 and user_3

"Friendship table in DynamoDB"
HashKey   RangeKey
user_1    user_2
user_1    user_3
user_2    user_1
user_3    user_1

您可以有另一个表,用于存储用户信息

You can have another table that stores User information

"User table in DynamoDB"
HashKey   name    isLoggedin
user_1    J       true
user_2    swaggyp false
user_3    furion  false

现在你想获得USER_1的朋友。你可以做一个DynamoDB查询与hash_key等于USER_1。在上面的例子中,你将得到2行:

Now you want to get user_1's friend. You can do a DynamoDB query with hash_key equals to user_1. In the above example, you will get 2 rows:

(USER_1,user_2)(uiser_1,user_3)。

(user_1, user_2) (uiser_1, user_3).

现在你知道user_2和user_3是USER_1的朋友。您可以使用用户表得到user_2和user_3的在线状态。

Now you know that user_2 and user_3 are user_1's friends. You can use User the table to get user_2 and user_3's online status.

这篇关于亚马逊DynamoDB - 基于友谊设计表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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