Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004

    Unanswered: use mysql as a queue

    I want to find the best method to use mysql as a queue. So what I would want to do with existing mysql functions, add entries to the table at the back(ok that already happens on insert) then I want to read the first item easily, not have to put all the entrees into an array and just read the first. then delete the first entry easily.

    Any help is appreciated.


  2. #2
    Join Date
    Apr 2004
    If you have an AUTO_INCREMENT column, the last inserted row will have the highest id and the first inserted will have the lowest.

    When you want to remove an element from the queue, do ("ai_col" = the name of the AUTO_INCREMENT column)
    SELECT ... FROM tab WHERE id=MIN(ai_col);
    DELETE FROM tab WHERE id=MIN(ai_col);
    If there are many clients accessing the "queue" at the same time, use some locking mechanism to avoid race conditions and other weird stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts