百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

retwis

> 编程语言
开源

一个用 PHP 和 Redis 编写的 Twitter 玩具克隆,在早期用于介绍 Redis 数据类型。

368 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个用 PHP 和 Redis 编写的 Twitter 玩具克隆,在早期用于介绍 Redis 数据类型。

Retwis is the Redis Hello World. A minimal Twitter-style social network clone written using Redis and PHP. The source code is designed to be very simple and at the same time to show different Redis data structures.

You can find a tutorial explaining step by step how the example was created in the Twitter clone tutorial of the Redis documentation.

This code was written back in 2009 when Redis was initially published, in order to expose interested developers to the Redis concepts and data types. Later, in May 2014, it was reworked in order to update it to modern Redis, since when the example was introduced Redis lacked sorted sets, hashes, and many other features.

The following is a description of the data layout.

Users

User IDs are generated sequencially via increments:

INCR next_user_id => 1000

(We'll use the example user ID 1000 in the next examples)

Users are stored into Redis hashes, the key name of the hash representing a given user is user:1000. Every hash has the following fields:

username (the username of the user)
password (password of course)
auth 9458sd893448dfd

There are additional keys for following, followers, and posts:

following:1000 (sorted set of user ids)
followers:1000 (sorted set of user ids)
posts:1000 (list of posts ids)

In order to reverse lookup the user ID from the authentication toke or username we have the following two additional keys:

The key `auths` is an hash mapping auth tokens to user IDs.
Example of field and value: 9458sd893448dfd => 1000

The key `users` is an hash mapping usernames to user IDs.
Example of field and value: antirez => 1000

Additionally we take a sorted set with usernames indexed by registration time (the score is the unix time the user joined), so that we can populate our "latest users" view. The key is called users_by_time.

Posts

Posts also have sequencial IDs, generated by incrementing the following key:

INCR next_post_id => 134

Every post is stored into an hash named post:134 with the following fields:

user_id
time
body

Timeline

Just a list of post IDs in the timeline key.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言