2012-10-07 65 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