Skip to content

Commit 01a7f7b

Browse files
DOC-6616 fixes following review
1 parent a1bf0e7 commit 01a7f7b

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

content/develop/use-cases/prefetch-cache/_index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ The following libraries and frameworks support Redis-backed prefetch caching:
9595
The following guides show how to build a simple Redis-backed prefetch cache in front of a primary store of reference data. Each guide includes a runnable interactive demo that pre-loads records on startup, runs a background sync worker that applies primary-store changes to Redis within milliseconds, and lets you watch the cache stay current as records are added, updated, and deleted on the source.
9696

9797
* [redis-py (Python)]({{< relref "/develop/use-cases/prefetch-cache/redis-py" >}})
98+
* [node-redis (Node.js)]({{< relref "/develop/use-cases/prefetch-cache/nodejs" >}})
99+
* [go-redis (Go)]({{< relref "/develop/use-cases/prefetch-cache/go" >}})
100+
* [Jedis (Java)]({{< relref "/develop/use-cases/prefetch-cache/java-jedis" >}})
101+
* [Lettuce (Java)]({{< relref "/develop/use-cases/prefetch-cache/java-lettuce" >}})
102+
* [StackExchange.Redis (C#)]({{< relref "/develop/use-cases/prefetch-cache/dotnet" >}})
103+
* [Predis (PHP)]({{< relref "/develop/use-cases/prefetch-cache/php" >}})
104+
* [redis-rb (Ruby)]({{< relref "/develop/use-cases/prefetch-cache/ruby" >}})
105+
* [redis-rs (Rust)]({{< relref "/develop/use-cases/prefetch-cache/rust" >}})

content/develop/use-cases/prefetch-cache/dotnet/PrefetchCache.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,11 @@ public List<string> Ids()
228228

229229
public long TtlRemaining(string entityId)
230230
{
231-
var ttl = _db.KeyTimeToLive(CacheKey(entityId));
232-
return ttl is null ? -1 : (long) ttl.Value.TotalSeconds;
231+
// Use Execute("TTL", ...) rather than KeyTimeToLive: the latter
232+
// returns `null` for BOTH a missing key and a key without a TTL,
233+
// collapsing the -2 and -1 sentinels. Execute returns the raw
234+
// integer so the demo UI can show the correct value in each case.
235+
return (long) _db.Execute("TTL", CacheKey(entityId));
233236
}
234237

235238
public Dictionary<string, object> Stats()

content/develop/use-cases/prefetch-cache/php/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ If your Redis server is running elsewhere, start the demo with the `PREFETCH_RED
290290

291291
### Get the source files
292292

293-
The demo consists of seven files. Download them from the [`php` source folder](https://github.com/redis/docs/tree/main/content/develop/use-cases/prefetch-cache/php) on GitHub, or grab them with `curl`:
293+
The demo consists of six files. Download them from the [`php` source folder](https://github.com/redis/docs/tree/main/content/develop/use-cases/prefetch-cache/php) on GitHub, or grab them with `curl`:
294294

295295
```bash
296296
mkdir prefetch-cache-demo && cd prefetch-cache-demo

content/develop/use-cases/prefetch-cache/rust/cache.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ impl PrefetchCache {
278278
let hit_rate_pct = if total == 0 {
279279
0.0
280280
} else {
281-
((1000 * hits / total) as f64) / 10.0
281+
// Round-half-up to 1 decimal in floating point. Earlier
282+
// `(1000 * hits / total) as f64 / 10.0` did integer division
283+
// and truncated, so 2/3 came out as 66.6 instead of 66.7.
284+
(1000.0 * hits as f64 / total as f64).round() / 10.0
282285
};
283286
let sync_lag_ms_avg = if sync_lag_samples == 0 {
284287
0.0

0 commit comments

Comments
 (0)