You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-20Lines changed: 65 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,49 @@
1
1
# Redis Light, Green Light
2
2
3
-
This project is an online multiplayer implementation of the game "Red Light, Green Light" using Python, Javascript and Redis. This is my submission for the 2022 [Redis Hackathon on DEV](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248)
3
+
This project is an online, multiplayer implementation of "Red Light, Green Light" from Squid Game built with Python, Javascript and Redis. This is my submission for the 2022 [Redis Hackathon on DEV](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248)!
4
4
5
5
### Gameplay
6
6
7
7

Here's a short video that explains the project and how it uses Redis:
16
45
17
-
[](https://www.youtube.com/watch?v=vyxdC1qK4NE)
46
+
[[ Coming soon ]]
18
47
19
48
## How it works
20
49
@@ -61,17 +90,17 @@ There are **eight** types of events that can happen in the lifecycle of a game:
61
90
62
91
```py
63
92
classEventType:
64
-
CREATED="created"
65
-
LIGHT="light"
66
-
JOIN="join"
67
-
MOVE="move"
68
-
WIN="win"
69
-
DIE="die"
70
-
LEAVE="leave"
71
-
END="end"
93
+
CREATED="created"# new game room is created
94
+
LIGHT="light"# the light color is updated
95
+
JOIN="join"# player joins a room
96
+
MOVE="move"# player moves successfully when the light is green
97
+
WIN="win"# player wins by moving 100 steps
98
+
DIE="die"# player tries to move when the light is read
99
+
LEAVE="leave"# player leaves or is disconnected from the game
100
+
END="end"# game ends because there are no more players in the room
72
101
```
73
102
74
-
I use streams as append-only logs to persist very action that happens during the course of a game. Here are some examples of how I store game event data in streams:
103
+
I use streams as append-only logs to persist very action that happens during the course of a game. Each event in the stream has an `event` property that stores one of the `EventType`s listed above. Here are some examples of how I store game event data in streams:
75
104
76
105
**Record a room creation event**
77
106
@@ -115,9 +144,13 @@ To display all events for a given room, the `XRANGE` command is used to fetch al
In addition to storing temporary game state and append-only event logs, Redis also supports the application as a message broker for the celery worker and scheduler, and it supports the SocketIO as a message queue which is required when there are multiple servers process (Flask, celery, celerybeat). Main application data is stored on DB index `0`, and these other services use other DB indexes for isolation and separation of concerns to the extent that it makes sense.
150
+
118
151
## How to run it locally?
119
152
120
-
Running the application in a local development environment involves starting the web client and also starting multiple backend services. Backend services can be brought up using a `docker-compose.yml` file or they can be started by running commands in Python virtual environment.
153
+
Running the application in a local development environment involves starting the web client and also starting multiple backend services. Backend services can be brought up using a `docker-compose.yml` file or they can be started by running commands in a Python virtual environment.
121
154
122
155
### Prerequisites
123
156
@@ -129,11 +162,25 @@ To run the backend locally with docker and docker-compose you will need:
129
162
130
163
- docker 20.10.14+
131
164
- docker-compose 1.29.2
132
-
- Python 3.9 (if not using docker)
165
+
- Python 3.9+ (if not using docker)
133
166
134
-
Recommended:
167
+
Run the following command to check your local versions:
135
168
136
-
- Redis Insights
169
+
```
170
+
make check
171
+
```
172
+
173
+
It should show something like:
174
+
175
+
```
176
+
Docker version 20.10.14, build a224086
177
+
178
+
docker-compose version 1.29.2, build 5becea4c
179
+
180
+
Python 3.10.2
181
+
182
+
Node v16.16.0
183
+
```
137
184
138
185
### Local installation
139
186
@@ -179,6 +226,8 @@ Next you can start the three services in different windows. Before starting each
179
226
source .env/bin/activate
180
227
```
181
228
229
+
For advanced usage, please see the [`Makefile`](/Makefile) which has some helpful targets for starting different parts of the application (redis-stack, backend services and client).
230
+
182
231
**Start the Flask API server**
183
232
184
233
```
@@ -252,7 +301,3 @@ Configuration ->
252
301
Before starting `celerybeat`, make sure that you have deleted a file called `celerybeat-schedule.db`.
253
302
254
303
The client runs on `http://localhost:3000`. It makes API and websocket connections with the backend which runs on `http://localhost:8000`.
255
-
256
-
## Deployment
257
-
258
-
To make deploys work, you need to create free account on [Redis Cloud](https://redis.info/try-free-dev-to)
0 commit comments