Fixed a minor bug in GETSET, now the SET part is not performed if the GET fails because the key does not contain a string value

This commit is contained in:
antirez 2009-12-24 09:40:11 -05:00
parent 8fb13ce816
commit 322fc7d855
2 changed files with 11 additions and 3 deletions

1
TODO
View File

@ -42,6 +42,7 @@ BIG ONES:
* Specially encoded memory-saving integer sets.
* A command to export a JSON dump (there should be mostly working patch needing major reworking).
* Specially encoded sets of integers (this includes a big refactoring providing an higher level layer for Sets manipulation)
* ZRANK: http://docs.google.com/viewer?a=v&q=cache:tCQaP3ZeN4YJ:courses.csail.mit.edu/6.046/spring04/handouts/ps5-sol.pdf+skip+list+rank+operation+augmented&hl=en&pid=bl&srcid=ADGEEShXuNjTcZyXw_1cq9OaWpSXy3PprjXqVzmM-LE0ETFznLyrDXJKQ_mBPNT10R8ErkoiXD9JbMw_FaoHmOA4yoGVrA7tZWiy393JwfCwuewuP93sjbkzZ_gnEp83jYhPYjThaIzw&sig=AHIEtbRF0GkYCdYRFtTJBE69senXZwFY0w
SMALL ONES:

13
redis.c
View File

@ -27,7 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#define REDIS_VERSION "1.1.94"
#define REDIS_VERSION "1.1.95"
#include "fmacros.h"
#include "config.h"
@ -3018,24 +3018,31 @@ static void setnxCommand(redisClient *c) {
setGenericCommand(c,1);
}
static void getCommand(redisClient *c) {
static int getGenericCommand(redisClient *c) {
robj *o = lookupKeyRead(c->db,c->argv[1]);
if (o == NULL) {
addReply(c,shared.nullbulk);
return REDIS_OK;
} else {
if (o->type != REDIS_STRING) {
addReply(c,shared.wrongtypeerr);
return REDIS_ERR;
} else {
addReplyBulkLen(c,o);
addReply(c,o);
addReply(c,shared.crlf);
return REDIS_OK;
}
}
}
static void getCommand(redisClient *c) {
getGenericCommand(c);
}
static void getsetCommand(redisClient *c) {
getCommand(c);
if (getGenericCommand(c) == REDIS_ERR) return;
if (dictAdd(c->db->dict,c->argv[1],c->argv[2]) == DICT_ERR) {
dictReplace(c->db->dict,c->argv[1],c->argv[2]);
} else {