nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
nanommo::Redis Class Reference

#include <redis.h>

Classes

struct  Entry

Public Member Functions

 ~Redis ()
 Redis (const Redis &)=delete
Redis & operator= (const Redis &)=delete
absl::StatusOr< std::string > Command (const std::vector< std::string > &words)
absl::StatusOr< std::vector< std::vector< std::string > > > Pipeline (const std::vector< std::vector< std::string > > &commands)
absl::Status Transaction (const std::vector< std::vector< std::string > > &commands)
absl::StatusOr< std::vector< std::string > > TransactionIf (const std::map< std::string, std::string > &holding, const std::vector< std::vector< std::string > > &commands)
absl::StatusOr< std::vector< Entry > > Read (const std::vector< std::string > &words)

Static Public Member Functions

static absl::StatusOr< std::unique_ptr< Redis > > Create (const std::string &host, int port=6379, RedisTimeouts timeouts={})
 Connects to Redis, or returns why it couldn't.

Detailed Description

Definition at line 28 of file redis.h.

Constructor & Destructor Documentation

◆ ~Redis()

nanommo::Redis::~Redis ( )

Definition at line 144 of file redis.cc.

◆ Redis()

nanommo::Redis::Redis ( const Redis & )
delete

Member Function Documentation

◆ Command()

absl::StatusOr< std::string > nanommo::Redis::Command ( const std::vector< std::string > & words)

Returns the reply as text, or a NotFound error when Redis says nil. A command that loses the connection fails, and the next one reconnects. One that Redis doesn't answer in time fails as Unavailable, and so does each after it, at once, until the timeouts' fail_fast is over; its connection goes, as the reply might come later, as another's.

Definition at line 186 of file redis.cc.

◆ Create()

absl::StatusOr< std::unique_ptr< Redis > > nanommo::Redis::Create ( const std::string & host,
int port = 6379,
RedisTimeouts timeouts = {} )
static

Connects to Redis, or returns why it couldn't.

Definition at line 121 of file redis.cc.

◆ operator=()

Redis & nanommo::Redis::operator= ( const Redis & )
delete

◆ Pipeline()

absl::StatusOr< std::vector< std::vector< std::string > > > nanommo::Redis::Pipeline ( const std::vector< std::vector< std::string > > & commands)

Sends all the commands before reading any reply, so they share a single round trip. Each reply comes back as a list of values, empty for nil.

Definition at line 275 of file redis.cc.

◆ Read()

absl::StatusOr< std::vector< Redis::Entry > > nanommo::Redis::Read ( const std::vector< std::string > & words)

Reads a stream, with XREAD or XREADGROUP on a single stream: its entries, or none when the command waited and nothing came. One that BLOCKs waits that long for Redis, and the timeout on top, and one that BLOCKs for 0 as long as Redis does: for ever, until an entry comes.

Definition at line 217 of file redis.cc.

◆ Transaction()

absl::Status nanommo::Redis::Transaction ( const std::vector< std::vector< std::string > > & commands)

Runs the commands as one transaction, between MULTI and EXEC, in a single round trip: Redis runs them all at once, with no one else's commands in between, or none of them if it couldn't take one. Fails if any of them failed.

Definition at line 313 of file redis.cc.

◆ TransactionIf()

absl::StatusOr< std::vector< std::string > > nanommo::Redis::TransactionIf ( const std::map< std::string, std::string > & holding,
const std::vector< std::vector< std::string > > & commands )

Runs the commands as one, as Transaction does, but only if each of the keys holds the value it's paired with: a Lua script checks them and runs the commands, in a single round trip, with no one else's commands in between. Returns the keys that don't, when it ran none of the commands. Fails if a command failed, which doesn't undo the others.

Definition at line 361 of file redis.cc.


The documentation for this class was generated from the following files: