2012-10-07 104 views
1

我試圖找出如何做尋呼SS.Redis,我使用:ServiceStack的Redis如何實現分頁

var todos = RedisManager.ExecAs<Todo>(r => r.GetLatestFromRecentsList(skip,take)); 

返回0,但我敢肯定的數據庫不是空的,因爲r.GetAll()返回事物列表。什麼是正確的方法來做到這一點?


編輯:這裏是代碼:

public class ToDoRepository : IToDoRepository 
{ 

    public IRedisClientsManager RedisManager { get; set; } //Injected by IOC 

    public Todo GetById(long id) { 
     return RedisManager.ExecAs<Todo>(r => r.GetById(id)); 
    } 
    public IList<Todo> GetAll() { 
     return RedisManager.ExecAs<Todo>(r => r.GetAll()); 
    } 
    public IList<Todo> GetAll(int from, int to) { 
     var todos = RedisManager.ExecAs<Todo>(r => r.GetLatestFromRecentsList(from,to)); 
     return todos; 
    } 
    public Todo NewOrUpdate(Todo todo) { 
     RedisManager.ExecAs<Todo>(r => 
     { 
      if (todo.Id == default(long)) todo.Id = r.GetNextSequence(); //Get next id for new todos 
      r.Store(todo); //save new or update 
     }); 
     return todo; 
    } 
    public void DeleteById(long id) { 
     RedisManager.ExecAs<Todo>(r => r.DeleteById(id)); 
    } 
    public void DeleteAll() { 
     RedisManager.ExecAs<Todo>(r => r.DeleteAll()); 
    } 
} 

回答

2

由於我沒有看到任何代碼,我假設你沒有保持最近通話清單,當你添加的entites。這裏的測試用例GetLatestFromRecentsList

var redisAnswers = Redis.As<Answer>(); 

redisAnswers.StoreAll(q1Answers); 
q1Answers.ForEach(redisAnswers.AddToRecentsList); //Adds to the Recents List 

var latest3Answers = redisAnswers.GetLatestFromRecentsList(0, 3); 

var i = q1Answers.Count; 
var expectedAnswers = new List<Answer> 
{ 
    q1Answers[--i], q1Answers[--i], q1Answers[--i], 
}; 

Assert.That(expectedAnswers.EquivalentTo(latest3Answers)); 

Redis StackOverflow是使用最近通話列表功能,以顯示添加的最新問題的另一個例子。無論何時創建新問題,它都會通過調用AddToRecentsList來維護最近的問題列表。

+0

看起來像我不明白我使用的功能的含義。我們在哪裏可以獲得SS.Redis文檔來解釋SS Redis函數和數據如何進行結構化? – Tom

+0

有大量的文檔,首先是:http://www.servicestack.net/docs/category/Redis%20Client然後包含在http://stackoverflow.com/a/8919931/85785中的鏈接 - 然後看看單元測試如果仍然不確定。 – mythz

+0

我可以再次重申我的q ...當我使用r.Store(todo);我怎樣才能得到分頁的項目,但不要調用r.GetAll(); ...其次,我不確定什麼是RecentsList功能的用法。我只能猜測它可以訪問你剛剛使用的列表。如果我關閉redis服務器,我不能再以這種方式得到我的待辦事項列表。所以如果我想要一個分頁的待辦事項列表,調用最近的列表可能不能保證結果,我可能需要調用另一個函數來做到這一點,對嗎? – Tom