本文整理汇总了C#中RedisClient.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Publish方法的具体用法?C# RedisClient.Publish怎么用?C# RedisClient.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Publish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPSubscribe
public void TestPSubscribe()
{
int change_count = 0;
int message_count = 0;
string last_message = String.Empty;
using (var redisConsumer = new RedisClient(Host, Port, 0))
using (var redisPublisher = new RedisClient(Host, Port, 0))
{
redisConsumer.Auth(Password);
redisPublisher.Auth(Password);
redisConsumer.SubscriptionReceived += (o, e) =>
{
message_count++;
last_message = e.Message.Body;
};
redisConsumer.SubscriptionChanged += (o, e) =>
{
change_count++;
};
Task consumer_task = Task.Factory.StartNew(() =>
{
redisConsumer.PSubscribe("t*");
});
while (change_count != 1) // wait for psubscribe
Thread.Sleep(10);
Assert.AreEqual(1, redisPublisher.Publish("test", "hello world"), "First publish");
Assert.AreEqual(0, redisPublisher.Publish("junk", "nothing"), "Junk publish");
Assert.AreEqual(1, redisPublisher.Publish("test2", "hello again"), "Second publish");
redisConsumer.PSubscribe("c*");
while (change_count != 2) // wait for psubscribe
Thread.Sleep(10);
Assert.AreEqual(1, redisPublisher.Publish("channel1", "something new"), "New channel publish");
redisConsumer.PUnsubscribe("t*");
redisConsumer.PUnsubscribe();
consumer_task.Wait();
Assert.AreEqual(3, message_count);
Assert.AreEqual(4, change_count);
Assert.AreEqual("something new", last_message);
}
}
示例2: PublishTest
public void PublishTest()
{
using (var mock = new FakeRedisSocket(":3\r\n"))
using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
{
Assert.AreEqual(3, redis.Publish("test", "message"));
Assert.AreEqual("*3\r\n$7\r\nPUBLISH\r\n$4\r\ntest\r\n$7\r\nmessage\r\n", mock.GetMessage());
}
}
示例3: _publishMessage
private void _publishMessage(JObject o)
{
o.Add(new JProperty("_timestamp", DateTime.UtcNow.ToBinary()));
using (var redis = new RedisClient(redisHost, redisPort))
{
redis.Publish(order_channel_publish, o.ToString(Formatting.None));
}
}
示例4: OnStart
//.........这里部分代码省略.........
{
alreadyHandledActions.Remove(key);
return;
}
HandlePositionClosed(e.Position);
}
catch (Exception ex)
{
this.Print("Error Positions.Closed:" + ex.Message + "---" + ex.Source);
this.Print(ex.StackTrace.Replace('\n', '-'));
}
};
}).Start();
foreach (var sym in symbols)
{
var symbol = this.MarketData.GetSymbol(sym);
this.MarketData.GetMarketDepth(symbol).Updated += () =>
{
var book = this.MarketData.GetMarketDepth(symbol);
var askDepth = book.AskEntries.Sum(e => e.Volume);
var bidDepth = book.BidEntries.Sum(e => e.Volume);
var asks = this.include_depth ? book.AskEntries.Select(t => new JObject(new JProperty(t.Price.ToString(), t.Volume))) : null;
var bids = this.include_depth ? book.BidEntries.Select(t => new JObject(new JProperty(t.Price.ToString(), t.Volume))) : null;
JObject o = new JObject(
new JProperty("cmd", "tick"),
new JProperty("payload", new JObject(
new JProperty("symbol", symbol.Code.ToLower()),
new JProperty("bid", symbol.Bid),
new JProperty("ask", symbol.Ask),
new JProperty("bidDepth", bidDepth),
new JProperty("askDepth", askDepth),
new JProperty("bids", bids),
new JProperty("asks", asks),
new JProperty("pip_size", symbol.PipSize),
new JProperty("spread", Math.Round(symbol.Spread / symbol.PipSize, 1)),
new JProperty("time", this.Server.Time.ToString("yyyy-MM-dd HH:mm:ss.FFFZ", CultureInfo.InvariantCulture))
)
));
quote_queue.Enqueue(o);
};
}
new Task(() =>
{
while (!_shuttingDown)
{
JObject o = new JObject(
new JProperty("cmd", "account_status"),
new JProperty("payload", new JObject(
new JProperty("acct_id", this.Account.Number),
new JProperty("is_live", this.Account.IsLive),
new JProperty("balance", this.Account.Balance),
new JProperty("equity", this.Account.Equity),
new JProperty("unrealized_gross_profit", this.Account.UnrealizedGrossProfit)
)
));
_publishMessage(o);
Thread.Sleep(1000 * 10);
}
}).Start();
new Task(() =>
{
while (Quotes && !_shuttingDown)
{
if (!_redisClientQuote.IsConnected) _redisClientQuote.Connect(5000);
if (quote_queue.Count > 0)
{
_redisClientQuote.StartPipe();
while (quote_queue.Count > 0)
{
JObject quote = quote_queue.Dequeue();
_redisClientQuote.Publish(quote_channel, quote.ToString(Formatting.None));
}
_redisClientQuote.EndPipe();
}
Thread.Sleep(50);
}
}).Start();
new Task(() =>
{
try
{
_redisClientOrderChannel.PSubscribe(order_channel_listen);
}
catch (Exception e)
{
this.Print(e.Message);
}
}).Start();
base.OnStart();
}