对许多人来说,社交媒体体验已成为一种压力体验。新闻提要已成为赞助内容的公告板。状态、评论和任何在线互动都会让用户暴露在不安的键盘侠面前。有些人可能会说,社交媒体已经变得 *绝非* 社交了。
现在,随着社交媒体巨头们继续犹豫不决,这个 Launchpad 应用程序 通过创建自己的社交媒体平台 Letus,正面解决了这个问题。该应用程序的核心价值在于为用户提供一个社交媒体平台,促进朋友、家人和工作同事之间更自然、更有意义的互动。
从头到尾,此应用程序都依赖于 RedisGraph 的强大功能、速度和灵活性。让我们来看看这个应用程序是如何创建的。
但在我们深入研究之前,请务必浏览 Redis Launchpad,以发现一系列令人兴奋的应用程序,您可以参与其中。
您将构建一个社交媒体平台,保护用户免受喷子侵害,并解放他们免受赞助内容的困扰。此移动应用程序 *仅* 显示来自朋友、家人或您在 Letus 上联系的任何人的帖子。
将不会有任何神秘的算法让您暴露在不必要的连接和广告中。相反,Letus 将让您完全控制您将看到的内容。下面我们将逐步介绍将此应用程序变为现实所需采取的步骤,以及所需组件。
RedisGraph:用于稀疏矩阵来表示图中的邻接矩阵,并使用线性代数来查询图。
Google Cloud Platform (GCP):用作公共云供应商,用于对文本进行分类并分析本项目中的情感。
Azure Functions:用作无服务器解决方案,以编写更少的代码、维护基础设施并节省成本。
Google Identity:用作客户身份和访问管理 (CIAM) 平台,通过基于 Web 的 Oauth 2.0 对用户进行身份验证。
Expo: 用于移动开发人员构建应用程序
Firebase: 后端即服务
$ git clone https://github.com/redis-developer/letus
$ cd LetusApp
$ npm install --global expo-cli
可以使用 expo install 命令自动将具有配置插件的节点模块添加到项目的 Expo 配置中
$ npm install
$ expo install
对于本地开发,RedisGraph 可以使用 redismod Docker 容器运行
$ docker run -d -p 6379:6379 redislabs/redismod
您可以仅在本地运行 Expo Go 应用程序以使用和开发 React Native 应用程序。通过访问现有的(免费)Firebase 身份验证和为 DEV 部署的现有(免费)Azure 函数。
开发工具在 http://localhost:19002 上运行 在浏览器中打开开发工具…… 启动 Metro Bundler Metro 正在等待 exp://192.168.1.9:19000 |
Create a .env.local file to store your local configuration
Set the value of LETUS_API_URL to the location of your API (can use .env if local functions)
Set the value of GOOGLE_WEB_CLIENT_ID to use a Web OAUTH credential created in your Google Identity account.
Set value of firebase config in the .env or .env.local file
FIREBASE_API_KEY=
FIREBASE_AUTH_DOMAIN=
FIREBASE_PROJECT_ID=
FIREBASE_STORAGE_BUCKET=
FIREBASE_MEASSGE_SENDER_ID=
FIREBASE_APP_ID=
$ expo start
按 i 启动 iOS 模拟器或 a 启动 Android 模拟器。(注意:Android 模拟器需要 Android Studio 和 sdk 设置)
此项目使用 Azure 函数,可以直接在本地开发中访问。如果您希望将这些函数发布到云中,则必须创建自己的 Azure 帐户。提示:有一个非常有用的 VS Code 扩展,可帮助管理您的 Azure 项目和函数。
REDIS_HOST
REDIS_PORT
REDIS_PASS
REDIS_GRAPH
GCP_API_KEY
单击 /try-free/ 并设置 Redis Enterprise 云数据库,其中包含 RedisGraph,如下所示
MATCH (me:Person {userid: $userid})
OPTIONAL MATCH (me)-[:ignores]->(ign:IgnoreSetting)
WITH me, ign
MATCH (poster:Person)-[:posted]->(post:Post)
WHERE (poster = me OR (poster)-[:friended]-(me))
AND (NOT (post)-[:inCategory]->(:Category {name:ign.category}) AND NOT (post)<-[:posted]-(:Person {userid:ign.poster}))
WITH post, poster, me
OPTIONAL MATCH (post)-[:hasComment]->(comment:Comment)<-[:commented]-(commenter:Person)
WHERE commenter = me OR (commenter)-[:friended]-(me)
WITH me, post, poster, collect(comment) as comments, collect(commenter) as commenters
ORDER BY post.created DESC
SKIP $skip
LIMIT $limit
RETURN post, poster, comments, commenters
MATCH (me:Person {userid:$userid}) ${categories
.map(
(cat, index) =>
'MERGE (cat' + index + ':Category {name: $cat' + index + '})'
)
.join(
' '
)}
MERGE (sentiment:Sentiment {name: $sentiment})
CREATE (me)-[:posted]->(post:Post {text:$text,created:$now})
MERGE (post)-[:hasSentiment]->(sentiment) ${categories
.map((cat, index) => 'MERGE (post)-[:inCategory]->(cat' + index + ')')
.join(' ')}
RETURN post
MATCH (me:Person), (post:Post)
WHERE me.userid = $userid
AND ID(post) = $onPost
CREATE (me)-[:commented]->(comment:Comment {text:$text,created:$now})
CREATE (post)-[:hasComment]->(comment)
RETURN post
注意:单向 :friended 关系决定待处理的好友请求
MATCH (me:Person { userid: $userid })
MATCH (them:Person { userid: $themid })
MERGE (me)-[:friended]->(them)
RETURN me, them
MATCH (me:Person {userid: $userid})
WITH me
MATCH (them:Person)-[:friended]->(me)
WHERE NOT (me)-[:friended]->(them)
RETURN them
MATCH (me:Person { userid: $userid })
MERGE (me)-[:ignores]->(ignore:IgnoreSetting {poster:$themid, category: $category, sentiment: $sentiment})
RETURN me, ignore
MATCH (them:Person)
MATCH (me:Person {userid:$userid})
WHERE NOT them.userid = $userid
AND them.name STARTS WITH $name
AND NOT (me)-[:friended]->(them)
RETURN them
NLP 命令
使用 GCP Natural Language 的免费层级,我们对系统中发布的所有帖子应用情感分析和文本分类。
const sslCreds = getApiKeyCredentials();
const client = new language.LanguageServiceClient({ sslCreds });
const document = {
content: text,
type: 'PLAIN_TEXT',
};
const [result] = await client.analyzeSentiment({ document: document });
sentiment = mapSentiment(result.documentSentiment.score || 0);
// GCP requires 20 words
// we pad with prepositions if between 10-19 words for max coverage
if (len < 20) {
content = [...content.split(' '), ...preps.slice(0, 20 - len)].join(' ');
}
const sslCreds = getApiKeyCredentials();
const client = new language.LanguageServiceClient({ sslCreds });
const document = {
content,
type: 'PLAIN_TEXT',
};
const [result] = await client.classifyText({ document: document });
categories = result.categories || [];
随着社交媒体不断融入日常生活,喷子现象仍然像以往一样普遍。Facebook、Twitter、Instagram 甚至 Linkedin 都已成为不安的键盘侠的狩猎场。
然后您会收到无休止的赞助内容轰炸,这些内容的利益优先于用户的利益。但通过使用 Redis,此市场应用程序能够为移动用户创建一个社交媒体平台,消除了这两种危害。
RedisGraph 的强大功能和速度对于构建 Letus 至关重要,因为它允许应用程序以最高效率查询数据。从一个简单的想法开始,Redis 能够让这个应用程序变为现实……但这并非全部。
每天都有越来越多的人利用 Redis 的奇思妙想来创建令人兴奋的应用程序,这些应用程序正在对日常生活产生影响。您如何使用 Redis 来帮助改善社会?
要获得更多灵感,您可以访问 Redis Launchpad,在那里您会发现各种创新的应用程序。同样,您也可以通过 单击此处 来了解有关此应用程序是如何制作的更多信息。
Matt Pileggi
Matt 在 Web 开发领域拥有 20 多年的经验,现在是 Games24x7 的首席工程师。
请务必通过 查看他的页面,了解 Matt 在 Github 上的所有项目的最新情况。