Scan

Other topics

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.

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...

Syntax:

  • public IEnumerable<RedisKey> Keys(int database = 0, RedisValue pattern = default(RedisValue), int pageSize = CursorUtils.DefaultPageSize, long cursor = CursorUtils.Origin, int pageOffset = 0, CommandFlags flags = CommandFlags.None)

Parameters:

ParameterDetails
databaseRedis database index to connect to
patternUnsure
pageSizeNumber of items to return per page
cursorUnsure
pageOffsetNumber of pages to offset the results by
flagsUnsure

Contributors

Topic Id: 66

Example Ids: 297,298

This site is not affiliated with any of the contributors.