本文整理汇总了C#中StackExchange.Redis.ConnectionMultiplexer.GetServer方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMultiplexer.GetServer方法的具体用法?C# ConnectionMultiplexer.GetServer怎么用?C# ConnectionMultiplexer.GetServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackExchange.Redis.ConnectionMultiplexer
的用法示例。
在下文中一共展示了ConnectionMultiplexer.GetServer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WatcherManager
public WatcherManager(IEnumerable<WatchGroup> groups)
{
var groupList = groups.ToList();
var config = new ConfigurationOptions()
{
AllowAdmin = true,
};
foreach (var group in groupList)
{
config.EndPoints.Add(group.Master.EndPoint);
}
muxerInstance = ConnectionMultiplexer.Connect(config);
muxerInstance.ConnectionRestored += MuxerInstanceOnConnectionRestored;
foreach (var group in groupList)
{
var server = muxerInstance.GetServer(group.Master.EndPoint);
var epStr = server.EndPoint.ToString();
group.Master.Server = server;
group.Master.OnPing(TimeSpan.Zero);
Program.zkAdaptor.Identity(group.Master.EndPoint.ToString());
this.groups.Add(epStr, group);
redisInstancesDict.Add(epStr, group.Master);
}
}
示例2: WorkflowManagement
internal WorkflowManagement(ConnectionMultiplexer mux, ITaskHandler taskHandler, WorkflowHandler workflowHandler, string identifier, IEnumerable<string> typesProcessed, ILua lua, EventHandler<Exception> exceptionHandler = null, Behaviours behaviours = Behaviours.All)
{
_taskHandler = taskHandler;
_workflowHandler = workflowHandler;
if (exceptionHandler != null)
{
ExceptionThrown += exceptionHandler;
}
_typesProcessed = typesProcessed;
_db = mux.GetDatabase();
_sub = mux.GetSubscriber();
if (_typesProcessed == null || _typesProcessed.Count() == 0)
{
_sub.Subscribe("submittedTask", (c, v) =>
{
ProcessNextTask();
});
}
else
{
foreach(var t in _typesProcessed)
{
_sub.Subscribe("submittedTask:" + t, (c, v) =>
{
ProcessNextTask(t);
});
}
}
_sub.Subscribe("workflowFailed", (c, v) =>
{
ProcessNextFailedWorkflow();
});
_sub.Subscribe("workflowComplete", (c, v) =>
{
ProcessNextCompleteWorkflow();
});
_lua = lua;
_lua.LoadScripts(_db, mux.GetServer("localhost:6379"));
_identifier = identifier;
if (behaviours.HasFlag(Behaviours.AutoRestart))
{
var resubmittedTasks = ResubmitTasks();
foreach (var item in resubmittedTasks)
{
Console.WriteLine("Resubmitted {0}", item);
}
}
}
示例3: RedisAdaptor
public RedisAdaptor(List<EndPoint> endPoints)
{
var config = new ConfigurationOptions()
{
AllowAdmin = true,
};
foreach (var endPoint in endPoints)
{
config.EndPoints.Add(endPoint);
}
muxerInstance = ConnectionMultiplexer.Connect(config);
Handle = muxerInstance.GetDatabase();
var script = Load("update_multikeys_multifields.lua");
//todo a hack way .. to be changed later
foreach (var endPoint in muxerInstance.GetEndPoints())
{
var server = muxerInstance.GetServer(endPoint);
updateScriptSha = server.ScriptLoad(script);
}
Handle.StringSet("test", "111");
}
示例4: FetchAllKeys
private static IEnumerable<RedisKey> FetchAllKeys(ConnectionMultiplexer multiplexer, EndPoint endpoint)
{
var server = multiplexer.GetServer(endpoint);
var allKeys = server.Keys()
.ToArray();
return allKeys;
}
示例5: TryGetServer
internal static IServer TryGetServer(ConnectionMultiplexer muxer, bool checkConnected = true)
{
if (muxer != null)
{
var eps = muxer.GetEndPoints(true);
foreach (var ep in eps)
{
var server = muxer.GetServer(ep);
if (server.IsSlave) continue;
if (checkConnected && !server.IsConnected) continue;
// that'll do
return server;
}
}
return null;
}
示例6: GetServer
internal static IServer GetServer(ConnectionMultiplexer conn)
{
return conn.GetServer(conn.GetEndPoints()[0]);
}
示例7: Initialize
private void Initialize()
{
var options = new ConfigurationOptions()
{
AllowAdmin = true,
ConnectTimeout = 1000,
};
var endpoint = new DnsEndPoint(_redisConfig.Host, _redisConfig.Port, AddressFamily.InterNetwork);
options.EndPoints.Add(endpoint);
if (!string.IsNullOrEmpty(_redisConfig.Password))
options.Password = _redisConfig.Password;
try
{
// create the connection
_connectionMultiplexer = ConnectionMultiplexer.ConnectAsync(options).Result;
// access to database.
_database = _connectionMultiplexer.GetDatabase(_redisConfig.DatabaseId);
// get the configured server.
_server = _connectionMultiplexer.GetServer(endpoint);
// check the version
var version = GetVersion();
if (version < _requiredMinimumVersion)
throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));
_logger.Information("Storage initialized: {0:l}:{1}, v{2:l}.", endpoint.Host, endpoint.Port, version);
}
catch (Exception e)
{
IsEnabled = false;
_logger.Error(string.Format("Storage initialization failed: {0:l}:{1}.", endpoint.Host, endpoint.Port));
}
}
示例8: RedisTests
public RedisTests()
{
_multiplexer = new RedisDatabase().GetDatabase().Multiplexer;
_server = _multiplexer.GetServer("localhost", 6379);
}
示例9: FlushDatabase
/// <summary>
/// Flushes the database that the connection belongs to.
/// </summary>
/// <param name="connection">
/// The connection.
/// </param>
public void FlushDatabase(ConnectionMultiplexer connection)
{
EndPoint[] endPoints = connection.GetEndPoints();
foreach (var endPoint in endPoints)
{
connection.GetServer(endPoint).FlushDatabase(this.Db);
}
}
示例10: GetDashboardInfo
/// <summary>
/// Provide an alternate ConnectionMultiplexer to use for INFO command
/// </summary>
/// <param name="Connection"></param>
/// <param name="title">Title to appear on the dashboard</param>
/// <param name="key">Redis INFO key</param>
/// <returns></returns>
public DashboardMetric GetDashboardInfo(ConnectionMultiplexer Connection, string title, string key)
{
return GetDashboardInfo(Connection.GetServer(Connection.GetDatabase(Db).IdentifyEndpoint()), title, key);
}
示例11: ReconfigureConnection
private void ReconfigureConnection(List<RedisInstanceBase> toConnect)
{
var config = ConfigurationOptions.Parse(muxerInstance.Configuration);
foreach (var ins in toConnect)
{
config.EndPoints.Add(ins.EndPoint);
}
lock (muxerSyncLock)
{
muxerInstance.Dispose();
muxerInstance = ConnectionMultiplexer.Connect(config);
RefreshAll();
muxerInstance.ConnectionRestored += MuxerInstanceOnConnectionRestored;
}
foreach (var ins in toConnect)
{
ins.Server = muxerInstance.GetServer(ins.EndPoint);
}
}
示例12: Initialize
private void Initialize()
{
var options = new ConfigurationOptions();
var endpoint = new DnsEndPoint(Config.Host, Config.Port, AddressFamily.InterNetwork);
options.EndPoints.Add(endpoint);
options.AllowAdmin = true;
if (!string.IsNullOrEmpty(Config.Password))
options.Password = Config.Password;
try
{
// create the connection
_connectionMultiplexer = ConnectionMultiplexer.ConnectAsync(options).Result;
// access to database.
_database = _connectionMultiplexer.GetDatabase(Config.DatabaseId);
// get the configured server.
_server = _connectionMultiplexer.GetServer(endpoint);
// check the version
var info = _server.Info();
Version version = null;
foreach (var pair in info[0])
{
if (pair.Key == "redis_version")
{
version = new Version(pair.Value);
if (version < _requiredMinimumVersion)
throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));
break;
}
}
Log.ForContext<Redis>().Information("Storage initialized: {0}, v{1}.", endpoint, version);
}
catch (Exception e)
{
IsEnabled = false;
Log.ForContext<Redis>().Error(e, string.Format("Storage initialization failed: {0}", endpoint));
}
}