Table of Contents

Class ConnectionMultiplexer

Namespace
StackExchange.Redis
Assembly
StackExchange.Redis.StrongName.dll

Represents an inter-related group of connections to redis servers

public sealed class ConnectionMultiplexer : IConnectionMultiplexer, IDisposable
Inheritance
ConnectionMultiplexer
Implements
Inherited Members

Properties

ClientName

Gets the client-name that will be used on all new connections

public string ClientName { get; }

Property Value

string

Configuration

Gets the configuration of the connection

public string Configuration { get; }

Property Value

string

Factory

Provides a way of overriding the default Task Factory. If not set, it will use the default Task.Factory. Useful when top level code sets it's own factory which may interfere with Redis queries.

public static TaskFactory Factory { get; set; }

Property Value

TaskFactory

IncludeDetailInExceptions

Should exceptions include identifiable details? (key names, additional .Data annotations)

public bool IncludeDetailInExceptions { get; set; }

Property Value

bool

IncludePerformanceCountersInExceptions

Should exceptions include performance counter details? (CPU usage, etc - note that this can be problematic on some platforms)

public bool IncludePerformanceCountersInExceptions { get; set; }

Property Value

bool

IsConnected

Indicates whether any servers are connected

public bool IsConnected { get; }

Property Value

bool

OperationCount

The number of operations that have been performed on all connections

public long OperationCount { get; }

Property Value

long

PreserveAsyncOrder

Gets or sets whether asynchronous operations should be invoked in a way that guarantees their original delivery order

public bool PreserveAsyncOrder { get; set; }

Property Value

bool

StormLogThreshold

Limit at which to start recording unusual busy patterns (only one log will be retained at a time; set to a negative value to disable this feature)

public int StormLogThreshold { get; set; }

Property Value

int

TimeoutMilliseconds

Gets the timeout associated with the connections

public int TimeoutMilliseconds { get; }

Property Value

int

Methods

BeginProfiling(object)

Begins profiling for the given context.

If the same context object is returned by the registered IProfiler, the IProfiledCommands will be associated with each other.

Call FinishProfiling with the same context to get the assocated commands.

Note that forContext cannot be a WeakReference or a WeakReference<T>

public void BeginProfiling(object forContext)

Parameters

forContext object

Close(bool)

Close all connections and release all resources associated with this object

public void Close(bool allowCommandsToComplete = true)

Parameters

allowCommandsToComplete bool

CloseAsync(bool)

Close all connections and release all resources associated with this object

public Task CloseAsync(bool allowCommandsToComplete = true)

Parameters

allowCommandsToComplete bool

Returns

Task

Configure(TextWriter)

Reconfigure the current connections based on the existing configuration

public bool Configure(TextWriter log = null)

Parameters

log TextWriter

Returns

bool

ConfigureAsync(TextWriter)

Reconfigure the current connections based on the existing configuration

public Task<bool> ConfigureAsync(TextWriter log = null)

Parameters

log TextWriter

Returns

Task<bool>

Connect(ConfigurationOptions, TextWriter)

Create a new ConnectionMultiplexer instance

public static ConnectionMultiplexer Connect(ConfigurationOptions configuration, TextWriter log = null)

Parameters

configuration ConfigurationOptions
log TextWriter

Returns

ConnectionMultiplexer

Connect(string, TextWriter)

Create a new ConnectionMultiplexer instance

public static ConnectionMultiplexer Connect(string configuration, TextWriter log = null)

Parameters

configuration string
log TextWriter

Returns

ConnectionMultiplexer

ConnectAsync(ConfigurationOptions, TextWriter)

Create a new ConnectionMultiplexer instance

public static Task<ConnectionMultiplexer> ConnectAsync(ConfigurationOptions configuration, TextWriter log = null)

Parameters

configuration ConfigurationOptions
log TextWriter

Returns

Task<ConnectionMultiplexer>

ConnectAsync(string, TextWriter)

Create a new ConnectionMultiplexer instance

public static Task<ConnectionMultiplexer> ConnectAsync(string configuration, TextWriter log = null)

Parameters

configuration string
log TextWriter

Returns

Task<ConnectionMultiplexer>

Dispose()

Release all resources associated with this object

public void Dispose()

ExportConfiguration(Stream, ExportOptions)

Write the configuration of all servers to an output stream

public void ExportConfiguration(Stream destination, ExportOptions options = (ExportOptions)-1)

Parameters

destination Stream
options ExportOptions

FinishProfiling(object, bool)

Stops profiling for the given context, returns all IProfiledCommands associated.

By default this may do a sweep for dead profiling contexts, you can disable this by passing "allowCleanupSweep: false".

public ProfiledCommandEnumerable FinishProfiling(object forContext, bool allowCleanupSweep = true)

Parameters

forContext object
allowCleanupSweep bool

Returns

ProfiledCommandEnumerable

GetCounters()

Get summary statistics associates with this server

