redishelpers

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

State storage

Open Match tries not to tie itself too closely to Redis, thus why the Redis code is largely sequestered off in this module. However, it is expected that most MMFs will read and write directly from/to state storage without using Open Match as an intermediary, so enabling a different database as the internal state storage would likely require separate MMFs designed to work with that database. We'll likely leave this to community members or software integrators, but we tried to avoid excluding the possibility for those who are sufficiently motivated.

Redis

The default state storage for Open Match is a single instance of Redis. Redis was chosen for the default for its proven performance and its alignment with a Matchmaker's resiliency expectations. For many legacy matchmakers, a singleton approach means that the expected behavior upon loss of the matchmaker is that all state is gone and all clients should re-queue and all servers should be queried again for readiness. Using Redis for Open Match adheres to the same assumptions under failure, but allows users to configure additional HA replicas for more resiliency and additional read replicas for horizontal scalability of performance. Our evaluation is that Redis should be able to handle almost all game matchmaking scenarios with proper configuration.

Persistence

It is possible to persist the Redis instance to disk, but this is probably not a great solution for most matchmakers. The performance hit for writing all the updates to disk with multiple tens or even hundreds of thousands of clients will likely make it untenable. If you think you need persistence because you are worried about the Redis instance failing, you're probably better off with a HA Redis deployment as mentioned above.

Resilience

Although it is possible to go to production with this as the solution if you're willing to accept the potential downsides, for most deployments, a HA Redis configuration would better fit your needs. An example YAML file for creating a self-healing HA Redis deployment on Kubernetes is available. Regardless of which configuation you use, it is probably a good idea to put some resource requests in your Kubernetes resource definition as mentioned above.

Single Redis instance considersations

It is possible, as noted above, to run on a single Redis node if you know and can accept the consequences. In general, if you're running something close to 'stock' Open Match with a single node Redis configuration, and the Redis instance is lost:

  • All players currently queued would need to re-queue. They should get an error from the Frontend API if they are currently waiting for updates, but in case there is an edge case that's not covered, your client should be set up to retry after a reasonable amount of time without a response.
  • The Backend API clients would need to reconnect and request new matches. The safest way would be to abandon all in-flight queries.

Documentation

Overview

Package redishelpers is a package for wrapping redis functionality.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectionPool

func ConnectionPool(cfg config.View) (*redis.Pool, error)

ConnectionPool reads the configuration and attempts to instantiate a redis connection pool based on the configured hostname and port.

func Count

func Count(ctx context.Context, pool *redis.Pool, key string) (int, error)

Count is a concurrent-safe, context-aware redis SCARD on the input key

func Create

func Create(ctx context.Context, pool *redis.Pool, key string, values map[string]string) (string, error)

Create is a concurrent-safe, context-aware redis SET of the input key to the input value

func Decrement

func Decrement(ctx context.Context, pool *redis.Pool, key string) (interface{}, error)

Decrement decrements a redis value at key.

func Delete

func Delete(ctx context.Context, pool *redis.Pool, key string) error

Delete is a concurrent-safe, context-aware redis DEL on the input key

func DeleteMultiFields

func DeleteMultiFields(ctx context.Context, pool *redis.Pool, keys []string, field string) error

DeleteMultiFields is a concurrent-safe, context-aware Redis DEL of the input field from the input keys

func Increment

func Increment(ctx context.Context, pool *redis.Pool, key string) (interface{}, error)

Increment increments a redis value at key.

func JSONStringToMap

func JSONStringToMap(result string) map[string]interface{}

JSONStringToMap converts a JSON blob (which is how we store many things in redis) to a golang map so the individual properties can be accessed. Useful helper function when debugging.

func Retrieve

func Retrieve(ctx context.Context, pool *redis.Pool, key string) (string, error)

Retrieve is a concurrent-safe, context-aware redis GET on the input key

func RetrieveAll

func RetrieveAll(ctx context.Context, pool *redis.Pool, key string) (map[string]string, error)

RetrieveAll is a concurrent-safe, context-aware redis HGETALL on the input key

func RetrieveField

func RetrieveField(ctx context.Context, pool *redis.Pool, key string, field string) (string, error)

RetrieveField is a concurrent-safe, context-aware redis HGET on the input field of the input key

func Update

func Update(ctx context.Context, pool *redis.Pool, key string, value string) (string, error)

Update is a concurrent-safe, context-aware redis SADD of the input value to the input key's set. (Yes, it is an imperfect mapping, likely rework this at some point)

func UpdateMultiFields

func UpdateMultiFields(ctx context.Context, pool *redis.Pool, kv map[string]string, field string) error

UpdateMultiFields is a concurrent-safe, context-aware Redis HSET of the input field Keys to update and the values to set the field to are passed in the 'kv' map. Example usage is to set multiple player's "assignment" field to various game server connection strings. "field" := "assignment" "kv" := map[string]string{ "player1": "servername:10000", "player2": "otherservername:10002" }

func Watcher

func Watcher(ctx context.Context, pool *redis.Pool, key string) <-chan string

Watcher makes a channel and returns it immediately. It also launches an asynchronous goroutine that watches a redis key and returns the value of that key once it exists 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.

Directories

Path Synopsis
Package ignorelist is an ignore list specific redis implementation and will be removed in a future version.
Package ignorelist is an ignore list specific redis implementation and will be removed in a future version.
Package playerindices indexes player attributes in Redis for faster filtering of player pools.
Package playerindices indexes player attributes in Redis for faster filtering of player pools.
Package redispb marshals and unmarshals Open Match Backend protobuf messages ('MatchObject') for redis state storage.
Package redispb marshals and unmarshals Open Match Backend protobuf messages ('MatchObject') for redis state storage.

Jump to

Keyboard shortcuts

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