Transients are not expiring as expected in simple custom plugin

Not clear about what exactly is wrong but few comments about things you are doing wrongish

  1. transients cache values up to a time so your random game can actually be totally pointless especially if a url is not being frequently fetched, since you use redis the value might expire as part of the memory cleanup when new values need to be added to it. In other words, the randomness in a way is already part of using a transient and your code might be pointless.

  2. An option name can be up to 64 characters, this means that for long urls you will end up with the same cached values for urls which starts with the same 64 (actually due to the transient prefix, even less) letters. Actually this might be a limitation on non redis implementation that save the transient to the DB, but I would just nut risk it – just use md5 or another hashing function in stead of escaping the URL.

  3. use a much better prefix for your transients, mod is way too generic and your code might colide with some other plugin.