ctstone / csredis

.NET client for Redis and Redis Sentinel (2.8). Includes both synchronous and asynchronous clients.
Other
292 stars 111 forks source link

C# Consumer Class using RedisSubscriptionClient #12

Closed OlivierThompson closed 10 years ago

OlivierThompson commented 10 years ago

Hi, I'm asking help for a sample C# Consumer class based on csredis and RedisSubscriptionClient . As a newcomer to C#, I recently discovered there are multiples ways of writing such a class, lambda expressions, callbacks, delegates etc.. Well I'm just looking for the simpliest solution that works. I read the samples but didnt find any complete consumer class here, nor in servicestack redis. I tested my Producer Class with redis-cli and "monitor", it works fine, I can see the messages posted.
Thanks in advance. Cheers

Here is the codefor my Consumer Class at the moment

using ctstone.Redis; using NUnit.Framework; public class Consumer : IDisposable { protected RedisSubscriptionClient sub; protected string Channel;
public delegate void onSuscriptionReceived(object sender, EventArgs e); public event onSuscriptionReceived received; public Consumer(string symbol) { Channel = symbol; sub = new RedisSubscriptionClient("localhost", 6379, ""); sub.SubscriptionReceived += (o, e) => { /* what do I put here ? /}; sub.Subscribe(Channel); } public void Dispose() { / what do I put here ? / } } public void ProcessMessageDelegate(object sender, EventArgs e) { / what do I put here ? */ }

and ..

        producer = new Producer("aChannel");
        consumer = new Consumer("aChannel");

        producer.SendMessage("test");