redispb

package
v0.3.3-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Redis State Storage Protobuffer Modules

These are modules used to read ('unmarshal'), write ('marshal'), and monitor Open Match protobuffer formats directly to/from Redis.

FAQs

  1. Why are there separate implementations for the Frontend objects (Players/Groups, participants in matchmaking) and Backend objects (MatchObjects, which hold profiles and match results)? We'd like to unify these at some point, but to make a more generic version of this library, we'd really like to depend on golang reflection, which is kind of messy right now for protobuffers. For now, we'll just focus on having separate implementations to carry us until the situation improves.

Documentation

Overview

Package redispb marshals and unmarshals Open Match Backend protobuf messages ('MatchObject') for redis state storage.

More details about the protobuf messages used in Open Match can be found in
the api/protobuf-spec/om_messages.proto file.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

All of this can probably be done more succinctly with some more interface and reflection, this is a hack but works for now.

Package redispb marshals and unmarshals Open Match Frontend protobuf messages ('Players' or groups) for redis state storage.

More details about the protobuf messages used in Open Match can be found in
the api/protobuf-spec/om_messages.proto file.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

All of this can probably be done more succinctly with some more interface and reflection, this is a hack but works for now.

Package redispb marshals and unmarshals Open Match Backend protobuf messages ('MatchObject') for redis state storage.

More details about the protobuf messages used in Open Match can be found in
the api/protobuf-spec/om_messages.proto file.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

All of this can probably be done more succinctly with some more interface and reflection, this is a hack but works for now.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalToRedis

func MarshalToRedis(ctx context.Context, pool *redis.Pool, pb proto.Message, ttl int) error

MarshalToRedis marshals a protobuf message to a redis hash. The protobuf message in question must have an 'id' field. If a positive integer TTL is provided, it will also be set.

func PlayerWatcher

func PlayerWatcher(ctx context.Context, pool *redis.Pool, pb om_messages.Player) <-chan om_messages.Player

PlayerWatcher makes a channel and returns it immediately. It also launches an asynchronous goroutine that watches a redis key and returns updates to that key on the channel.

The pattern for this function is from 'Go Concurrency Patterns', it is a function that wraps a closure goroutine, and returns a channel. reference: https://talks.golang.org/2012/concurrency.slide#25

NOTE: this function will never stop querying Redis during normal operation! You need to

disconnect the client from the frontend API (which closes the context) once
you've received the results you were waiting for to stop doing work!

func UnmarshalFromRedis

func UnmarshalFromRedis(ctx context.Context, pool *redis.Pool, pb *om_messages.MatchObject) error

UnmarshalFromRedis unmarshals a MatchObject from a redis hash. This can probably be made generic to work with other pb messages in the future. In every case where we don't get an update, we return an error.

func UnmarshalPlayerFromRedis

func UnmarshalPlayerFromRedis(ctx context.Context, pool *redis.Pool, player *om_messages.Player) error

UnmarshalPlayerFromRedis unmarshals a Player from a redis hash. This can probably be deprecated if we work on getting the above generic enough. The problem is that protobuf message reflection is pretty messy.

func Watcher

func Watcher(ctx context.Context, pool *redis.Pool, pb om_messages.MatchObject) <-chan om_messages.MatchObject

Watcher makes a channel and returns it immediately. It also launches an asynchronous goroutine that watches a redis key and returns updates to that key on the channel.

The pattern for this function is from 'Go Concurrency Patterns', it is a function that wraps a closure goroutine, and returns a channel. reference: https://talks.golang.org/2012/concurrency.slide#25

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL