當前位置: 首頁>>代碼示例>>C#>>正文


C# RedisClient.CreateSubscription方法代碼示例

本文整理匯總了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();
        }
開發者ID:joaofx,項目名稱:nedis,代碼行數:27,代碼來源:NedisQueue.cs

示例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);
                }
            }
        }
開發者ID:jbroder,項目名稱:CrisisTracker,代碼行數:29,代碼來源:Program.cs

示例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();
        }
開發者ID:borakasmer,項目名稱:RedisPubSubWithSignalR,代碼行數:28,代碼來源:Program.cs

示例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");
                }
            }
        }
開發者ID:completecorrect,項目名稱:FundManagement,代碼行數:23,代碼來源:Program.cs

示例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();
        }
開發者ID:rjourde,項目名稱:redis-demo,代碼行數:83,代碼來源:Program.cs


注:本文中的ServiceStack.Redis.RedisClient.CreateSubscription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。