2015-10-01 10 views
13

Cerco un antipasto molto semplice C# applicazione per l'utilizzo StackExchange.Redis ho cercare sul web e ha trovato StackExchange.RedisStackExchange.Redis semplice C# Esempio

Ma questo non mi sembra un esempio di avvio rapido.

devo Redis installazione in Windows utilizzando StackExchange.Redis exe

Qualcuno può aiutarmi a trovare una semplice applicazione C# la connessione con il server Redis e l'impostazione e ottenere alcuni tasti.

+0

Stai cercando di utilizzare la cache o server di stato? –

+0

Hai visto il [readme] (https://github.com/StackExchange/StackExchange.Redis/blob/master/README.md)? – thepirat000

risposta

13

È possibile trovare esempi C# nel file 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

Vi consiglio anche la libreria [CachingFramework.Redis] (https://github.com/thepirat000/CachingFramework.Redis) che è stata costruita su SE.Redis e offre funzionalità extra come meccanismo di codifica, serializzazione collegabile e molto altro. – thepirat000

6

Vedere il seguente codice da loro github sample:

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); 
     }