node.js - node redis zadd key error -


I try to reset sort command to zadd But when I run this script, throw error:

  var ts = Math.round (date.now () / 1000), key = 'usr ::' + dest.ID + ':: Msgs', id = uuid.v1 (); Var notify = {msg: response.msg, from: response.from? Response.from: Empty, type: response.type? Response.type: null, date: ts, read: 0} client.zadd (key, ts, JSON.stringify (notified), function (fault, response) {if (mistake) mistake;  

Is there any confusion with this code?

By the way : What do I try to do? Notification / Inbox system ... better way to protect me from asking For example you will help and at the end you will not: (

Error: Error operation against wrong key type key

I would say that the key is already present in Redis and it is not a sorted set. Try to see if you already have usr: Id :: msgs entries in Redis, and Check their type.

Update:

If you keep only one sort set, then it is not really possible to update the entry, because Entry data used as the value of sorted and sorted items

You have several solutions:

1) You can read and remove items, Deserialize, change the status of the read, re-order, Sort Add items again in the set it can be done with a roundtrip if necessary by using server-side luja script.

2) You can split your data model into several objects: place a sorting setting timestamp and message ID, and use a hash object per message ID to store the properties of each message It is easy to update the message reading status (HMET).

3) You can also have two sorted sets (one for reading messages, one for unread messages) changing the status of the message will include removing the item from one set, and Add it to the other.

The best option for solutions is probably depending on your data access pattern.


Comments