Is there any way to update value in Redis?

Viewed 4353

I use Redis Desktop Manager in windows 10 for caching in ASP.Net Core 3.1 by StackExchange.Redis library.

Except delete and then again add new Key-Value in Redis, is there any way for updating value by key?

3 Answers

You can just do set <key> <value> again and the value will be overwrite.

  using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(""))
    {
       IDatabase db = redis.GetDatabase();
       string age = "11";
       db.StringSet("age", age);
    }

you want to update "age" 25,you can reuse db.StringSet("age", "25");

 var content = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(dto));
 await _cache.SetAsync("Key", content);

dto is the value sent by Action

Related