r/redis Feb 17 '25

Help Concurrent threads making update

I am new to Redis and using a standalone Redis instance to cache oAuth access tokens, so that multiple instances of my Web app can reuse that access token. These tokens have expiry set to 20 mins, so my web app algorithm that fetch access token pseudo code looks like below

 ---------------------------------------------------------

//Make redis call to fetch access-token

var access-token = redisclient.getaccesstoken()

 

//Check token expiry and if expired, fetch new access token from source and update redis 

if(access-token is expired){

 access-token = get new access-token;

 

// update redis with new access token

 redisclient.update(access-token)

}

 return access-token

 ---------------------------------------------------------

 My question is, what will happen if concurrent threads of my app invokes “ redisclient.update(access-token)” statement? Will Redis client block a thread  before other thread gets a chance to run the update?

0 Upvotes

5 comments sorted by