本文整理汇总了C#中StackExchange.Redis.ConnectionMultiplexer.GetSubscriber方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMultiplexer.GetSubscriber方法的具体用法?C# ConnectionMultiplexer.GetSubscriber怎么用?C# ConnectionMultiplexer.GetSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackExchange.Redis.ConnectionMultiplexer
的用法示例。
在下文中一共展示了ConnectionMultiplexer.GetSubscriber方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: subscribeSelfFilter
static string subscribeSelfFilter(ConnectionMultiplexer redis, string SubscribeItem, int timeOut, Func<RedisValue, bool> filter)
{
AutoResetEvent autoEvent = new AutoResetEvent(false);
var sub = redis.GetSubscriber();
Console.WriteLine("client is waitting");
var res = string.Empty;
var t = Thread.CurrentThread;
var flag = true;
var tt2 = DateTime.MinValue.Ticks;
var tt1 = DateTime.MaxValue.Ticks;
//Task realT = null;
sub.SubscribeAsync(SubscribeItem, (channel, message) =>
{
if (flag && filter(message))
{
//sub.Unsubscribe(SubscribeItem);
Console.WriteLine(message);
res = message.ToString();
//res = "evil";
autoEvent.Set();
}
tt2 = DateTime.Now.Ticks;
Console.WriteLine("processTime:" + (tt2 - tt1));
});
//flag = false;
Console.WriteLine("timeout");
autoEvent.WaitOne(1);
//Thread.Sleep(timeOut);
tt1 = DateTime.Now.Ticks;
//sub.Publish(SubscribeItem, "aa");
sub.UnsubscribeAllAsyncBefore().Wait();
Console.WriteLine("res:" + res);
var tt3 = DateTime.Now.Ticks;
Console.WriteLine("pubTime:" + (tt3 - tt1));
//Thread.Sleep(500);
//redis.Close(false);
//if(realT != null)
//{
// realT.Wait();
//}
//sub.Unsubscribe(SubscribeItem);
return res;
}
示例3: ConnectAsync
public async Task ConnectAsync(string connectionString, TraceSource trace)
{
_connection = await ConnectToRedis(connectionString);
_connection.ConnectionFailed += OnConnectionFailed;
_connection.ConnectionRestored += OnConnectionRestored;
_connection.ErrorMessage += OnError;
_trace = trace;
_redisSubscriber = _connection.GetSubscriber();
}
示例4: ConnectAsync
public async Task ConnectAsync(string connectionString, ILogger logger)
{
_connection = await ConnectionMultiplexer.ConnectAsync(connectionString);
_connection.ConnectionFailed += OnConnectionFailed;
_connection.ConnectionRestored += OnConnectionRestored;
_connection.ErrorMessage += OnError;
_logger = logger;
_redisSubscriber = _connection.GetSubscriber();
}
示例5: RedisStorage
public RedisStorage(ConfigurationOptions Options, int db, string prefix)
{
if (Options == null) throw new ArgumentNullException("Options");
var HangfireOptions = new RedisStorageOptions()
{
Prefix = prefix
};
Db = db;
Options.AbortOnConnectFail = false;
Options.ClientName = ClientName;
ServerPool = ConnectionMultiplexer.Connect(Options);
var Sub = new RedisSubscribe(ServerPool.GetSubscriber(), prefix);
var LockID = Guid.NewGuid().ToString();
StorageInternals = new RedisStorageInternals(prefix, LockID, Sub);
FetchedJobsOptions = new FetchedJobsWatcherOptions(HangfireOptions);
}
示例6: Initialize
public bool Initialize(string clientId, string connection)
{
var connectionDict = connection.ToObject<Dictionary<string, object>>();
ClientId = clientId;
var server = connectionDict.GetSetting("server", "");
_multiplexer = ConnectionMultiplexer.Connect(server);
var subscriber = _multiplexer.GetSubscriber();
subscriber.Subscribe("RedisNotifier.serverMessage", onMessage);
subscriber.Subscribe("RedisNotifier.expireCache", onExpireCache);
subscriber.Subscribe("RedisNotifier.expireItemCache", onExpireItemCache);
BroadcastMessage(string.Format("Redis {0} client connected on: {1}", clientId, server));
log(Logging.LoggingLevel.Minimal, "Initialized");
return true;
}
示例7: RedisHybridCacheClient
public RedisHybridCacheClient(ConnectionMultiplexer connectionMultiplexer, ISerializer serializer = null, ILoggerFactory loggerFactory = null)
: base(new RedisCacheClient(connectionMultiplexer, serializer, loggerFactory), new RedisMessageBus(connectionMultiplexer.GetSubscriber(), "cache-messages", serializer, loggerFactory), loggerFactory) { }
示例8: RockMemoryCache
/// <summary>
/// Initializes a new instance of the <see cref="RockMemoryCache"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="config">The configuration.</param>
private RockMemoryCache( string name, NameValueCollection config = null )
: base(name, config)
{
// Use lambda expressions to create a set method for MemoryCache._stats._lastTrimGen2Count to circumvent poor functionality of MemoryCache
// The default MemoryCache does not check for memory pressure except after a Gen 2 Garbage Collection. We want to do this more often than that.
// So this method allows us to reset the field the MemoryCacheStatistics object uses periodically to a new value, to force the trim to be checked.
// Define the types
var memoryCacheType = typeof( MemoryCache );
var memoryCacheStatisticsType = memoryCacheType.Assembly.GetType( "System.Runtime.Caching.MemoryCacheStatistics", true );
// Define the _stats field on MemoryCache
var statsField = memoryCacheType.GetField( "_stats", BindingFlags.Instance | BindingFlags.NonPublic );
// Define the _lastTrimGen2Count field on MemoryCacheStatistics
var lastTrimGen2CountField = memoryCacheStatisticsType.GetField( "_lastTrimGen2Count", BindingFlags.Instance | BindingFlags.NonPublic );
// Get a reference to this memory cache instance
var targetExpression = Expression.Constant( this, typeof( MemoryCache ) );
// Define the parameters to the method
var valueExpression = Expression.Parameter( typeof( int ), "value" );
// Create the field expressions
var statsFieldExpression = Expression.Field( targetExpression, statsField );
var lastTrimGen2CountFieldExpression = Expression.Field( statsFieldExpression, lastTrimGen2CountField );
// Create the field value assignment expression
var fieldValueAssignmentExpression = Expression.Assign( lastTrimGen2CountFieldExpression, valueExpression );
// Compile to function
_setMemoryCacheLastTrimGen2CountFunc = Expression.Lambda<Action<int>>( fieldValueAssignmentExpression, valueExpression ).Compile();
// Fire this method initially after a 1000 ms delay
_setMemoryCacheLastTrimGen2CountTimer = new Timer( SetMemoryCacheLastTrimGen2Count, null, 1000, Timeout.Infinite );
// Check to see if caching has been disabled
_isCachingDisabled = ConfigurationManager.AppSettings["DisableCaching"].AsBoolean();
// setup redis cache clustering if needed
_isRedisClusterEnabled = ConfigurationManager.AppSettings["EnableRedisCacheCluster"].AsBoolean();
if ( _isRedisClusterEnabled && _isCachingDisabled == false )
{
string connectionString = ConfigurationManager.AppSettings["RedisConnectionString"];
if ( !string.IsNullOrWhiteSpace( connectionString ) )
{
try
{
_redisConnection = ConnectionMultiplexer.Connect( connectionString );
_redisConnection.PreserveAsyncOrder = false; // enable concurrent processing of pub/sub messages https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/PubSubOrder.md
_redisConnection.ConnectionRestored += _redisConnection_ConnectionRestored;
_redisConnection.ConnectionFailed += _redisConnection_ConnectionFailed;
_isRedisConnected = true;
}
catch ( Exception ex )
{
Model.ExceptionLogService.LogException( ex, null );
}
if ( _redisConnection != null )
{
// setup the subscription to listen for published instructions on caching
ISubscriber sub = _redisConnection.GetSubscriber();
sub.Subscribe( REDIS_CHANNEL_NAME, ( channel, message ) => {
ProcessRedisCacheInstruction( channel, message );
} );
}
else
{
_isRedisClusterEnabled = false;
}
}
else
{
_isRedisClusterEnabled = false;
}
}
}
示例9: MasterWasSwitched
private void MasterWasSwitched(RedisChannel redisChannel, RedisValue redisValue)
{
_connection.ConnectionFailed -= OnConnectionFailed;
_connection.ConnectionRestored -= OnConnectionRestored;
_connection.ErrorMessage -= OnError;
_connection.Close();
if (redisValue.IsNullOrEmpty) return;
var message = redisValue.ToString();
var messageParts = message.Split(' ');
var ip = IPAddress.Parse(messageParts[3]);
var port = int.Parse(messageParts[4]);
EndPoint newMasterEndpoint = new IPEndPoint(ip, port);
if (_options.EndPoints.Any() && newMasterEndpoint == _options.EndPoints[0]) return;
_options.EndPoints.Clear();
_options.EndPoints.Add(newMasterEndpoint);
_connection = ConnectionMultiplexer.Connect(_options);
_connection.ConnectionFailed += OnConnectionFailed;
_connection.ConnectionRestored += OnConnectionRestored;
_connection.ErrorMessage += OnError;
_redisSubscriber = _connection.GetSubscriber();
var handler = ConnectionRestored;
if (handler != null) handler(new ApplicationException("Redis master was switched"));
}
示例10: ConnectToSentinel
private void ConnectToSentinel()
{
_sentinelConnection = ConnectionMultiplexer.Connect(_sentinelConfiguration);
var subscriber = _sentinelConnection.GetSubscriber();
subscriber.Subscribe("+switch-master", MasterWasSwitched);
_sentinelConnection.ConnectionFailed += SentinelConnectionFailed;
_sentinelConnection.ConnectionRestored += SentinelConnectionRestored;
}
示例11: CreateSubscriber
private static ISubscriber CreateSubscriber(string connectionString)
{
_connection = ConnectionMultiplexer.Connect(connectionString);
var subscriber = _connection.GetSubscriber();
return subscriber;
}