本文整理汇总了C#中BookSleeve.RedisConnection.GetOpenSubscriberChannel方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.GetOpenSubscriberChannel方法的具体用法?C# RedisConnection.GetOpenSubscriberChannel怎么用?C# RedisConnection.GetOpenSubscriberChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookSleeve.RedisConnection
的用法示例。
在下文中一共展示了RedisConnection.GetOpenSubscriberChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedisMessageBus
public RedisMessageBus(string server, int port, string password, int db, IEnumerable<string> keys, IDependencyResolver resolver)
: base(resolver)
{
_db = db;
_keys = keys.ToArray();
_connection = new RedisConnection(host: server, port: port, password: password);
_connection.Closed += OnConnectionClosed;
_connection.Error += OnConnectionError;
// Start the connection
_connectTask = _connection.Open().Then(() => {
// Create a subscription channel in redis
_channel = _connection.GetOpenSubscriberChannel();
// Subscribe to the registered connections
_channel.Subscribe(_keys, OnMessage);
// Dirty hack but it seems like subscribe returns before the actual
// subscription is properly setup in some cases
while (_channel.SubscriptionCount == 0) {
Thread.Sleep(500);
}
});
}
示例2: ConnectionReady
public bool ConnectionReady()
{
if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
{
lock (_connectionLock)
{
if (_redisConnection == null || _redisConnection.State != RedisConnectionBase.ConnectionState.Open)
{
_redisConnection = new RedisConnection(Host, Port, password: Password);
try
{
_redisConnection.Open();
_subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
_subscriberConnection.MessageReceived += OnRedisMessageReceived;
_subscriberConnection.Error += OnRedisError;
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}
return true;
}
示例3: RedisSignalBus
public RedisSignalBus(RedisConnection redisConnection)
{
_handlers = new ConcurrentDictionary<string, SafeSet<EventHandler<SignaledEventArgs>>>();
_redisConnection = redisConnection;
_subscriberConnection = _redisConnection.GetOpenSubscriberChannel();
_subscriberConnection.MessageReceived += OnRedisMessageReceived;
}
示例4: Main
/// <summary>
/// This is a small application to test event subscriptions in redis - which are required for automatic expiry of cache items
/// if subscriptions dont work try setting the redis config :
/// config set notify-keyspace-events Ex
/// </summary>
/// <param name="args"></param>
private static void Main(string[] args)
{
Console.WriteLine("Start");
_conn = new RedisConnection("localhost");
var c = _conn.Open();
c.Wait();
Console.WriteLine("Conn : " + _conn.State);
_conn.Keys.Remove(_db, "_expireys");
_subConn = new RedisSubscriberConnection("localhost");
var s = _subConn.Open();
s.Wait();
Console.WriteLine("SubConn : " + _subConn.State);
channel = _conn.GetOpenSubscriberChannel();
Thread.Sleep(100);
Console.WriteLine("Channel : " + channel.State);
channel.PatternSubscribe("*:expired", OnExecutionCompleted).Wait();
Console.WriteLine("Subscriptions : " + channel.SubscriptionCount);
Set(1, 4);
Thread.Sleep((6 * 1000) );
if (received > 0)
{
Console.WriteLine("Subscriptions have worked");
}
else
{
Console.WriteLine("Subscriptions have not worked");
}
Console.ReadKey();
}