本文整理汇总了C#中ServiceStack.Redis.RedisClient.CreateSubscription方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.CreateSubscription方法的具体用法?C# RedisClient.CreateSubscription怎么用?C# RedisClient.CreateSubscription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.CreateSubscription方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Subscribe
public void Subscribe(string queueName, Action action)
{
Task.Factory.StartNew(() =>
{
using (var client1 = new RedisClient("localhost"))
{
using (var subscription1 = client1.CreateSubscription())
{
subscription1.OnSubscribe =
channel => Debug.WriteLine(string.Format("Subscribed to '{0}'", channel));
subscription1.OnUnSubscribe =
channel => Debug.WriteLine(string.Format("UnSubscribed from '{0}'", channel));
subscription1.OnMessage = (channel, msg) =>
{
Debug.WriteLine(string.Format("Received '{0}' from channel '{1}' Busy: {2}", msg, channel, false));
action();
};
subscription1.SubscribeToChannels(queueName);
Debug.WriteLine("Subscribed");
}
}
}).Start();
}
示例2: ConsumeStream
static void ConsumeStream()
{
using (var redis = new RedisClient(Settings.AidrRedisConsumer_RedisHost, Settings.AidrRedisConsumer_RedisPort))
{
using (var subscription = redis.CreateSubscription())
{
subscription.OnSubscribe = (channel) => {
Console.WriteLine("Subscribed to " + channel);
};
subscription.OnUnSubscribe = (channel) =>
{
Console.WriteLine("Unsubscribed from " + channel);
};
subscription.OnMessage = (channel, message) =>
{
if (message.EndsWith("}"))
Console.Write(".");
else
Console.Write("!");
_tweetQueue.Enqueue(message);
AllowAsyncDBWrite();
};
subscription.SubscribeToChannelsMatching(Settings.AidrRedisConsumer_SubscribePattern);
}
}
}
示例3: Main
static void Main(string[] args)
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
IRedisSubscription sub = null;
using (sub = client.CreateSubscription())
{
sub.OnMessage += (channel, message) =>
{
try
{
List<Item> items = JsonConvert.DeserializeObject<List<Item>>(message);
Console.WriteLine((string)message);
SignalRClass sc = new SignalRClass();
sc.SendRank(items);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
};
}
sub.SubscribeToChannels(new string[] { "Rank" });
}
Console.ReadLine();
}
示例4: ConsumerAction
private static void ConsumerAction(object name)
{
using (var consumer = new RedisClient(RedisConStr))
{
using (var subscription = consumer.CreateSubscription())
{
subscription.OnSubscribe = (channel) =>
{
Console.WriteLine("[{0}] Subscribe to channel '{1}'.", name, channel);
};
subscription.OnUnSubscribe = (channel) =>
{
Console.WriteLine("[{0}] Unsubscribe to channel '{1}'.", name, channel);
};
subscription.OnMessage = (channel, message) =>
{
Console.WriteLine("[{0}] Received message '{1}' from channel '{2}'.", name, message, channel);
};
subscription.SubscribeToChannels("default");
}
}
}
示例5: Main
static void Main(string[] args)
{
/*** String ***/
using (IRedisNativeClient client = new RedisClient())
{
client.Set("urn:messages:1", Encoding.UTF8.GetBytes("Hello C# World!"));
}
using (IRedisNativeClient client = new RedisClient())
{
var result = Encoding.UTF8.GetString(client.Get("urn:messages:1"));
Console.WriteLine("Message: {0}", result);
}
/*** Lists ***/
using (IRedisClient client = new RedisClient())
{
var customerNames = client.Lists["urn:customernames"];
customerNames.Clear();
customerNames.Add("Joe");
customerNames.Add("Mary");
customerNames.Add("Bob");
}
using (IRedisClient client = new RedisClient())
{
var customerNames = client.Lists["urn:customernames"];
foreach (var customerName in customerNames)
{
Console.WriteLine("Customer {0}", customerName);
}
}
/*** Object ***/
long lastId = 0;
using (IRedisClient client = new RedisClient())
{
var customerClient = client.GetTypedClient<Customer>();
var customer = new Customer()
{
Id = customerClient.GetNextSequence(),
Address = "123 Main St",
Name = "Bob Green",
Orders = new List<Order>
{
new Order { OrderNumber = "AB123"},
new Order { OrderNumber = "AB124"}
}
};
var storedCustomer = customerClient.Store(customer);
lastId = storedCustomer.Id;
}
using (IRedisClient client = new RedisClient())
{
var customerClient = client.GetTypedClient<Customer>();
var customer = customerClient.GetById(lastId);
Console.WriteLine("Got customer {0}, with name {1}", customer.Id, customer.Name);
}
/*** Transaction ***/
using (IRedisClient client = new RedisClient())
{
var transaction = client.CreateTransaction();
transaction.QueueCommand(c => c.Set("abc", 1));
transaction.QueueCommand(c => c.Increment("abc", 1));
transaction.Commit();
var result = client.Get<int>("abc");
Console.WriteLine(result);
}
/*** Publishing & Subscribing ***/
using (IRedisClient client = new RedisClient())
{
client.PublishMessage("debug", "Hello C#!");
var sub = client.CreateSubscription();
sub.OnMessage = (c, m) => Console.WriteLine("Got message {0}, from channel {1}", m, c);
sub.SubscribeToChannels("news");
}
Console.ReadLine();
}