From: antirez Date: Thu, 14 Apr 2011 11:31:14 +0000 (+0200) Subject: Merge remote branch 'pietern/unstable-zset' into unstable X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/7c0e1b53c4c4f646c788fcd09666e1c321c1d134?ds=inline;hp=-c Merge remote branch 'pietern/unstable-zset' into unstable --- 7c0e1b53c4c4f646c788fcd09666e1c321c1d134 diff --combined src/config.c index 48f90349,f6c6ad68..98fdb15d --- a/src/config.c +++ b/src/config.c @@@ -261,6 -261,10 +261,10 @@@ void loadServerConfig(char *filename) server.list_max_ziplist_value = memtoll(argv[1], NULL); } else if (!strcasecmp(argv[0],"set-max-intset-entries") && argc == 2) { server.set_max_intset_entries = memtoll(argv[1], NULL); + } else if (!strcasecmp(argv[0],"zset-max-ziplist-entries") && argc == 2) { + server.zset_max_ziplist_entries = memtoll(argv[1], NULL); + } else if (!strcasecmp(argv[0],"zset-max-ziplist-value") && argc == 2) { + server.zset_max_ziplist_value = memtoll(argv[1], NULL); } else if (!strcasecmp(argv[0],"rename-command") && argc == 3) { struct redisCommand *cmd = lookupCommand(argv[1]); int retval; @@@ -289,9 -293,6 +293,9 @@@ if ((server.cluster_enabled = yesnotoi(argv[1])) == -1) { err = "argument must be 'yes' or 'no'"; goto loaderr; } + } else if (!strcasecmp(argv[0],"cluster-config-file") && argc == 2) { + zfree(server.cluster.configfile); + server.cluster.configfile = zstrdup(argv[1]); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@@ -450,6 -451,12 +454,12 @@@ void configSetCommand(redisClient *c) } else if (!strcasecmp(c->argv[2]->ptr,"set-max-intset-entries")) { if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; server.set_max_intset_entries = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-entries")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; + server.zset_max_ziplist_entries = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-value")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; + server.zset_max_ziplist_value = ll; } else { addReplyErrorFormat(c,"Unsupported CONFIG parameter: %s", (char*)c->argv[2]->ptr); @@@ -601,6 -608,16 +611,16 @@@ void configGetCommand(redisClient *c) addReplyBulkLongLong(c,server.set_max_intset_entries); matches++; } + if (stringmatch(pattern,"zset-max-ziplist-entries",0)) { + addReplyBulkCString(c,"zset-max-ziplist-entries"); + addReplyBulkLongLong(c,server.zset_max_ziplist_entries); + matches++; + } + if (stringmatch(pattern,"zset-max-ziplist-value",0)) { + addReplyBulkCString(c,"zset-max-ziplist-value"); + addReplyBulkLongLong(c,server.zset_max_ziplist_value); + matches++; + } setDeferredMultiBulkLength(c,replylen,matches*2); } diff --combined src/redis.c index 9112adb5,3d0f5378..b0c3179e --- a/src/redis.c +++ b/src/redis.c @@@ -205,20 -205,14 +205,20 @@@ void redisLogRaw(int level, const char time_t now = time(NULL); FILE *fp; char buf[64]; + int rawmode = (level & REDIS_LOG_RAW); + level &= 0xff; /* clear flags */ if (level < server.verbosity) return; fp = (server.logfile == NULL) ? stdout : fopen(server.logfile,"a"); if (!fp) return; - strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now)); - fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg); + if (rawmode) { + fprintf(fp,"%s",msg); + } else { + strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now)); + fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg); + } fflush(fp); if (server.logfile) fclose(fp); @@@ -233,7 -227,7 +233,7 @@@ void redisLog(int level, const char *fm va_list ap; char msg[REDIS_MAX_LOGMSG_LEN]; - if (level < server.verbosity) return; + if ((level&0xff) < server.verbosity) return; va_start(ap, fmt); vsnprintf(msg, sizeof(msg), fmt, ap); @@@ -846,6 -840,8 +846,8 @@@ void initServerConfig() server.list_max_ziplist_entries = REDIS_LIST_MAX_ZIPLIST_ENTRIES; server.list_max_ziplist_value = REDIS_LIST_MAX_ZIPLIST_VALUE; server.set_max_intset_entries = REDIS_SET_MAX_INTSET_ENTRIES; + server.zset_max_ziplist_entries = REDIS_ZSET_MAX_ZIPLIST_ENTRIES; + server.zset_max_ziplist_value = REDIS_ZSET_MAX_ZIPLIST_VALUE; server.shutdown_asap = 0; server.cache_flush_delay = 0; server.cluster_enabled = 0; @@@ -1504,15 -1500,6 +1506,15 @@@ sds genRedisInfoString(char *section) } } + /* Clusetr */ + if (allsections || defsections || !strcasecmp(section,"cluster")) { + if (sections++) info = sdscat(info,"\r\n"); + info = sdscatprintf(info, + "# Cluster\r\n" + "cluster_enabled:%d\r\n", + server.cluster_enabled); + } + /* Key space */ if (allsections || defsections || !strcasecmp(section,"keyspace")) { if (sections++) info = sdscat(info,"\r\n"); @@@ -1721,23 -1708,6 +1723,23 @@@ void usage() exit(1); } +void redisAsciiArt(void) { +#include "asciilogo.h" + char *buf = zmalloc(1024*16); + + snprintf(buf,1024*16,ascii_logo, + REDIS_VERSION, + redisGitSHA1(), + strtol(redisGitDirty(),NULL,10) > 0, + (sizeof(long) == 8) ? "64" : "32", + server.cluster_enabled ? "cluster" : "stand alone", + server.port, + (long) getpid() + ); + redisLogRaw(REDIS_NOTICE|REDIS_LOG_RAW,buf); + zfree(buf); +} + int main(int argc, char **argv) { long long start; @@@ -1756,7 -1726,6 +1758,7 @@@ if (server.daemonize) daemonize(); initServer(); if (server.daemonize) createPidFile(); + redisAsciiArt(); redisLog(REDIS_NOTICE,"Server started, Redis version " REDIS_VERSION); #ifdef __linux__ linuxOvercommitMemoryWarning(); diff --combined src/redis.h index 7e3a8c8f,32dcc359..5506e365 --- a/src/redis.h +++ b/src/redis.h @@@ -71,10 -71,12 +71,12 @@@ #define REDIS_ZSET 3 #define REDIS_HASH 4 #define REDIS_VMPOINTER 8 + /* Object types only used for persistence in .rdb files */ #define REDIS_HASH_ZIPMAP 9 #define REDIS_LIST_ZIPLIST 10 #define REDIS_SET_INTSET 11 + #define REDIS_ZSET_ZIPLIST 12 /* Objects encoding. Some kind of objects like Strings and Hashes can be * internally represented in multiple ways. The 'encoding' field of the object @@@ -179,7 -181,6 +181,7 @@@ #define REDIS_VERBOSE 1 #define REDIS_NOTICE 2 #define REDIS_WARNING 3 +#define REDIS_LOG_RAW (1<<10) /* Modifier to log without timestamp */ /* Anti-warning macro... */ #define REDIS_NOTUSED(V) ((void) V) @@@ -198,6 -199,8 +200,8 @@@ #define REDIS_LIST_MAX_ZIPLIST_ENTRIES 512 #define REDIS_LIST_MAX_ZIPLIST_VALUE 64 #define REDIS_SET_MAX_INTSET_ENTRIES 512 + #define REDIS_ZSET_MAX_ZIPLIST_ENTRIES 128 + #define REDIS_ZSET_MAX_ZIPLIST_VALUE 64 /* Sets operations codes */ #define REDIS_OP_UNION 0 @@@ -589,6 -592,8 +593,8 @@@ struct redisServer size_t list_max_ziplist_entries; size_t list_max_ziplist_value; size_t set_max_intset_entries; + size_t zset_max_ziplist_entries; + size_t zset_max_ziplist_value; time_t unixtime; /* Unix time sampled every second. */ /* Virtual memory I/O threads stuff */ /* An I/O thread process an element taken from the io_jobs queue and @@@ -853,6 -858,7 +859,7 @@@ robj *createSetObject(void) robj *createIntsetObject(void); robj *createHashObject(void); robj *createZsetObject(void); + robj *createZsetZiplistObject(void); int getLongFromObjectOrReply(redisClient *c, robj *o, long *target, const char *msg); int checkType(redisClient *c, robj *o, int type); int getLongLongFromObjectOrReply(redisClient *c, robj *o, long long *target, const char *msg); @@@ -916,6 -922,12 +923,12 @@@ void backgroundRewriteDoneHandler(int e zskiplist *zslCreate(void); void zslFree(zskiplist *zsl); zskiplistNode *zslInsert(zskiplist *zsl, double score, robj *obj); + unsigned char *zzlInsert(unsigned char *zl, robj *ele, double score); + double zzlGetScore(unsigned char *sptr); + void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr); + void zzlPrev(unsigned char *zl, unsigned char **eptr, unsigned char **sptr); + unsigned int zsetLength(robj *zobj); + void zsetConvert(robj *zobj, int encoding); /* Core functions */ void freeMemoryIfNeeded(void); @@@ -1009,6 -1021,8 +1022,8 @@@ int stringmatchlen(const char *pattern int stringmatch(const char *pattern, const char *string, int nocase); long long memtoll(const char *p, int *err); int ll2string(char *s, size_t len, long long value); + int string2ll(char *s, size_t len, long long *value); + int d2string(char *s, size_t len, double value); int isStringRepresentableAsLong(sds s, long *longval); int isStringRepresentableAsLongLong(sds s, long long *longval); int isObjectRepresentableAsLongLong(robj *o, long long *llongval);