Skip to content

Commit

Permalink
Create searchkeysasync.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gsilvamartin authored Feb 25, 2024
1 parent b8a9df0 commit 16fbb98
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/docs/serviceabstractions/cache/redis/searchkeysasync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SearchKeysAsync Method

The `SearchKeysAsync` method is part of the `IRedisRepository<T>` interface in the `NetPlus.ServiceAbstractions.Cache.Redis` library. This method searches for keys in the Redis cache asynchronously based on a pattern.

## Syntax

```csharp
public Task<IEnumerable<string>> SearchKeysAsync(string pattern)
```

## Parameters

- `pattern`: The pattern to match keys against in the Redis cache. This is a string.

## Returns

A task representing the asynchronous operation and containing an enumerable of strings representing the keys that match the pattern.

## Example

```csharp
var repository = serviceProvider.GetService<IRedisRepository<MyClass>>();
IEnumerable<string> matchingKeys = await repository.SearchKeysAsync("myKey*");
```

In this example, `matchingKeys` will contain all keys in the Redis cache that start with "myKey".

## Remarks

> [!NOTE]
> The `SearchKeysAsync` method uses the `Keys` method from the `IServer` interface provided by the StackExchange.Redis library to search for keys in Redis.
> [!TIP]
> If the `pattern` parameter is not provided or is null, the `SearchKeysAsync` method will return all keys in the Redis cache.
> [!WARNING]
> Be aware that the `SearchKeysAsync` method will throw an exception if the Redis server is not available or if there is a network issue. Make sure to handle these exceptions in your code.

0 comments on commit 16fbb98

Please sign in to comment.