question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REDIS waited for Delete appears to not be immediately effective

See original GitHub issue

Environment:

  • Node.js Version: v14.19.3
  • Redis Server Version: redis-3.2.12-2.el7.x86_64
  • Node Redis Version: ^2.8.0
  • Platform: Centos 7

The code at issue runs every 5 minutes and about 7% of the time it would appear that the delete does not throw but is not effective since the key can still be obtained with a subsequent get.

I had thought that with this code the client and the server actions would be synchronous and therefore if the delete returned from the await then it must have been successful.

Any thoughts? - thanks.

Code at issue

` const redis = require(“./redis”); … await redis.setAsync(“HealthTestKey”, “HealthTestValue”);

const healthTestKey = await redis.getAsync("HealthTestKey");

if (healthTestKey !== "HealthTestValue") {
...
// not going here

} else {
  // Delete key value pair
  await redis.delAsync("HealthTestKey");
  const healthTestKey = await redis.getAsync("HealthTestKey");
  if (!healthTestKey) {
...
// not going here
  } else {
...
// goes in here around 7% of the time - suggests the delete was not immediately effective
  }
}

} catch (e) { … // does not go in here`

Client library code:

` const { promisify } = require(“util”);

const logger = require("./apiLogger");

const redis = require("redis");

require("dotenv").config();

const redisUrl =
  process.env.REDIS_PASSWORD && process.env.REDIS_HOST
    ? `redis://:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
    : undefined;
const redisClient = redis.createClient(redisUrl);

redisClient.on("error", async (e) => {
  const { recordInternalError } = require("./healthCheck");

  logger.error(`Failed to initialise REDIS Client: ${e.message} ${e.stack}`);

  await recordInternalError(
{
  email: "",
  entryPoint: "/services/redis"
},
e

); });

module.exports = Object.assign(redisClient, {
  getAsync: promisify(redisClient.get).bind(redisClient),

setAsync: async (key, value, flag, duration) => { if (!key.length || !value) { throw new Error( REDIS setAsync has missing arguments: key: ${key} value: ${value} ); } return new Promise((resolve, reject) => { try { if (flag !== undefined && duration !== undefined) { redisClient.set(key, value, flag, duration); } else { redisClient.set(key, value); } resolve(true); } catch (err) { reject(err); } }); }, delAsync: async (key) => { return new Promise((resolve, reject) => { redisClient.del(key, (err, result) => { if (err) { return reject(err); } return resolve(result); }); }); }, expireAsync: promisify(redisClient.expire).bind(redisClient) }); `

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
leibalecommented, Jul 7, 2022

This code dose not reproduce it:

import { createClient } from '@redis/client';
import { equal } from 'node:assert/strict';

const client = createClient();

client.on('error', err => console.error(err));

await client.connect();

for (let i = 0; i < 1_000_000; i++) {
  equal(
    await client.set('key', 'value'),
    'OK'
  );

  equal(
    await client.del('key'),
    1
  );

  equal(
    await client.get('key'),
    null
  );
}

Have you tried using the “MONITOR” command to check maybe there is a “SET” command from another client that gets executed in between the “DEL” and “GET” commands?

0reactions
derekmlrcommented, Jul 8, 2022

Huh, ran the same successfully. So hopefully it’s just a weird issue on my express flow that I can fix, but looking into it.

Thanks for the check!

Read more comments on GitHub >

github_iconTop Results From Across the Web

SHUTDOWN - Redis
Since Redis 7.0, the server waits for lagging replicas up to a configurable shutdown-timeout , by default 10 seconds, before shutting down. This...
Read more >
Alternatives to slow DEL large key - redis - Stack Overflow
I guess my main concern is blocking the client that needs to delete a key but does not care to wait for the...
Read more >
Investigating timeout exceptions in StackExchange.Redis for ...
Steps to investigate: · Upgrade the cache to a larger size so that you are not running up against memory limitations on the...
Read more >
Learn Redis the hard way (in production) - trivago tech blog
We tried to reproduce the issue in our pre-production environments. Sadly, we were not successful. We thought that those issues only appeared ......
Read more >
Understanding the Top 5 Redis Performance Metrics - Datadog
Using critical Redis metrics to troubleshoot performance issues ... will allow you to remove keys that have not been recently used regardless of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found