Scroll to top

StackExchange.Redis : Scan


Curious Bot - December 1, 2018 - 0 comments

Basic scanning of all keys on server

// Connect to a target server using your ConnectionMultiplexer instance
IServer server = conn.GetServer("localhost", 6379);

// Write out each key in the server
foreach(var key in server.Keys()) {
Console.WriteLine(key);
}

Iterating using a cursor

// Connect to a target server using your ConnectionMultiplexer instance
IServer server = conn.GetServer("localhost", 6379);

var seq = server.Keys();
IScanningCursor scanningCursor = (IScanningCursor)seq;

// Use the cursor in some way...

Parameters

Parameter Details
database Redis database index to connect to
pattern Unsure
pageSize Number of items to return per page
cursor Unsure
pageOffset Number of pages to offset the results by
flags Unsure

Syntax

Parameter Details
database Redis database index to connect to
pattern Unsure
pageSize Number of items to return per page
cursor Unsure
pageOffset Number of pages to offset the results by
flags Unsure

Remarks

The Keys() call will select either the KEYS or SCAN command based on the version of the Redis server. Where possible it will prefer the usage of SCAN which returns an IEnumerable<RedisKey> and does not block. KEYS on the other hand will block when scanning the key space.

Related posts