本文整理汇总了C#中ServiceStack.Redis.RedisClient.PublishMessage方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.PublishMessage方法的具体用法?C# RedisClient.PublishMessage怎么用?C# RedisClient.PublishMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.PublishMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NotifySubscribers
private void NotifySubscribers(string queueName)
{
using (var client = new RedisClient("localhost"))
{
client.PublishMessage(queueName, NewItem);
}
}
示例2: SaveItem
public void SaveItem(Item item)
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
var itemClient = client.As<Item>();
var itemList = itemClient.Lists["urn:item:" + item.ProductID];
item.Id = itemClient.GetNextSequence();
itemList.Add(item);
client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);
//Publis top 5 Ranked Items
IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
List<Item> RankList = new List<Item>();
int counter = 0;
foreach (var itm in Data)
{
counter++;
RankList.Add(new Item() { Name = itm.Key, Price = (int)itm.Value, Id = counter });
}
var itemJson = JsonConvert.SerializeObject(RankList);
client.PublishMessage("Rank", itemJson);
//---------------------------------------------
}
}
示例3: Post
public object Post(RoomMessageJson roomMessage)
{
var hipchatMessage = default(HipchatMessage);
try
{
hipchatMessage = roomMessage.ToHipchatMessage();
}
catch (Exception x)
{
File.WriteAllText(HttpContext.Current.Server.MapPath("errors.log"), x.ToString());
}
using (var redisPublisher = new RedisClient(ConfigUtils.GetAppSetting("redisServer")))
{
redisPublisher.PublishMessage("HipchatMessage", hipchatMessage.ToJson());
}
return hipchatMessage.ToJson();
}
示例4: Main
/*
/// <summary>
/// http://geekswithblogs.net/shaunxu/archive/2012/04/27/redis-on-windows.aspx
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
using (var redis = new RedisClient(RedisConStr))
{
redis.FlushAll();
}
//Dequeue();
//Enqueue();
}
*/
static void Main(string[] args)
{
using (var redis = new RedisClient(RedisConStr))
{
redis.FlushAll();
}
var consumerThread1 = new Thread(new ParameterizedThreadStart(ConsumerAction));
var consumerThread2 = new Thread(new ParameterizedThreadStart(ConsumerAction));
var consumerThread3 = new Thread(new ParameterizedThreadStart(ConsumerAction));
consumerThread1.Start("Consumer 1");
consumerThread2.Start("Consumer 2");
consumerThread3.Start("Consumer 3");
using (var publisher = new RedisClient(RedisConStr))
{
Console.WriteLine("Input message: ");
var message = Console.ReadLine();
while (!string.IsNullOrWhiteSpace(message))
{
publisher.PublishMessage("default", message);
Console.WriteLine("Input message: ");
message = Console.ReadLine();
}
}
Console.WriteLine("Done!");
Console.ReadKey();
}
示例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();
}
示例6: UpdateItem
public void UpdateItem(Item item)
{
var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "yyyyyyyyyyyyyyyyyy", Ssl = true, Port = 6380 };
using (IRedisClient client = new RedisClient(conf))
{
IRedisTypedClient<Item> itemClient = client.As<Item>();
IRedisList<Item> itemList = itemClient.Lists["urn:item:" + item.ProductID];
var index = itemList.Select((Value, Index) => new { Value, Index })
.Single(p => p.Value.Id == item.Id).Index;
var toUpdateItem = itemList.First(x => x.Id == item.Id);
//var index = itemList.IndexOf(toUpdateItem);
toUpdateItem.Name = item.Name;
toUpdateItem.Price = item.Price;
itemList.RemoveAt(index);
if (itemList.Count - 1 < index)
itemList.Add(toUpdateItem);
else itemList.Insert(index, toUpdateItem);
client.RemoveItemFromSortedSet("urn:Rank", item.Name);
client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);
//Publis top 5 Ranked Items
IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
List<Item> RankList = new List<Item>();
int counter = 0;
foreach (var itm in Data)
{
counter++;
RankList.Add(new Item() { Name = itm.Key, Price = (int)itm.Value, Id = counter });
}
var itemJson = JsonConvert.SerializeObject(RankList);
client.PublishMessage("Rank", itemJson);
//---------------------------------------------
}
}
示例7: test_redis
public ActionResult test_redis()
{
dynamic house_j = new JObject();
house_j.address = "上海市普陀区金鼎路298弄45号601";
house_j.zone_name = "上海家园小区";
house_j.sql_id = 123123123123;
house_j.master = "业主";
house_j.master_mobile = 13917447328; //业主电话
house_j.manage = "经纪人";
house_j.manage_mobile = 13917447328; //经纪人电话
house_j.create_time = DateTime.UtcNow.ToUnixTimestamp();
var channel_name = "address:googlemap:geo:update";
using (var redisPublisher = new RedisClient())
{
for (var i = 1; i <= 10; i++)
{
redisPublisher.PublishMessage(channel_name,house_j.ToString() );
}
}
return new RenderJsonResult { Result = new { house = house_j } };
}