2015-10-01 20 views
13

Tôi đang tìm kiếm một khởi động C ứng dụng rất đơn giản cho việc sử dụng # StackExchange.Redis Tôi đã tìm kiếm trên web và tìm thấy StackExchange.RedisStackExchange.Redis đơn giản C# Ví dụ

Nhưng điều này không có vẻ như một ví dụ khởi động nhanh.

tôi đã thiết lập redis trên cửa sổ sử dụng StackExchange.Redis exe

bất cứ ai có thể giúp tôi xác định vị trí một đơn giản C# ứng dụng kết nối với máy chủ redis và thiết lập và nhận được một số phím.

+0

Bạn đang tìm kiếm để sử dụng bộ nhớ đệm hoặc máy chủ bang? –

+0

Bạn đã xem [readme] (https://github.com/StackExchange/StackExchange.Redis/blob/master/README.md) chưa? – thepirat000

Trả lời

13

Bạn có thể tìm thấy các ví dụ C# trong tệp readme.

using StackExchange.Redis; 
... 
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); 
IDatabase db = redis.GetDatabase(); 
string value = "abcdefg"; 
db.StringSet("mykey", value); 
... 
string value = db.StringGet("mykey"); 
Console.WriteLine(value); // writes: "abcdefg" 
+0

Tôi cũng khuyên bạn nên thư viện [CachingFramework.Redis] (https://github.com/thepirat000/CachingFramework.Redis) được xây dựng trên SE.Redis và cung cấp thêm chức năng như cơ chế gắn thẻ, serialization có thể cắm được và nhiều thứ khác. – thepirat000

6

Xem đoạn mã sau từ github sample của họ:

using (var muxer = ConnectionMultiplexer.Connect("localhost,resolvedns=1")) 
     { 
      muxer.PreserveAsyncOrder = preserveOrder; 
      RedisKey key = "MBOA"; 
      var conn = muxer.GetDatabase(); 
      muxer.Wait(conn.PingAsync()); 

      Action<Task> nonTrivial = delegate 
      { 
       Thread.SpinWait(5); 
      }; 
      var watch = Stopwatch.StartNew(); 
      for (int i = 0; i <= AsyncOpsQty; i++) 
      { 
       var t = conn.StringSetAsync(key, i); 
       if (withContinuation) t.ContinueWith(nonTrivial); 
      } 
      int val = (int)muxer.Wait(conn.StringGetAsync(key)); 
      watch.Stop(); 

      Console.WriteLine("After {0}: {1}", AsyncOpsQty, val); 
      Console.WriteLine("({3}, {4})\r\n{2}: Time for {0} ops: {1}ms; ops/s: {5}", AsyncOpsQty, watch.ElapsedMilliseconds, Me(), 
       withContinuation ? "with continuation" : "no continuation", preserveOrder ? "preserve order" : "any order", 
       AsyncOpsQty/watch.Elapsed.TotalSeconds); 
     } 
Các vấn đề liên quan