Here's the code:
import redis def deleteUser(userID): addToUnregistered = False for key in x.keys("user:"+str(userID)+":*"):#for each key associated with a user addToUnregistered = addToUnregistered or x.delete(key)#delete the key and 'or; the result of that delete against addToUnregistered if addToUnregistered: #if a key was deleted x.lpush("unregisteredUserIDs",str(userID)) #add the userID to the list of unregistered User Id's
A quick explanation. Redis is a NoSQL database. Based on some company requirements, all information that is associated with a given user will have "user:userIDNumber:" at the beginning of the data. So, a quick example might be "user:1:age". When a user gets deleted, we add his userID to a list of unregistered ID's.
So, I create a variable called addToUnregistered and set it to False. When redis deletes a key, redis returns True. So, I do a logical "or" against the output of deleting the key and addToUnregistered. This ensures that addToUnregistered is only true if I successfully deleted a key. If it's true, I add it to the unregisteredUserIDs list.
BUT SOMETHING WENT WRONG! If I try to delete a bad UserID, everything works perfectly, but if I try to delete a good one, only the first key gets deleted and the userID does get added to the unregistered list. Can Anyone spot my error?
The redis commands are correct.
Haha this spoiler doesn't hold the answer, but it does have some proof that I know the answer... just incase you guys thought I was trying to get you to do my job lol
This post has been edited by atraub: 06 August 2012 - 01:50 PM