What is the procedure for removing an item from a Redis list object?

Currently, I am facing an issue with deleting specific data from Redis while working on a caching scenario for MongoDB. Despite trying the Lrem() method, it did not yield the desired result. Any guidance on how to successfully delete specific object data from Redis would be greatly appreciated.

const deleteComment = async (req, res) => {
  let key = `Comments/${req.query.postId}`;

  try {
    const deleteValue = await Comment.findOneAndDelete({
      _id: req.params.id,
      $or: [{ writer: req.user.id }, { authorId: req.user.id }],
    })
      .populate("responseTo", "writer")
      .populate("postId", "authorId")
      .populate("writer");

    const jsonData = JSON.stringify(deleteValue);
    await client.lRem(key, 0, jsonData);

    res
      .status(200)
      .json({ success: true, message: "Comment Deleted", ıtem: deleteValue });
  } catch (err) {
    res.status(500).json({ message: err });
  }
};

Answer №1

If you have control over the code inserting the JSON, ensure they produce identical strings for LREM to work properly. Consider altering your data structure or a combination of structures if needed.

One suggestion is to store JSON as a String, while the List can hold keys to these Strings. When deleting a comment, utilize LREM to remove it from the List, and either UNLINK or DEL to erase the JSON. The List maintains an ordered index of comments, with each comment stored in a String.

Alternatively, consider using RedisJSON to store a JSON document containing an array of comments for organized data. This will enable you to delete specific comments using JSON.DEL and JSONPath.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Add the hue value from Hue into the Chromajs HSL state value

My objective is to dynamically change the background color of a div based on user input. I plan to assign the user's input as the value of the state key hue, and then set another state key called color to hold the HSL representation of the hue using C ...

Maximizing the potential of $urlRouterProvider.otherwise in angular js

I am encountering an issue with redirecting to the login screen when there is no UABGlobalAdminId in my storage. I have tried using $urlRouterProvider.otherwise but it doesn't seem to be functioning properly. When I attempt to debug, the console does ...

Incorporate a reduction in cookies in the session using Node.js

When using Express with cookieSession, I am seeking a way to include additional information in the session without it getting stored in the cookie. I understand that only the sessionId needs to be maintained on the client side, but I am unsure how to add ...

IIS6 hosting a Node.js server

In my corporate environment, we are restricted to using IIS6 and cannot upgrade. I would like to run node.js within IIS6 but have found that iisnode is only compatible with IIS7. Is there an ISAPI redirect solution available that can facilitate the conne ...

Disable infinite scrolling when a checkbox is clicked

Currently, I have implemented infinite scrolling on a table and it is functioning properly. <tbody infinite-scroll-disabled="myModule.isScrollingDisabled()" infinite-scroll="myModule.nextPage()" infinate-scroll-immediate-check="false" infinite-scroll-d ...

HTML/CSS: Creating Dynamic Button Animations

My code has a few issues that I am looking to fix: One problem is the sudden color change that occurs when the submit button is clicked. It seems like a glitchy animation, and I want to remove it. Right after clicking the submit button, there is an abru ...

Why isn't my SCO considered complete?

My SCO is very basic, with an empty html page. I am utilizing the pipwerks scorm api wrapper in Chrome dev tools to establish a connection to the LMS, set cmi.completion_status to "completed", and cmi.success_status to "failed" (as outlined in the scorm ru ...

Why is the jQuery ajax file uploading feature failing to function properly in the IE9 standard mode?

My file upload function works well in browsers like Chrome and IE10, but encountered an issue when tested on IE9. The Action controller reported that Request.Files were returning files with '0' length. I'm unsure if this problem is related ...

ng-select search functionality failing to display any matches

Currently, I am encountering an issue with the ng-select functionality in my Angular CLI version 11.2.8 project. Despite using ng-select version 7.3 and ensuring compatibility with the Angular CLI version, the search functionality within the select eleme ...

What are the steps to containerize my Node.js Express app running on an Amazon Linux AMI using Docker?

1. The technology stack I am using for the application includes expressjs, nodejs, mongoDB, redisDB, and s3 for storage. 2. The API is hosted on a Linux AMI. 3. I am in the process of creating a docker container image for my application. ...

Prevent the page from refreshing when a row is updated using jQuery AJAX

My data is successfully updated and displayed on the table in the browser with the updated row. The issue arises when the page reloads after the update. I am using Ajax jQuery to update my row. Please advise me on how to prevent the page from refreshing ...

update the state of the array containing objects with a new value

Here is a piece of code that I am working on: const [state, setState] = useState( [{id: 1, key:""}, {id: 2, key:""}, {id: 3, key:""}] ) I am trying to update the "key" state in my code. I'm a bit confused at t ...

Using Reactjs to automatically populate text into a React-Select Input field

I have implemented react-select in my project. Sometimes, I encounter the need to update my react-select input field without directly interacting with it (such as injecting text into it). However, I am unable to find a proper way to achieve this based on ...

Challenges encountered while using the FileReader to select files in HTML5

I am currently in the process of developing a video preview script where I aim to have one function that covers both drag and drop operations as well as files selected by an input type="file" element. Below is the core function: function FileHandler(files ...

Stop the recurrence of multiple clicks by incorporating a Bootstrap modal popup confirmation

$('button[name="remove_levels"]').on('click', function (e) { var $form = $(this).closest('form'); e.preventDefault(); $('#confirm').modal({ backdrop: 'static', ...

Does Vue have its own equivalent of Angular's UI-Router?

Does Vue have a router similar to Angular's ui-router? Which router is recommended for Vue? ...

Ways to link ajax jQuery response to C# variable

I'm a beginner in C#, JS, jQuery, and more. Currently, I am working on a cinema website project for school using ASP.NET and C#. I have reached a point where I feel like I am close to solving the issue, but I can't quite figure it out. What is t ...

Creating enduring designs in Next.js

I've been diving into this amazing article and I'm puzzling over the implementation of persistence in Option 4. It seems like you would need to redefine the .getLayout method for each page. I'm uncertain about how nesting logic is handled fo ...

Link-defying button

I'm developing a website with a homepage that serves as an entry point to the rest of the site (it welcomes the user and allows them to click anywhere to access the main website). The following code accomplishes this: <template> <div onc ...

Error: The 'book' property is undefined and cannot be read in the BookDetails.render function

I am currently working on retrieving data from renderList and implementing it in render(). Upon using console.log this.renderList() https://i.stack.imgur.com/IwOzw.png The retrieved data is displayed above. While working on the render(), I attempted ...