在线学习从未如此容易获得。无论你想要了解更多关于加密货币的信息、提高你的编程技能,甚至只是学习一门新语言,数字时代都为每个人提供了大量内容的访问权限。
然而,随着时间的推移,电子学习被视为另一种数字商品,用户期望所有在线内容都能立即获得。速度仍然是性能的关键,任何页面加载时间的滞后或延迟都会损害用户体验。
因此,这些高期望要求任何称职的电子学习平台由能够以超高效率处理、处理和传输数据的数据库提供支持……这正是为什么这个 Launchpad 应用程序 使用了 Redis。
从头到尾,这个应用程序都是为了连接、教育和赋予学习者权力而构建的,通过将他们与最符合其兴趣的课程联系起来。
让我们来研究一下它是如何实现的。但在我们深入研究之前,你可能还想查看我们在 Launchpad 上的所有其他令人惊叹的应用程序。
你将构建一个强大的电子学习平台,将学生和教师以及各种在线课程库连接起来。由于速度是性能的关键,你将部署许多不同的 Redis 组件来实现这一目标。
下面我们将揭示使这个应用程序成为现实所需的组件以及每个项目的性能。
数据模型通过使用 RedisGraph 的节点和关系来表达。模型非常简单,因为它涉及学生、课程和主题实体,表达了它们彼此之间不同类型的关系。
X-Mentor 遵循事件驱动架构方法,其中考虑以下领域事件
https://github.com/redis-developer/x-mentor
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------
x-mentor_x-gears_1 python3 init.py --url redi ... Up
x-mentor_x-keycloak_1 /opt/jboss/tools/docker-en ... Up 0.0.0.0:8880->8080/tcp, 8443/tcp
x-mentor_x-mentor-client_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:3000->80/tcp
x-mentor_x-mentor-core_1 /opt/docker/conf/wait-for- ... Up 0.0.0.0:9000->9000/tcp
x-mentor_x-redis_1 redis-server --loadmodule ... Up 0.0.0.0:6379->6379/tcp
[node1] (local) root@192.168.0.8 ~/x-mentor
$
等待 Keycloak 和 x-mentor-core 准备就绪,然后转到 http://localhost:3000。
你可以通过 8880 端口访问 Keycloak,如下所示
使用 admin/admin 登录 keycloak。
此步骤启动了针对 Keycloak 的身份验证过程,通过
使用以下代码检查用户名是否已存在于用户布隆过滤器中
BF.EXISTS users '${student.username}'
注册涉及 4 个步骤
BF.ADD users '${student.username}'
GRAPH.QUERY xmentor "CREATE (:Student {username: '${student.username}', email: '${student.email}'})"
TS.CREATE studentprogress:${username} RETENTION 0 LABELS student ${username}
在此步骤中,我们将向你展示如何在电子学习平台上创建课程。每个课程都将作为 RedisJSON 中的 JSON 存储。
:
请按照以下命令操作
GET course-last-index
INCR course-last-index
JSON.SET course:${course.id} . '${course.asJson}'
BF.ADD courses '${course.id}'
GRAPH.QUERY xmentor "CREATE (:Course {name: '${course.title}', id: '${course.id.get}', preview: '${course.preview}'})"
XADD course-created $timestamp title ${course.title} topic ${course.topic}
在这里,我们将揭示如何将学生注册到特定课程。
以下是你需要遵循的步骤
BF.EXISTS users ${student.username}
JSON.GET course:${course.id}
GRAPH.QUERY xmentor "MATCH (s:Student), (c:Course) WHERE s.username = '${studying.student}' AND c.name = '${studying.course}' CREATE (s)-[:studying]->(c)"
作为任何在线资源的一部分,用户通常能够提供评论。要使此功能成为现实,你需要执行以下步骤
下图说明了 Redis Graph 和 Redis 流之间的交互。
要使此功能成为现实,请按照以下命令操作
GRAPH.QUERY xmentor "MATCH (student)-[:studying]->(course) where student.username = '$student' RETURN course"
GRAPH.QUERY xmentor "MATCH (student)-[:rates]->(course) where student.username ='$student' RETURN course"
GRAPH.QUERY xmentor "MATCH (s:Student), (c:Course) WHERE s.username = '${rating.student}' AND c.name = '${rating.course}' CREATE (s)-[:rates {rating:${rating.stars}}]->(c)"
XADD course-rated $timestamp student $student_username course $course
starts $stars
全部
以下命令使用 rediSearch 从 redisJSON 中通过查询检索课程
FT.SEARCH courses-idx ${query}*
按 ID
BF.EXISTS courses ${course.id}
JSON.GET course:${course.id}
GRAPH.QUERY xmentor “MATCH (student)-[:studying]->(course) where student.username = ‘$student’ RETURN course”
FT.SEARCH courses-idx ${course.title}
现在我们将向你展示如何允许学生根据他们的兴趣过滤他们喜欢的课程。以下是如何操作
下图显示了 Redis Graph 和 Redis 流之间的交互。
以下是你需要遵循的命令
GRAPH.QUERY xmentor "MATCH (student)-[:interested]->(topic) WHERE
student.username ='$student' RETURN topic"
GRAPH.QUERY xmentor "MATCH (s:Student), (t:Topic) WHERE s.username =
'${interest.student}' AND t.name = '${interest.topic}' CREATE
(s)-[:interested]->(t)"
GRAPH.QUERY xmentor "MATCH (student)-[interest:interested]->(topic) WHERE student.username='${interest.student}' and topic.name='${interest.topic}' DELETE interest"
XADD student-interest-lost $timestamp student ${student.username} topic $topic
XADD student-interest-lost $timestamp student ${student.username} topic $topic
在这里,我们将向你展示如何创建课程推荐系统,将用户与最符合其兴趣的课程联系起来。这在很大程度上取决于 RedisGraph 的高级功能。
在图数据库中搜索节点之间的关系是实现最有效的推荐策略的最简单方法。让我们看看如何操作。
为了创建能够将用户的个人兴趣与最相关的课程相匹配的特殊推荐系统
GRAPH.QUERY xmentor "MATCH (student)-[:studying]->(course) where student.username = '$student' RETURN course"
GRAPH.QUERY xmentor "MATCH (topic:Topic) RETURN topic"
GRAPH.QUERY xmentor "MATCH (topic:Topic)-[:has]->(course:Course)
GRAPH.QUERY xmentor "MATCH (student)-[:studying]->(course) WHERE course.name = '$course' RETURN student"
GRAPH.QUERY xmentor "MATCH (topic)-[:has]->(course) WHERE
topic.name = '${topic.name}' RETURN course"
GRAPH.QUERY xmentor "MATCH (student)-[:interested]->(topic) WHERE student.username ='$student' RETURN topic"
GRAPH.QUERY xmentor "MATCH (student)-[:studying]->(course),
(topic)-[:has]->(course) where student.username = '${student.username}'
and topic.name = '${topic.name}' RETURN course"
GRAPH.QUERY xmentor "MATCH (student)-[:studying]->(course), (topic)-[:has]->(course) WHERE student.username = '${student.username}' RETURN topic"
此功能允许您跟踪用户在平台上观看课程所花费的时间。该信息随后将用于实施排行榜。
一旦 x-mentor-core 收到请求,它将发布学生进度注册域事件。这将通过以下命令作为学生进度注册流(这是一个 Redis 流)中的元素结束
XADD student-progress-registered $timestamp student $student_username duration $duration
发送到 RedisGears 的所有数据都将被推送到流中,然后使用以下命令将此数据汇集到 Redis TimeSeries 中
TS.ADD studentprogress:$student_username $timestamp $duration RETENTION 0 LABELS student $student_username
排行榜功能允许您拥有一个显示使用 X-Mentor 的顶级学生的排名的排行榜。学生根据他们在平台上观看内容所花费的时间进行排名 - 您观看的时间越多,排名就越高。
为此,您需要分离两个功能
当用户请求排行榜数据时,首先查看 Redis 中的时间序列键
LRANGE student-progress-list 0 -1 // to retrieve all the list elements
对于每个键,您需要使用 Redis TimeSeries 获取三个月时间窗口内样本的范围,执行求和聚合。您可以使用以下代码来实现这一点
TS.RANGE $student_key $thee_months_back_timestamp $timestamp AGGREGATION sum 1000
以下是实现此功能所需的额外先决条件。
执行这些命令将为您提供每个学生的累计屏幕时间。收到这些排名后,您可以根据屏幕时间最长的学生创建排名系统。
在数字时代,任何应用程序的一个基本前提是它必须以最高速度运行。对于电子学习平台来说尤其如此,用户需要长时间参与其课程内容。
仅仅延迟就会在用户和应用程序之间产生摩擦,阻碍其连接教师与学生以及通过其课程提供价值的能力。将 Redis 作为应用程序的主要数据库消除了这种威胁,并有助于创建一个完全优化的应用程序,轻松满足用户的需求。
要更直观地了解此应用程序是如何创建的,您可以观看此YouTube 视频。我们还在Redis Launchpad 上为您提供各种应用程序,这些应用程序正在影响世界各地的日常生活。
所以一定要查看它们!
Sergio Cano
Sergio 是一位全栈工程师,用他自己的话说,“喜欢解决问题和学习新事物”。
作为一名热情的学习者,不难看出他从哪里获得了构建此应用程序的灵感。
请务必查看他的个人资料,看看他参与了哪些其他项目。