当前位置: 首页>>代码示例>>C#>>正文


C# RedisClient.Publish方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:richard-green,项目名称:csredis,代码行数:45,代码来源:RedisPubSubTests.cs

示例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());
     }
 }
开发者ID:DTBruce,项目名称:csredis,代码行数:9,代码来源:PubSubTests.cs

示例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));
     }
 }
开发者ID:pennyfx,项目名称:ctrader-to-redis-interface,代码行数:8,代码来源:cAlgoRedisClient.cs

示例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();
        }
开发者ID:pennyfx,项目名称:ctrader-to-redis-interface,代码行数:101,代码来源:cAlgoRedisClient.cs


注:本文中的RedisClient.Publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。