本文整理汇总了C#中StackExchange.Redis.ConnectionMultiplexer类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMultiplexer类的具体用法?C# ConnectionMultiplexer怎么用?C# ConnectionMultiplexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionMultiplexer类属于StackExchange.Redis命名空间,在下文中一共展示了ConnectionMultiplexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Redis
private Redis()
{
try
{
redis = ConnectionMultiplexer.Connect("localhost");
DB = redis.GetDatabase();
}
catch (RedisConnectionException rce)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = Environment.CurrentDirectory + @"\redis\redis.windows.conf";
startInfo.FileName = Environment.CurrentDirectory + @"\redis\redis-server.exe";
startInfo.WorkingDirectory = Environment.CurrentDirectory + @"\redis\";
Process p = Process.Start(startInfo);
Thread.Sleep(200);
for (int i = 0; i < 3; ++i)
{
try
{
redis = ConnectionMultiplexer.Connect("localhost");
DB = redis.GetDatabase();
break;
}
catch (RedisConnectionException rce2)
{
Thread.Sleep(1000);
}
}
}
}
示例2: OpenAsync
public async Task OpenAsync(PartitionContext context)
{
if (!WebJobsHelper.RunAsWebJobs)
Console.WriteLine(string.Format("EventProcessor initialization. Partition: '{0}', Offset: '{1}'",
context.Lease.PartitionId, context.Lease.Offset));
partitionContext = context;
var retries = 3;
while (retries > 0)
{
try
{
retries--;
hubClient = EventHubClient.CreateFromConnectionString(
ConfigurationManager.ConnectionStrings["SigfoxDemoAlertSender"].ConnectionString,
"alert");
cacheConnection = await ConnectionMultiplexer.ConnectAsync(ConfigurationManager.ConnectionStrings["SigfoxDemoCache"].ConnectionString);
cacheDatabase = cacheConnection.GetDatabase();
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SigfoxDemoDatabase"].ConnectionString);
//sqlConnection.Open();
//sqlCommand = new SqlCommand("InsertAlert", sqlConnection) { CommandType = CommandType.StoredProcedure };
//sqlCommand.Parameters.Add(new SqlParameter("@Device", SqlDbType.VarChar));
retries = 0;
}
catch (Exception e)
{
Console.Error.WriteLine("Error opening destination Event Hub: " + e.Message);
if (retries == 0)
throw;
}
}
checkpointStopWatch = new Stopwatch();
checkpointStopWatch.Start();
}
示例3: MessagesController
public MessagesController(ApplicationDbContext context, UserManager<ApplicationUser> userManager, MapperConfiguration mapperConfiguration, ConnectionMultiplexer redis)
{
_context = context;
_userManager = userManager;
_mapperConfiguration = mapperConfiguration;
_redis = redis;
}
示例4: RedisManager
public RedisManager()
{
var configurationOptions = new ConfigurationOptions {Password = "be61827946a5d7a6b7333875104d4a26"};
configurationOptions.EndPoints.Add(HostAndPort);
_redisConn = ConnectionMultiplexer.Connect(configurationOptions);
}
示例5: 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);
}
}
}
示例6: RedisCacheConfig
static RedisCacheConfig()
{
string isLocal = WebConfigReader.Read("IsLocal");
if (isLocal == "1")
{
connection = ConnectionMultiplexer.Connect(WebConfigReader.Read("RedisServer"));
}
else
{
var options = new ConfigurationOptions();
options.EndPoints.Add(WebConfigReader.Read("RedisKeyDns"), 6380);
options.Ssl = true;
options.Password = WebConfigReader.Read("RedisPassword");
options.AllowAdmin = true;
// necessary?
options.KeepAlive = 30;
options.ConnectTimeout = 15000;
options.SyncTimeout = 15000;
connection = ConnectionMultiplexer.Connect(options);
}
}
示例7: RedisEntityTagStore
public RedisEntityTagStore(ConnectionMultiplexer connection,
int databaseId = 0,
TimeSpan? expiry = null)
{
_expiry = expiry;
Init(connection, databaseId);
}
示例8: RedisCache
/// <summary>
/// Initializes a new instance of the <see cref="RedisCache"/> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
public RedisCache(ConfigurationOptions configuration)
{
if (RedisCache.connection == null)
{
try
{
connectionTask = ConnectionMultiplexer.ConnectAsync(configuration);
connectionTask.ContinueWith(t =>
{
lock (syncronizationObject)
{
if (RedisCache.connection == null)
RedisCache.connection = t.Result;
}
this.cache = RedisCache.connection.GetDatabase();
Trace.TraceInformation("Redis Cache Provider connection complete - Correlation Id = {0}", Trace.CorrelationManager.ActivityId);
});
}
catch (AggregateException age)
{
age.Handle(e =>
{
Trace.TraceError("Redis Cache Provider error - Correlation Id = {0}\n {1}\n {2}", Trace.CorrelationManager.ActivityId, e.Message, e.StackTrace);
return true;
});
}
catch (Exception ex)
{
Trace.TraceError("Redis Cache Provider exception - Correlation Id = {0}\n {1}\n {2}", Trace.CorrelationManager.ActivityId, ex.Message, ex.StackTrace);
}
}
}
示例9: UseRedis
/// <summary>
/// Use Redis as the messaging backplane for scaling out of ASP.NET SignalR applications in a web farm.
/// </summary>
/// <param name="resolver">The dependency resolver</param>
/// <param name="configuration">The Redis scale-out configuration options.</param>
/// <param name="sharedMultiplexer">shared multiplexer</param>
/// <returns>The dependency resolver.</returns>
public static IDependencyResolver UseRedis(this IDependencyResolver resolver, RedisScaleoutConfiguration configuration, ConnectionMultiplexer sharedMultiplexer)
{
var bus = new Lazy<RedisMessageBus>(() => new RedisMessageBus(resolver, configuration, new RedisConnection(sharedMultiplexer)));
resolver.Register(typeof(IMessageBus), () => bus.Value);
return resolver;
}
示例10: MainForm
public MainForm()
{
InitializeComponent();
var options = new ConfigurationOptions
{
ConnectTimeout = 5000,
SyncTimeout = 2000,
KeepAlive = 60,
EndPoints =
{
{Settings.Default.RedisHost, Settings.Default.RedisPort}
}
};
_redis = ConnectionMultiplexer.Connect(options);
var retries = 0;
while (!_redis.IsConnected)
{
var config = _redis.Configuration;
_redis.Dispose();
if (retries > 10)
{
MessageBox.Show(string.Format("Could not connect to the Redis server with configuration: {0}",
config));
Application.Exit();
}
_redis = ConnectionMultiplexer.Connect(options, Console.Out);
retries++;
}
_red = new LightControlSet(button_RedOn, button_RedOff, button_RedFlash, textBox_RedOnDuty, textBox_RedOffDuty, textBox_RedOffset, textBox_RedPower, button_RedApply);
_green = new LightControlSet(button_GreenOn, button_GreenOff, button_GreenFlash, textBox_GreenOnDuty, textBox_GreenOffDuty, textBox_GreenOffset, textBox_GreenPower, button_GreenApply);
_blueYellow = new LightControlSet(button_BlueOn, button_BlueOff, button_BlueFlash, textBox_BlueOnDuty, textBox_BlueOffDuty, textBox_BlueOffset, textBox_BluePower, button_BlueApply);
}
示例11: Connect
public static void Connect()
{
ConfigurationOptions options = new ConfigurationOptions();
options.EndPoints.Add("localhost:6379");
Connection = ConnectionMultiplexer.Connect(options);
}
示例12: RetrieveMultiplexer
public static ConnectionMultiplexer RetrieveMultiplexer(ConfigurationOptions config)
{
if(_multiplexer != null) return _multiplexer;
_multiplexer = ConnectionMultiplexer.Connect(config);
return _multiplexer;
}
示例13: RedisStorage
public RedisStorage(string connectionString, RedisStorageOptions options = null)
{
if (connectionString == null) throw new ArgumentNullException("connectionString");
if (options == null) options = new RedisStorageOptions();
_connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
_invisibilityTimeout = options.InvisibilityTimeout;
var endpoint = _connectionMultiplexer.GetEndPoints()[0];
if (endpoint is IPEndPoint)
{
var ipEp = endpoint as IPEndPoint;
ConnectionString = string.Format("{0}:{1}", TryGetHostName(ipEp.Address), ipEp.Port);
}
else
{
var dnsEp = endpoint as DnsEndPoint;
ConnectionString = string.Format("{0}:{1}", dnsEp.Host, dnsEp.Port);
}
Db = options.Db;
if (Prefix != options.Prefix)
{
Prefix = options.Prefix;
}
identity = Guid.NewGuid().ToString();
}
示例14: 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");
}
示例15: 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);
}
}