Skip to content

Commit

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

The `RemoveAsync` method is part of the `IRedisRepository<T>` interface in the `NetPlus.ServiceAbstractions.Cache.Redis` library. This method removes an object from the Redis cache asynchronously based on the specified key.

## Syntax

```csharp
public async Task<bool> RemoveAsync(string key)
```

## Parameters

- `key`: The unique identifier for the object in the Redis cache. This is a string.

## Returns

A task representing the asynchronous operation and containing a boolean indicating if the object was successfully removed.

## Example

```csharp
var repository = serviceProvider.GetService<IRedisRepository<MyClass>>();
bool success = await repository.RemoveAsync("myKey");
```

In this example, the object with the key "myKey" will be removed from the Redis cache. The `success` variable will be `true` if the object was successfully removed, and `false` otherwise.

## Remarks

> [!NOTE]
> The `RemoveAsync` method uses the `KeyDeleteAsync` method from the `IDatabase` interface provided by the StackExchange.Redis library to remove the value from Redis.
> [!TIP]
> If the key does not exist in the Redis cache, the `RemoveAsync` method will return `false`.
> [!WARNING]
> Be aware that the `RemoveAsync` 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 f650beb

Please sign in to comment.