2012-02-21 12 views
3

私はRedisにはかなり新しく、それを評価しています。私はここからRedisのサーバーを使用しています:Redis/ServiceStackクライアントトランザクション例外

ポート6379 タイムアウト300 保存900 1 保存300 10 60万 ログレベルのデバッグ ログファイルの保存:私はまた、サーバーに対して次の設定を使用していますhttps://github.com/downloads/dmajkic/redis/redis-2.4.5-win32-win64.zip

私はこの使用ServiceStackクライアント(ServiceStack-ServiceStack.Redis-4add28のようなコードを実行しようとしています標準出力 データベース1 MaxClientsの32 maxmemory 2147483648

A)ここで

は私のコードは、私が試してみて、コミット時に、ユーザーは、この(ServiceStackに付属している例の一つから)

public class User 
{ 
    public User() 
    { 
     this.BlogIds = new List<long>(); 
    } 

    public long Id { get; set; } 
    public string Name { get; set; } 
    public List<long> BlogIds { get; set; } 
} 

のように見える私はこの例外を取得

public void InsertInsideTransaction(bool shouldTransactionRollback) 
{ 
    RedisClient transClient = new RedisClient("localhost"); 

    ClearAll(); 
    using (var trans = transClient.CreateTransaction()) 
    { 
     trans.QueueCommand(r => 
      { 
       var redisUsers = r.GetTypedClient<User>(); 
       var sacha = new User { Id = redisUsers.GetNextSequence(), Name = "Sacha Barber" }; 
       redisUsers.Store(sacha); 
       //redisUsers.Dispose(); 
      }); 

     //commit or rollback based on incoming flag 
     if (shouldTransactionRollback) 
      trans.Rollback(); 
     else 
      trans.Commit(); 

     IList<User> users = Users(); 
     Console.WriteLine(string.Format("InsertInsideTransaction : There are currently {0}, Users", users.Count())); 
    } 




} 

ですトランザクション

マルチリクエストで不明な返信:43QUEUED、sPort:60793、LastCommand:EXEC

C:\ Users \ barbers \ Desktop \ Downloads \ ServiceStack-ServiceStack.Redis-4add28a \ ServiceStack-ServiceStack.Redis-4add28a \ src \ ServiceStack.Redis \ RedisNativeClient_UtilsのServiceStack.Redis.RedisNativeClient.CreateResponseError(文字列エラー)で

