2013-04-13 1 views
1

트랜잭션 중에 해시에서 모든 항목을 가져 오는 방법은 무엇입니까? 올바른 유형의 onSuccessCallback이 표시되지 않습니다. 난 그냥 수동으로 직렬화 할 수있는 byte[][] 사고로 매핑했지만, 레디 스는Servicestack.redis 트랜잭션 및 해시

이 작업을 수행 할 수 어쨌든 그게 (값의 잘못된 종류를 들고 키에 대한 운영)에 대해 불평?

var hashValues 
using (var trans = client.CreateTransaction()) 
{ 
    trans.QueueCommand(c => hashValues=c.GetAllEntriesFromHash("some key")); 
    trans.Remove("some key"); 
    trans.Commit(); 
} 

return hashValues; 

그래서 내가하려는 것은 해시에서 모든 값을 가져온 다음 해시를 제거하는 원자 적 연산입니다.

답변

2

가장 좋은 방법은 다음과 같습니다.을 기반으로하면 Redis의 반환 값이 fieldname 다음에 오는 것처럼 보입니다. ServiceStack.Redis가 dictionary mapping을 처리합니다. 거래 내에서 모든 것을 작동 시키려면 'Redis'수준에서 일해야한다고 생각합니다.

byte[][] hashAll = null; 

var client = new BasicRedisClientManager("localhost:6379"); 
using (var trans = client.GetClient().CreateTransaction()) 
{ 
    trans.QueueCommand(r => ((RedisNativeClient)r).HGetAll("meHashKey"), result => hashAll = result);   
    trans.QueueCommand(r => r.Remove("meHashKey")); 
    trans.Commit(); 
} 

//variable map will hold the Hash/Dictionary<string, string>/Key-Value Pairings 
var map = new Dictionary<string, string>(); 
for (var i = 0; i < hashAll.Length; i += 2) 
{ 
    var key = hashAll[i].FromUtf8Bytes(); 
    map[key] = hashAll[i + 1].FromUtf8Bytes(); 
} 
+0

이 작업을 수행하려고했지만 'RedisNaticClient'로 전송하지 않았습니다. 나는 집에 도착하자마자 이걸 시험해 볼거야. 감사! – Joe