Remove/Delete all/one item from StackExchange.Redis cache

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Remove/Delete all/one item from StackExchange.Redis cache

Message par Clippy »

Remove/Delete all/one item from StackExchange.Redis cache
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Remove/Delete all/one item from StackExchange.Redis cache

Message par Clippy »

To remove a single item:

```
_cache.KeyDelete(key);

```

To remove *all* involves the `FLUSHDB` or `FLUSHALL` redis command; both are available in StackExchange.Redis; but, [for reasons discussed here](https://stackexchange.github.io/StackExchange.Redis/KeysScan.html), they are not on the `IDatabase` API (because: they affect servers, not logical databases).

As per the "So how do I use them?" on that page:

```
server.FlushDatabase(); // to wipe a single database, 0 by default
server.FlushAllDatabases(); // to wipe all databases

```

(quite possibly after using `GetEndpoints()` on the multiplexer)
Répondre

Revenir à « Azure Infrastructure »