https://github.com/boardgameio/redis-pubsub
Redis pub/sub adapter for boardgame.io multiplayer servers
https://github.com/boardgameio/redis-pubsub
boardgame-io redis
Last synced: 4 months ago
JSON representation
Redis pub/sub adapter for boardgame.io multiplayer servers
- Host: GitHub
- URL: https://github.com/boardgameio/redis-pubsub
- Owner: boardgameio
- License: mit
- Created: 2021-08-14T22:29:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-16T13:28:33.000Z (about 4 years ago)
- Last Synced: 2025-04-27T17:39:12.323Z (5 months ago)
- Topics: boardgame-io, redis
- Language: TypeScript
- Homepage:
- Size: 137 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @boardgame.io/redis-pubsub
This package provides a Redis pub/sub adapter for [boardgame.io](https://boardgame.io/) multiplayer servers.
## Installation
```sh
npm install @boardgame.io/redis-pubsub
```## Requirements
Requires `redis` npm library `3.1.2` or greater ([docs](https://github.com/NodeRedis/node-redis)), and `boardgame.io` version `0.47.0` or greater.
If you don’t have those installed yet, install them too:
```sh
npm install redis boardgame.io
```Using a database adapter that stores and shares the state across servers is also required to properly horizontally scale them. See [the boardgame.io storage docs](https://boardgame.io/documentation/#/storage) for details.
## Usage
```js
import redis from 'redis';
import { RedisPubSub } from '@boardgame.io/redis-pubsub'
import { Server, Origins, SocketIO } from 'boardgame.io/server';
import { PostgresStore } from 'bgio-postgres';
import MyGame from './src/MyGame';// 1. Create your Redis clients.
const pubClient = redis.createClient({ host: '192.168.8.50' });
const subClient = pubClient.duplicate();// 2. Create an instance of the RedisPubSub adapter.
const pubSub = new RedisPubSub(pubClient, subClient);const server = Server({
games: [MyGame],
origins: [Origins.LOCALHOST],
// 3. Pass the pub/sub instance to the SocketIO transport class.
transport: new SocketIO({ pubSub }),
db: new PostgresStore('vdf@192.168.8.50/vdf'),
});server.run(8000);
```## License
[MIT](LICENSE)