C:\ Users \ barbers \ Desktop \ Downloads \ ServiceStack-ServiceStack.Redis-4add28a \ ServiceStack-ServiceStack.Redis-4add28a \ src \ ServiceStack.Redis \ RedisNativeClient_UtilsのServiceStack.Redis.RedisNativeClient.ReadMultiDataResultCount()にあるcs:行146 ServiceStack.Redis.Pipeline.QueuedRedisOperation.ProcessResult()(C:\ Users \ barbers \ Desktop \ Downloads \ ServiceStack-ServiceStack.Redis-4add28a \ ServiceStack-ServiceStack.Redis-4add28a \ src \ ServiceStack)の.cs:line 578 Redis \ Pipeline \ QueuedRedisOperation.cs:C:\ Users \ barbers \ Desktop \ Downloads \ ServiceStack-ServiceStack.Redis-4addのServiceStack.Redis.RedisTransaction.Commit()の行169 C:\ Users \ barbers \ Desktop \ DocumentDBs \ DocumentDB内のDocumentDB.Redis.RedisMessAround.InsertInsideTransaction(Boolean shouldTransactionRollback)の行番号 の行番号:28a \ ServiceStack-ServiceStack.Redis-4add28a \ src \ ServiceStack.Redis \ Transaction \ RedisTransaction.cs .Redis \ RedisMessAround.cs:C:\ Users \ barbers \ Desktop \ DocumentDBs \ DocumentDB.Redis \ Program.csのDocumentDB.Redis.Program.Run()の行63 :DocumentDB.Redis.Programの行45 。 C:\ Users \ barbers \ Desktop \ DocumentDBs \ DocumentDB.Redis \ Program.csのMain(String [] args):System.AppDomain._nExecuteAssembly(RuntimeAssemblyアセンブリ、String [] args)の 行System.AppDomainの .ExecuteAssembly(String assemblyFile、Evidence assemblySecurity、String [] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at Syste System.Threading.ExecutionContext.RunでSystem.Threading.ExecutionContext.Run(のExecutionContextのExecutionContext、ContextCallbackコールバック、オブジェクト状態、ブールignoreSyncCtx) でm.Threading.ThreadHelper.ThreadStart_Context(オブジェクトの状態) (のExecutionContextのExecutionContext、ContextCallbackコールバック、オブジェクトSystem.Threading.ThreadHelper.ThreadStartの状態) ()

私はその後、RedisのServiceStackの人はそれが彼らのユニットテストで取引を利用して作業している[OK]を考え、そのServiceStackクライアント(ServiceStackに付属しているよりも、私は「RedisTransactionTests」を編集しました-ServiceStack。Redisの-4add28a)私はここで

を使用しています例外を完全に取得するようだが、私は、私は、この編集したテストコード

[Test] 
[TestCase(true)] 
[TestCase(false)] 
public void TestUserTrans(bool shouldTransactionRollback) 
{ 
    int count = 0; 


    IRedisTransaction trans = Redis.CreateTransaction(); 

    try 
    { 
     trans.QueueCommand(r => 
     { 
      var redisUsers = r.GetTypedClient<User>(); 
      var sacha = new User { Id = redisUsers.GetNextSequence(), Name = "Sacha Barber" }; 
      redisUsers.Store(sacha); 
     }); 

     //commit or rollback based on incoming flag 
     if (shouldTransactionRollback) 
      trans.Rollback(); 
     else 
      trans.Commit(); 
    } 
    catch (Exception ex) 
    { 

    } 

    IList<User> users = Users(); 
    count = users.Count(); 
    Console.WriteLine(string.Format("TestUserTrans : There are currently {0}, Users", users.Count())); 
    if (shouldTransactionRollback) 
     Assert.That(count == 0); 
    else 
     Assert.That(count == 1); 

} 

を持っている「RedisTransactionTests」

public class User 
{ 
    public User() 
    { 
     this.BlogIds = new List<long>(); 
    } 

    public long Id { get; set; } 
    public string Name { get; set; } 
    public List<long> BlogIds { get; set; } 
} 

に追加するものです飲み込んだ。私がやっている何を地球上

間違っ

答えて

4

あなたが読んで、同じトランザクションの範囲内の結果を使用することはできません。 http://redis.io/topics/transactions

それが効果的に1回でRedisので送られて処理される単一化合物のコマンドで複数のコマンドをバッチ処理することで動作:

あなたはMULTI/EXECがどのように機能するかに必ずお読みください。

例では、redisUsers.GetNextSequence()で読み取りを行い、キューに入れられたトランザクション内の結果を使用しようとしています。あなたは、あなたが前にそれを読む必要があなたのキューに入れられたトランザクション内の変数を利用したい場合は、代わりに、これを行うことはできません。

var sacha = new User { 
    Id = Redis.As<User>().GetNextSequence(), Name = "Sacha Barber" }; 

trans.QueueCommand(r => r.As<User>().Store(sacha)); 

注:.As<T>()は、トランザクションのためにr.GetTypedClient<T>()

ための短い手であります読み取り時に整合性を確認するには、WATCHコマンドを発行して、トランザクションで使用するすべての変数を指定します。トランザクションが完了する前にこれらの変数のいずれかが変更されると、例外が発生し、キューに入れられた操作は実行されません。

+0

私は初心者でした。 これは私を分類しました。あなたが投稿したリンクを必ず読んでいます。どうもありがとう – sacha