Giter Site home page Giter Site logo

redis-pubsub's Introduction

@boardgame.io/redis-pubsub

This package provides a Redis pub/sub adapter for boardgame.io multiplayer servers.

Installation

npm install @boardgame.io/redis-pubsub

Requirements

Requires redis npm library 3.1.2 or greater (docs), and boardgame.io version 0.47.0 or greater.

If you don’t have those installed yet, install them too:

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 for details.

Usage

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('[email protected]/vdf'),
});

server.run(8000);

License

MIT

redis-pubsub's People

Contributors

delucis avatar vdfdev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

alexrogalskiy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.