public ServerCounters GetCounters()

Returns

ServerCounters

GetDatabase(int, object)

Obtain an interactive connection to a database inside redis

public IDatabase GetDatabase(int db = -1, object asyncState = null)

Parameters

db int
asyncState object

Returns

IDatabase

GetEndPoints(bool)

Gets all endpoints defined on the server

public EndPoint[] GetEndPoints(bool configuredOnly = false)

Parameters

configuredOnly bool

Returns

EndPoint[]

GetServer(EndPoint, object)

Obtain a configuration API for an individual server

public IServer GetServer(EndPoint endpoint, object asyncState = null)

Parameters

endpoint EndPoint
asyncState object

Returns

IServer

GetServer(IPAddress, int)

Obtain a configuration API for an individual server

public IServer GetServer(IPAddress host, int port)

Parameters

host IPAddress
port int

Returns

IServer

GetServer(string, int, object)

Obtain a configuration API for an individual server

public IServer GetServer(string host, int port, object asyncState = null)

Parameters

host string
port int
asyncState object

Returns

IServer

GetServer(string, object)

Obtain a configuration API for an individual server

public IServer GetServer(string hostAndPort, object asyncState = null)

Parameters

hostAndPort string
asyncState object

Returns

IServer

GetStatus()

Provides a text overview of the status of all connections

public string GetStatus()

Returns

string

GetStatus(TextWriter)

Provides a text overview of the status of all connections

public void GetStatus(TextWriter log)

Parameters

log TextWriter

GetStormLog()

Obtains the log of unusual busy patterns

public string GetStormLog()

Returns

string

GetSubscriber(object)

Obtain a pub/sub subscriber connection to the specified server

public ISubscriber GetSubscriber(object asyncState = null)

Parameters

asyncState object

Returns

ISubscriber

HashSlot(RedisKey)

Compute the hash-slot of a specified key

public int HashSlot(RedisKey key)

Parameters

key RedisKey

Returns

int

PublishReconfigure(CommandFlags)

Request all compatible clients to reconfigure or reconnect

public long PublishReconfigure(CommandFlags flags = CommandFlags.None)

Parameters

flags CommandFlags

Returns

long

The number of instances known to have received the message (however, the actual number can be higher; returns -1 if the operation is pending)

PublishReconfigureAsync(CommandFlags)

Request all compatible clients to reconfigure or reconnect

public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None)

Parameters

flags CommandFlags

Returns

Task<long>

The number of instances known to have received the message (however, the actual number can be higher)

RegisterProfiler(IProfiler)

Sets an IProfiler instance for this ConnectionMultiplexer.

An IProfiler instances is used to determine which context to associate an IProfiledCommand with. See BeginProfiling(object) and FinishProfiling(object) for more details.

public void RegisterProfiler(IProfiler profiler)

Parameters

profiler IProfiler

ResetStormLog()

Resets the log of unusual busy patterns

public void ResetStormLog()

ToString()

See Object.ToString()

public override string ToString()

Returns

string

Wait(Task)

Wait for a given asynchronous operation to complete (or timeout)

public void Wait(Task task)

Parameters

task Task

WaitAll(params Task[])

Wait for the given asynchronous operations to complete (or timeout)

public void WaitAll(params Task[] tasks)

Parameters

tasks Task[]

Wait<T>(Task<T>)

Wait for a given asynchronous operation to complete (or timeout)

public T Wait<T>(Task<T> task)

Parameters

task Task<T>

Returns

T

Type Parameters

T

Events

ConfigurationChanged

Raised when configuration changes are detected

public event EventHandler<EndPointEventArgs> ConfigurationChanged

Event Type

EventHandler<EndPointEventArgs>

ConfigurationChangedBroadcast

Raised when nodes are explicitly requested to reconfigure via broadcast; this usually means master/slave changes

public event EventHandler<EndPointEventArgs> ConfigurationChangedBroadcast

Event Type

EventHandler<EndPointEventArgs>

ConnectionFailed

Raised whenever a physical connection fails

public event EventHandler<ConnectionFailedEventArgs> ConnectionFailed

Event Type

EventHandler<ConnectionFailedEventArgs>

ConnectionRestored

Raised whenever a physical connection is established

public event EventHandler<ConnectionFailedEventArgs> ConnectionRestored

Event Type

EventHandler<ConnectionFailedEventArgs>

ErrorMessage

A server replied with an error message;

public event EventHandler<RedisErrorEventArgs> ErrorMessage

Event Type

EventHandler<RedisErrorEventArgs>

HashSlotMoved

Raised when a hash-slot has been relocated

public event EventHandler<HashSlotMovedEventArgs> HashSlotMoved

Event Type

EventHandler<HashSlotMovedEventArgs>

InternalError

Raised whenever an internal error occurs (this is primarily for debugging)

public event EventHandler<InternalErrorEventArgs> InternalError

Event Type

EventHandler<InternalErrorEventArgs>