Search code examples
c#redispaginationstackexchange.redis

how to get result with cursor and paging using ZSCAN command with stackexchange.redis library?


I am using stackexchange.redis. in that zscan is giving all matched value
I want to get exactly given page size result and next cursor for remaining values.

I have debugged its source code library in that i found that they are scanning entire source value until cursor became zero and provides all matched values.

so could we can get result as per cursor same as redis command Zscan.

here is my code snap

 using (ConnectionMultiplexer conn = ConnectionMultiplexer.Connect(conf))
 {
           var dbs = conn.GetDatabase();                         
           int currentpage = 0,pagesize=20;
           var scanresult = dbs.SortedSetScan("key", "an*", pagesize, 0, 0, CommandFlags.None);
 }

here I am getting all values of matching criteria instead of page size and next cursor.

so help out if any one has done it before


Solution

  • This is because of stack stackexchange.redis library code. its scanning as per enumerable method. so its not working same as redis command line.

    To solve this issue we have used another redis client library called csredis

    using (var redis = new RedisClient("yourhost"))
    {
        string ping = redis.Ping();
         var scanresult=redis.ZScan(key, cursor, pattern, pagesize);
    
    }
    

    As shown in above code we will get all dadta into "scanresult".