the param oagesize of SortedSetScan can not work

566 Views Asked by At

I'm using SortedSetScan to filter some data,my code is below:

db.SortedSetScan("SR.Cache.APP:Termial1", "A*", 50, CommandFlags.None);

but the pagesize is always not work,the result count always be all. What's wrong about my code? or is it a bug?

may anybody can help me,thx!

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, the result of that is always "all". The page size simply impacts the number of round-trips, versus the amount of data each call, when issuing the underlying ZSCAN command. The IEnumerable<T>, however, is lazy, etc, so if you only want the first 50 items, use:

db.SortedSetScan(...).Take(50)

instead, which will perform whatever operations it needs in order to get 50 items. Tweaking the page size simply changes how many operations are needed. It would be incorrect to think "I'll make the page size 50 so it only takes one operation" - it doesn't work like that; redis *SCAN commands can return empty pages, or pages with one or two items on, regardless of the page size. The page size is more a "how many things to look at before giving up for this iteration" guidance fore redis. This is described more fully on the redis SCAN documentation - in particular, read what it says about "The COUNT option".

Note that the sequence obtained from all of the SE.Redis scanning operations can be resumed at a later point by casting the IEnumerable<T> or IEnumerator<T> to an IScanningCursor, and obtaining the cursor details to supply as parameters.

You might also want to think whether the "range" methods are more appropriate (note: they don't allow pattern filters).