Commit af4e866d authored by antirez's avatar antirez
Browse files

Merged with split

parents b8b8501d 0f49d6b0
...@@ -12,7 +12,7 @@ mkrelease.sh ...@@ -12,7 +12,7 @@ mkrelease.sh
release release
myredis.conf myredis.conf
misc/* misc/*
release.h src/release.h
appendonly.aof appendonly.aof
SHORT_TERM_TODO SHORT_TERM_TODO
redis.conf.* redis.conf.*
2010-07-01 gitignore modified (antirez)
2010-06-22 redis.c split into many different C files. (antirez)
2010-06-16 more pub/sub tests (Pieter Noordhuis)
2010-06-15 initial basic pub/sub tests (Pieter Noordhuis)
2010-06-15 fix BLPOP/BRPOP to use the wrapped function for list length (Pieter Noordhuis)
2010-06-15 tests for BLPOP/BRPOP via an option in the tcl client that defers reading the reply (Pieter Noordhuis)
2010-06-14 TODO updated (antirez)
2010-06-14 Merge branch 'ltrim-tests' of git://github.com/pietern/redis (antirez)
2010-06-14 rename "list" to "linkedlist" to be more verbose (Pieter Noordhuis)
2010-06-14 allow running the test suite against an external Redis instance, without auto spawning (antirez)
2010-06-14 change ltrim tests to cover all min/max cases and add stronger stresser (Pieter Noordhuis)
2010-06-13 Fixed deps in makefile and mkreleasehdr.sh script to really take advantage of the new trick to avoid recompilation of redis.c on git sha1 or dirty status change (antirez)
2010-06-13 hopefully faster recompiling with a trick (antirez)
2010-06-13 fixed a bug in rdbLoadObject abount specially encoded objects (antirez)
2010-06-13 use raw strings when loading a hash from the rdb into a zipmap (Pieter Noordhuis)
2010-06-12 Merge branch 'expire' of git://github.com/pietern/redis (antirez)
2010-06-11 Merge branch 'lists' of git://github.com/pietern/redis (antirez)
2010-06-11 LPUSHX, RPUSHX, LINSERT only work on non-empty lists, so there are no clients waiting for a push (Pieter Noordhuis)
2010-06-11 make LINSERT return -1 when the value could not be inserted (Pieter Noordhuis)
2010-06-11 check if the list encoding needs to be changed on LPUSHX, RPUSHX, LINSERT (Pieter Noordhuis)
2010-06-11 make sure the value to insert is string encoded (Pieter Noordhuis)
2010-06-11 rename vars, move arguments, add comments (Pieter Noordhuis)
2010-06-11 always iterate from head to tail on LINSERT (Pieter Noordhuis)
2010-06-11 use REDIS_TAIL to insert AFTER an entry and REDIS_HEAD to insert BEFORE an entry (Pieter Noordhuis)
2010-06-11 move listTypeInsert to be grouped with other wrapper functions (Pieter Noordhuis)
2010-06-11 squashed merge from robey/twitter3: LINSERT BEFORE|AFTER, LPUSHX, RPUSHX (Pieter Noordhuis)
2010-06-09 remove pop function and the sds dependency; can be implemented using get+delete (Pieter Noordhuis)
2010-06-07 compute swappability for ziplist encoded lists (Pieter Noordhuis)
2010-06-07 reuse the sds from the main dictionary in the expiration dictionary (Pieter Noordhuis)
2010-06-07 TODO updated (antirez)
2010-06-07 encode integers while loading an hash (antirez)
2010-06-05 Merge branch 'lists' of git://github.com/pietern/redis (antirez)
2010-06-05 fixed two leaks for the dual encoded lists (Pieter Noordhuis)
2010-06-04 TODO updated (antirez)
2010-06-04 DISCSARD now unwatches all keys, as it should (antirez)
2010-06-04 generated tests for different encodings to avoid test code duplication (Pieter Noordhuis)
2010-06-04 refactor list tests to test both encodings; implemented assert functions (Pieter Noordhuis)
2010-06-04 renamed hash wrapper functions to match wrapper function naming convention: "<type>Type<func>" (Pieter Noordhuis)
2010-06-04 Merge branch 'lists' of git://github.com/pietern/redis (antirez)
2010-06-04 Merge branch 'smallkeys' (antirez)
2010-06-04 safety assert in listTypeNext (Pieter Noordhuis)
2010-06-04 renamed list wrapper functions to be more verbose (Pieter Noordhuis)
2010-06-04 add thresholds for converting a ziplist to a real list (Pieter Noordhuis)
2010-06-04 merge antirez/smallkeys (Pieter Noordhuis)
2010-06-03 test restored (antirez)
2010-06-03 memory leak introduced in the latest big changes fixed (antirez)
2010-06-03 Fixed VM bugs introduced with the top level keys as sds strings changes (antirez)
2010-06-03 top level keys are no longer redis objects but sds strings. There are still a few bugs to fix when VM is enabled (antirez)
2010-06-03 update Makefile to include ziplist.o (Pieter Noordhuis)
2010-06-03 use ziplists in SORT STORE until the thresholds are determined (Pieter Noordhuis)
2010-06-03 Merge branch 'testsuite' of git://github.com/pietern/redis (antirez)
2010-06-03 Merge branch 'testsuite' of git://github.com/pietern/redis into smallkeys (antirez)
2010-06-03 tag memory leak check on kill server as "leaks" (Pieter Noordhuis)
2010-06-03 tag test with sleep() as slow (Pieter Noordhuis)
2010-06-03 make sure the config it returned when called without code (Pieter Noordhuis)
2010-06-03 tag more slow tests (Pieter Noordhuis)
2010-06-03 change how arguments are passed from the AOF tests (Pieter Noordhuis)
2010-06-03 scope res variable outside test (Pieter Noordhuis)
2010-06-02 tags for existing tests (Pieter Noordhuis)
2010-06-02 pass tags to filter and match via arguments (Pieter Noordhuis)
2010-06-02 basic support to tag tests (Pieter Noordhuis)
2010-06-02 changed how server.tcl accepts options to support more directives without requiring more arguments to the proc (Pieter Noordhuis)
2010-06-02 removed obsolete code (Pieter Noordhuis)
2010-06-02 catch exceptions in the server proc, to be able to kill the entire chain of running servers (Pieter Noordhuis)
2010-06-02 Merge branch 'master' into smallkeys (antirez)
2010-06-02 smarter swapout policy on AOF too (antirez)
2010-06-02 better swapout policy while loading RDB file (antirez)
2010-06-02 minor code comment change (antirez)
2010-06-01 use integer types from stdint.h to be more verbose on the size in bytes of encoded elements. update list length to use 2 bytes instead of 1. (Pieter Noordhuis)
2010-06-01 added stress test for heavy i/o in ziplists (Pieter Noordhuis)
2010-06-01 fix signedness errors in ziplist testing code (Pieter Noordhuis)
2010-06-01 minor code movements and free object pull restored to 1 million (antirez)
2010-06-01 TODO updated with syslog plans for 2.2 (antirez)
2010-06-01 Debug message was printing stuff that are sometimes not initialized/valid (antirez)
2010-06-01 Merge branch 'smallkeys' of github.com:antirez/redis into smallkeys (antirez)
2010-06-01 fixed a few comments (antirez)
2010-06-01 fixed bugs introduced in the rewrite of the new VM engine (antirez)
2010-05-31 support rewriting the AOF with dual list encoding (Pieter Noordhuis)
2010-05-31 small refactor of fwrite* commands for AOF rewrite to allow writing a bulk long long (Pieter Noordhuis)
2010-05-31 use list wrapper functions in computing the dataset digest (Pieter Noordhuis)
2010-05-31 ziplistNext should work as expected when called with a pointer to ZIP_END (Pieter Noordhuis)
2010-05-31 update SORT to work with the dual list encoding (Pieter Noordhuis)
2010-05-31 function to create a new ziplist encoded list (Pieter Noordhuis)
2010-05-31 fixed missing incrRefCount (antirez)
2010-05-31 support rdb saving/loading with dual list encoding (Pieter Noordhuis)
2010-05-31 fixed signedness and disambiguate variable names (Pieter Noordhuis)
2010-05-31 added rdb save function to directly save long long values (Pieter Noordhuis)
2010-05-31 update RPOPLPUSH to support dual encoding (Pieter Noordhuis)
2010-05-31 update list iteration semantic to work as expected (i.e. "while(lNext(..))") (Pieter Noordhuis)
2010-05-31 ziplistDelete no longer needs a direction now ziplistPrev is fixed (Pieter Noordhuis)
2010-05-31 ziplistPrev should return the tail when the argument is ZIP_END (Pieter Noordhuis)
2010-05-31 first step of VM rewrite. blocking VM tests passing, more work needed in the async side (antirez)
2010-05-31 Merge branch 'no-appendfsync-on-rewrite' (antirez)
2010-05-30 fix LREM to remove *all* occurances when a zero argument is given (Pieter Noordhuis)
2010-05-30 fixed LINDEX to always return bulk response (Pieter Noordhuis)
2010-05-30 the tail offset must be an integer pointer to hold a 32-bit offset (Pieter Noordhuis)
2010-05-30 update LREM to support dual encoding via extra iteration primitives (Pieter Noordhuis)
2010-05-30 support dual encoding in LTRIM (Pieter Noordhuis)
2010-05-30 update LRANGE to use basic iteration code to support dual encoding (Pieter Noordhuis)
2010-05-30 inline support for dual encoding in the LINDEX and LSET commands (Pieter Noordhuis)
2010-05-30 generic pop and length function for ziplist encoding (Pieter Noordhuis)
2010-05-30 generic push function that supports the dual encoding (Pieter Noordhuis)
2010-05-30 change delete function to accept a direction argument, so "p" can be properly updated (Pieter Noordhuis)
2010-05-30 expose extra functionality from ziplist.c (Pieter Noordhuis)
2010-05-30 code style consistency fixes (Pieter Noordhuis)
2010-05-29 ziplistIndex now accepts negative indices (Pieter Noordhuis)
2010-05-29 fix compile warnings (Pieter Noordhuis)
2010-05-29 use simpler encoding for the length of the previous entry (Pieter Noordhuis)
2010-05-29 replace functions to get pointers to head and tail by macros (Pieter Noordhuis)
2010-05-29 function to insert an element at an arbitrary position in the list (Pieter Noordhuis)
2010-05-29 extract a generic delete function that can be used in pop and delete(range) (Pieter Noordhuis)
2010-05-29 use the entry struct in zipRawEntryLength (Pieter Noordhuis)
2010-05-29 rename argument names to s* to disambiguate from e* (Pieter Noordhuis)
2010-05-29 change ziplistRepr to use the entry struct (Pieter Noordhuis)
2010-05-29 modify compare function to check if the encoding is equal before comparing (Pieter Noordhuis)
2010-05-29 use a struct to retrieve all details for an entry (Pieter Noordhuis)
2010-05-29 initial implementation for making the ziplist doubly linked (Pieter Noordhuis)
2010-05-29 fix some warnings (Pieter Noordhuis)
2010-05-29 add function to retrieve ziplist size in bytes (Pieter Noordhuis)
2010-05-22 fix compare function of ziplist to only load integer from ziplist when it is encoded as integer (Pieter Noordhuis)
2010-05-22 add function to retrieve length of ziplist (Pieter Noordhuis)
2010-05-22 re-introduce ZIP_BIGLEN for clarity (Pieter Noordhuis)
2010-05-22 added header ziplist.h (Pieter Noordhuis)
2010-05-22 code to compare strings with entries in ziplist, regardless of their encoding (Pieter Noordhuis)
2010-05-22 updated iteration code to work well with different encodings (Pieter Noordhuis)
2010-05-22 move code from zip.c to ziplist.c (Pieter Noordhuis)
2010-05-22 partial revert of c80df5 because ziplist functions are starting to divert too much from zipmap functions (Pieter Noordhuis)
2010-05-22 initial work for integer encoding in ziplists (Pieter Noordhuis)
2010-05-22 move length housekeeping to a macro (Pieter Noordhuis)
2010-05-21 allow entries to be deleted in place when iterating over a ziplist (Pieter Noordhuis)
2010-05-21 allow pointer to be stored to current element when iterating over ziplist (Pieter Noordhuis)
2010-05-21 rename ziplistDelete to ziplistDeleteRange (Pieter Noordhuis)
2010-05-21 code to delete an inner range from the ziplist (Pieter Noordhuis)
2010-05-21 check if *value is non-NULL before setting it (Pieter Noordhuis)
2010-05-21 change iteration code to avoid allocating a new sds for each traversed entry (Pieter Noordhuis)
2010-05-21 code to iterate over a ziplist (Pieter Noordhuis)
2010-05-21 implementation for a ziplist with push and pop support (Pieter Noordhuis)
2010-05-21 extracted general methods to zip.c for reuse in other zip* structures (Pieter Noordhuis)
2010-05-28 command table size calculated with sizeof (antirez)
2010-05-28 use qsort and bsearch to lookup commands in O(log(N)) instead of O(N) (Pieter Noordhuis)
2010-05-28 Merge branch 'cli-stdin' of git://github.com/pietern/redis (antirez)
2010-05-28 Fixed ZINCR Nan bugs leading to server crash and added tests (antirez)
2010-05-28 redis.conf new features the new option, a minor typo preventing the compilation fixed (antirez)
2010-05-28 don't fsync after a rewrite if appendfsync is set to no. use aof_fsycn instead of fsync where appropriate (antirez)
2010-05-28 added new option no-appendfsync-on-rewrite to avoid blocking on fsync() in the main thread while a background process is doing big I/O (antirez)
2010-05-28 Added Git sha1 and dirty status in redis-server -v output (antirez)
2010-05-28 changed the message in the Makefile with the new command like to run the test suite (antirez)
2010-05-27 Fixed typo. (Vincent Palmer)
2010-05-27 new multi/exec tests (antirez)
2010-05-26 build command outside while loop (Pieter Noordhuis)
2010-05-26 require the flag "-c" to be used for redis-cli to read the last argument from stdin (Pieter Noordhuis)
2010-05-26 Merge branch 'master' into nested-multi (antirez)
2010-05-26 Fix EXEC bug that was leaving the client in dirty status when used with WATCH (antirez)
2010-05-26 raise error on nested MULTI and WATCH inside multi (antirez)
2010-05-25 allow regular sets to be passed to zunionstore/zinterstore (Pieter Noordhuis)
2010-05-25 Version is now 2.1.1 (antirez)
2010-05-25 RENAME is now WATCH-aware (antirez)
2010-05-25 TODO updated (antirez)
2010-05-25 WATCH is now able to detect keys removed by FLUSHALL and FLUSHDB (antirez)
2010-05-25 WATCH tests (antirez)
2010-05-25 minor bug fixed in WATCH (antirez)
2010-05-25 WATCH for MULTI/EXEC (CAS alike concurrency) (antirez)
2010-05-25 gitignore updated (antirez)
2010-05-21 Master is now already unfreezed, unstable, and ready to hacking sessions! (antirez)
2010-05-21 Merge branch 'solaris' of git://github.com/pietern/redis (antirez)
2010-05-21 Changelog updated (antirez)
2010-05-21 redis version is now 1.3.14 (aka 2.0.0 RC1) (antirez) 2010-05-21 redis version is now 1.3.14 (aka 2.0.0 RC1) (antirez)
2010-05-21 html doc updated (antirez) 2010-05-21 html doc updated (antirez)
2010-05-21 by default test with valgrind does not show full leak info (antirez) 2010-05-21 by default test with valgrind does not show full leak info (antirez)
2010-05-21 minor fix for the skiplist code, resulting in a false positive with valgrind, and in general into a useless small allocation (antirez) 2010-05-21 minor fix for the skiplist code, resulting in a false positive with valgrind, and in general into a useless small allocation (antirez)
2010-05-21 Merge branch 'master' of git@github.com:antirez/redis (antirez) 2010-05-21 Merge branch 'master' of git@github.com:antirez/redis (antirez)
2010-05-21 tests suite initial support for valgrind, fixed the old test suite until the new one is able to target a specific host/port (antirez) 2010-05-21 tests suite initial support for valgrind, fixed the old test suite until the new one is able to target a specific host/port (antirez)
2010-05-21 include solaris fixes in sha1.c (Pieter Noordhuis)
2010-05-20 Don't exit with error in tests temp file cleanup if there are no files to clean (antirez) 2010-05-20 Don't exit with error in tests temp file cleanup if there are no files to clean (antirez)
2010-05-20 fix memory leak on 32-bit builds (Pieter Noordhuis) 2010-05-20 fix memory leak on 32-bit builds (Pieter Noordhuis)
2010-05-20 Merge branch 'master' of github.com:antirez/redis (antirez) 2010-05-20 Merge branch 'master' of github.com:antirez/redis (antirez)
......
...@@ -5,25 +5,25 @@ VERSION 2.2 TODO (Optimizations and latency) ...@@ -5,25 +5,25 @@ VERSION 2.2 TODO (Optimizations and latency)
============================================ ============================================
* Support for syslog(3). * Support for syslog(3).
* Implement an UDP interface for low-latency operations.
VERSION 2.x TODO
================
* BRPOPLPUSH
* Save dataset / fsync() on SIGTERM
* Change the implementation of ZCOUNT to use the augmented skiplist in order to be much faster. * Change the implementation of ZCOUNT to use the augmented skiplist in order to be much faster.
Virtual Memory optimizations: VM TODO
=======
* Use multiple open FDs against the VM file, one for thread. * Use multiple open FDs against the VM file, one for thread.
* Check what happens performance-wise if instead of creating threads again and again the same threads are reused forever. Note: this requires a way to disable this clients in the child, but waiting for empty new jobs queue can be enough. * Check what happens performance-wise if instead of creating threads again and again the same threads are reused forever. Note: this requires a way to disable this clients in the child, but waiting for empty new jobs queue can be enough.
* Implement LEN, PEEK, POKE, SETBIT, GETBIT
STRING COMMANDS
===============
* Implement STRLEN, PEEK, POKE, SETBIT, GETBIT
OTHER IMPORTANT THINGS THAT WILL BE ADDED BUT I'M NOT SURE WHEN OTHER IMPORTANT THINGS THAT WILL BE ADDED BUT I'M NOT SURE WHEN
=============================================================== ===============================================================
BIG ONES: BIG ONES:
* BRPOPLPUSH
* Specially encoded memory-saving integer sets. * Specially encoded memory-saving integer sets.
* A command to export a JSON dump (there should be mostly working patch needing major reworking). * 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) * Specially encoded sets of integers (this includes a big refactoring providing an higher level layer for Sets manipulation)
...@@ -45,20 +45,11 @@ THE "MAYBE" TODO LIST: things that may or may not get implemented ...@@ -45,20 +45,11 @@ THE "MAYBE" TODO LIST: things that may or may not get implemented
Most of this can be seen just as proposals, the fact they are in this list Most of this can be seen just as proposals, the fact they are in this list
it's not a guarantee they'll ever get implemented ;) it's not a guarantee they'll ever get implemented ;)
* Move dict.c from hash table to skip list, in order to avoid the blocking resize operation needed for the hash table.
* FORK command (fork()s executing the commands received by the current
client in the new process). Hint: large SORTs can use more cores,
copy-on-write will avoid memory problems.
* DUP command? DUP srckey dstkey, creates an exact clone of srckey value in dstkey.
* SORT: Don't copy the list into a vector when BY argument is constant. * SORT: Don't copy the list into a vector when BY argument is constant.
* Write the hash table size of every db in the dump, so that Redis can resize the hash table just one time when loading a big DB. * Write the hash table size of every db in the dump, so that Redis can resize the hash table just one time when loading a big DB.
* LOCK / TRYLOCK / UNLOCK as described many times in the google group
* Replication automated tests
* Byte Array type (BA prefixed commands): BASETBIT BAGETBIT BASETU8 U16 U32 U64 S8 S16 S32 S64, ability to atomically INCRBY all the base types. BARANGE to get a range of bytes as a bulk value, BASETRANGE to set a range of bytes. * Byte Array type (BA prefixed commands): BASETBIT BAGETBIT BASETU8 U16 U32 U64 S8 S16 S32 S64, ability to atomically INCRBY all the base types. BARANGE to get a range of bytes as a bulk value, BASETRANGE to set a range of bytes.
* zmalloc() should avoid to add a private header for archs where there is some other kind of libc-specific way to get the size of a malloced block. Already done for Mac OS X.
* Read-only mode. * Read-only mode.
* Pattern-matching replication. * Kill the delete-on-write behavior of expires, replicating DELs
* Add an option to relax the delete-expiring-keys-on-write semantic *denying* replication and AOF when this is on? Can be handy sometimes, when using Redis for non persistent state, but can create problems. For instance should rename and move also "move" the timeouts? How does this affect other commands?
* Multiple BY in SORT. * Multiple BY in SORT.
KNOWN BUGS KNOWN BUGS
......
This diff is collapsed.
/*
* Copyright (c) 2009-2010, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __REDIS_H__
#define __REDIS_H__
enum
{
REG_GS = 0,
# define REG_GS REG_GS
REG_FS,
# define REG_FS REG_FS
REG_ES,
# define REG_ES REG_ES
REG_DS,
# define REG_DS REG_DS
REG_EDI,
# define REG_EDI REG_EDI
REG_ESI,
# define REG_ESI REG_ESI
REG_EBP,
# define REG_EBP REG_EBP
REG_ESP,
# define REG_ESP REG_ESP
REG_EBX,
# define REG_EBX REG_EBX
REG_EDX,
# define REG_EDX REG_EDX
REG_ECX,
# define REG_ECX REG_ECX
REG_EAX,
# define REG_EAX REG_EAX
REG_TRAPNO,
# define REG_TRAPNO REG_TRAPNO
REG_ERR,
# define REG_ERR REG_ERR
REG_EIP,
# define REG_EIP REG_EIP
REG_CS,
# define REG_CS REG_CS
REG_EFL,
# define REG_EFL REG_EFL
REG_UESP,
# define REG_UESP REG_UESP
REG_SS
# define REG_SS REG_SS
};
#endif
...@@ -15,7 +15,7 @@ endif ...@@ -15,7 +15,7 @@ endif
CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF) CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)
DEBUG?= -g -rdynamic -ggdb DEBUG?= -g -rdynamic -ggdb
OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o vm.o pubsub.o multi.o debug.o sort.o
BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o linenoise.o CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o linenoise.o
CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
...@@ -48,7 +48,7 @@ redis-check-dump.o: redis-check-dump.c lzf.h ...@@ -48,7 +48,7 @@ redis-check-dump.o: redis-check-dump.c lzf.h
redis-cli.o: redis-cli.c fmacros.h anet.h sds.h adlist.h zmalloc.h \ redis-cli.o: redis-cli.c fmacros.h anet.h sds.h adlist.h zmalloc.h \
linenoise.h linenoise.h
redis.o: redis.c fmacros.h config.h redis.h ae.h sds.h anet.h dict.h \ redis.o: redis.c fmacros.h config.h redis.h ae.h sds.h anet.h dict.h \
adlist.h zmalloc.h lzf.h pqsort.h zipmap.h ziplist.h sha1.h staticsymbols.h adlist.h zmalloc.h lzf.h pqsort.h zipmap.h ziplist.h sha1.h
release.o: release.c release.h release.o: release.c release.h
sds.o: sds.c sds.h zmalloc.h sds.o: sds.c sds.h zmalloc.h
sha1.o: sha1.c sha1.h sha1.o: sha1.c sha1.h
...@@ -83,17 +83,14 @@ clean: ...@@ -83,17 +83,14 @@ clean:
dep: dep:
$(CC) -MM *.c $(CC) -MM *.c
staticsymbols:
tclsh utils/build-static-symbols.tcl > staticsymbols.h
test: test:
tclsh8.5 tests/test_helper.tcl --tags "${TAGS}" (cd ..; tclsh8.5 tests/test_helper.tcl --tags "${TAGS}")
bench: bench:
./redis-benchmark ./redis-benchmark
log: log:
git log '--pretty=format:%ad %s (%cn)' --date=short > Changelog git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
32bit: 32bit:
@echo "" @echo ""
......
This diff is collapsed.
#include "redis.h"
/*-----------------------------------------------------------------------------
* Config file parsing
*----------------------------------------------------------------------------*/
int yesnotoi(char *s) {
if (!strcasecmp(s,"yes")) return 1;
else if (!strcasecmp(s,"no")) return 0;
else return -1;
}
void appendServerSaveParams(time_t seconds, int changes) {
server.saveparams = zrealloc(server.saveparams,sizeof(struct saveparam)*(server.saveparamslen+1));
server.saveparams[server.saveparamslen].seconds = seconds;
server.saveparams[server.saveparamslen].changes = changes;
server.saveparamslen++;
}
void resetServerSaveParams() {
zfree(server.saveparams);
server.saveparams = NULL;
server.saveparamslen = 0;
}
/* I agree, this is a very rudimental way to load a configuration...
will improve later if the config gets more complex */
void loadServerConfig(char *filename) {
FILE *fp;
char buf[REDIS_CONFIGLINE_MAX+1], *err = NULL;
int linenum = 0;
sds line = NULL;
if (filename[0] == '-' && filename[1] == '\0')
fp = stdin;
else {
if ((fp = fopen(filename,"r")) == NULL) {
redisLog(REDIS_WARNING, "Fatal error, can't open config file '%s'", filename);
exit(1);
}
}
while(fgets(buf,REDIS_CONFIGLINE_MAX+1,fp) != NULL) {
sds *argv;
int argc, j;
linenum++;
line = sdsnew(buf);
line = sdstrim(line," \t\r\n");
/* Skip comments and blank lines*/
if (line[0] == '#' || line[0] == '\0') {
sdsfree(line);
continue;
}
/* Split into arguments */
argv = sdssplitlen(line,sdslen(line)," ",1,&argc);
sdstolower(argv[0]);
/* Execute config directives */
if (!strcasecmp(argv[0],"timeout") && argc == 2) {
server.maxidletime = atoi(argv[1]);
if (server.maxidletime < 0) {
err = "Invalid timeout value"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"port") && argc == 2) {
server.port = atoi(argv[1]);
if (server.port < 1 || server.port > 65535) {
err = "Invalid port"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"bind") && argc == 2) {
server.bindaddr = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"save") && argc == 3) {
int seconds = atoi(argv[1]);
int changes = atoi(argv[2]);
if (seconds < 1 || changes < 0) {
err = "Invalid save parameters"; goto loaderr;
}
appendServerSaveParams(seconds,changes);
} else if (!strcasecmp(argv[0],"dir") && argc == 2) {
if (chdir(argv[1]) == -1) {
redisLog(REDIS_WARNING,"Can't chdir to '%s': %s",
argv[1], strerror(errno));
exit(1);
}
} else if (!strcasecmp(argv[0],"loglevel") && argc == 2) {
if (!strcasecmp(argv[1],"debug")) server.verbosity = REDIS_DEBUG;
else if (!strcasecmp(argv[1],"verbose")) server.verbosity = REDIS_VERBOSE;
else if (!strcasecmp(argv[1],"notice")) server.verbosity = REDIS_NOTICE;
else if (!strcasecmp(argv[1],"warning")) server.verbosity = REDIS_WARNING;
else {
err = "Invalid log level. Must be one of debug, notice, warning";
goto loaderr;
}
} else if (!strcasecmp(argv[0],"logfile") && argc == 2) {
FILE *logfp;
server.logfile = zstrdup(argv[1]);
if (!strcasecmp(server.logfile,"stdout")) {
zfree(server.logfile);
server.logfile = NULL;
}
if (server.logfile) {
/* Test if we are able to open the file. The server will not
* be able to abort just for this problem later... */
logfp = fopen(server.logfile,"a");
if (logfp == NULL) {
err = sdscatprintf(sdsempty(),
"Can't open the log file: %s", strerror(errno));
goto loaderr;
}
fclose(logfp);
}
} else if (!strcasecmp(argv[0],"databases") && argc == 2) {
server.dbnum = atoi(argv[1]);
if (server.dbnum < 1) {
err = "Invalid number of databases"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"include") && argc == 2) {
loadServerConfig(argv[1]);
} else if (!strcasecmp(argv[0],"maxclients") && argc == 2) {
server.maxclients = atoi(argv[1]);
} else if (!strcasecmp(argv[0],"maxmemory") && argc == 2) {
server.maxmemory = memtoll(argv[1],NULL);
} else if (!strcasecmp(argv[0],"slaveof") && argc == 3) {
server.masterhost = sdsnew(argv[1]);
server.masterport = atoi(argv[2]);
server.replstate = REDIS_REPL_CONNECT;
} else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
server.masterauth = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"glueoutputbuf") && argc == 2) {
if ((server.glueoutputbuf = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"rdbcompression") && argc == 2) {
if ((server.rdbcompression = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"activerehashing") && argc == 2) {
if ((server.activerehashing = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"daemonize") && argc == 2) {
if ((server.daemonize = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"appendonly") && argc == 2) {
if ((server.appendonly = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"appendfilename") && argc == 2) {
zfree(server.appendfilename);
server.appendfilename = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"no-appendfsync-on-rewrite")
&& argc == 2) {
if ((server.no_appendfsync_on_rewrite= yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"appendfsync") && argc == 2) {
if (!strcasecmp(argv[1],"no")) {
server.appendfsync = APPENDFSYNC_NO;
} else if (!strcasecmp(argv[1],"always")) {
server.appendfsync = APPENDFSYNC_ALWAYS;
} else if (!strcasecmp(argv[1],"everysec")) {
server.appendfsync = APPENDFSYNC_EVERYSEC;
} else {
err = "argument must be 'no', 'always' or 'everysec'";
goto loaderr;
}
} else if (!strcasecmp(argv[0],"requirepass") && argc == 2) {
server.requirepass = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"pidfile") && argc == 2) {
zfree(server.pidfile);
server.pidfile = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"dbfilename") && argc == 2) {
zfree(server.dbfilename);
server.dbfilename = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"vm-enabled") && argc == 2) {
if ((server.vm_enabled = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"vm-swap-file") && argc == 2) {
zfree(server.vm_swap_file);
server.vm_swap_file = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"vm-max-memory") && argc == 2) {
server.vm_max_memory = memtoll(argv[1],NULL);
} else if (!strcasecmp(argv[0],"vm-page-size") && argc == 2) {
server.vm_page_size = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"vm-pages") && argc == 2) {
server.vm_pages = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"vm-max-threads") && argc == 2) {
server.vm_max_threads = strtoll(argv[1], NULL, 10);
} else if (!strcasecmp(argv[0],"hash-max-zipmap-entries") && argc == 2){
server.hash_max_zipmap_entries = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"hash-max-zipmap-value") && argc == 2){
server.hash_max_zipmap_value = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"list-max-ziplist-entries") && argc == 2){
server.list_max_ziplist_entries = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"list-max-ziplist-value") && argc == 2){
server.list_max_ziplist_value = memtoll(argv[1], NULL);
} else {
err = "Bad directive or wrong number of arguments"; goto loaderr;
}
for (j = 0; j < argc; j++)
sdsfree(argv[j]);
zfree(argv);
sdsfree(line);
}
if (fp != stdin) fclose(fp);
return;
loaderr:
fprintf(stderr, "\n*** FATAL CONFIG FILE ERROR ***\n");
fprintf(stderr, "Reading the configuration file, at line %d\n", linenum);
fprintf(stderr, ">>> '%s'\n", line);
fprintf(stderr, "%s\n", err);
exit(1);
}
/*-----------------------------------------------------------------------------
* CONFIG command for remote configuration
*----------------------------------------------------------------------------*/
void configSetCommand(redisClient *c) {
robj *o = getDecodedObject(c->argv[3]);
long long ll;
if (!strcasecmp(c->argv[2]->ptr,"dbfilename")) {
zfree(server.dbfilename);
server.dbfilename = zstrdup(o->ptr);
} else if (!strcasecmp(c->argv[2]->ptr,"requirepass")) {
zfree(server.requirepass);
server.requirepass = zstrdup(o->ptr);
} else if (!strcasecmp(c->argv[2]->ptr,"masterauth")) {
zfree(server.masterauth);
server.masterauth = zstrdup(o->ptr);
} else if (!strcasecmp(c->argv[2]->ptr,"maxmemory")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR ||
ll < 0) goto badfmt;
server.maxmemory = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"timeout")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR ||
ll < 0 || ll > LONG_MAX) goto badfmt;
server.maxidletime = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"appendfsync")) {
if (!strcasecmp(o->ptr,"no")) {
server.appendfsync = APPENDFSYNC_NO;
} else if (!strcasecmp(o->ptr,"everysec")) {
server.appendfsync = APPENDFSYNC_EVERYSEC;
} else if (!strcasecmp(o->ptr,"always")) {
server.appendfsync = APPENDFSYNC_ALWAYS;
} else {
goto badfmt;
}
} else if (!strcasecmp(c->argv[2]->ptr,"no-appendfsync-on-rewrite")) {
int yn = yesnotoi(o->ptr);
if (yn == -1) goto badfmt;
server.no_appendfsync_on_rewrite = yn;
} else if (!strcasecmp(c->argv[2]->ptr,"appendonly")) {
int old = server.appendonly;
int new = yesnotoi(o->ptr);
if (new == -1) goto badfmt;
if (old != new) {
if (new == 0) {
stopAppendOnly();
} else {
if (startAppendOnly() == REDIS_ERR) {
addReplySds(c,sdscatprintf(sdsempty(),
"-ERR Unable to turn on AOF. Check server logs.\r\n"));
decrRefCount(o);
return;
}
}
}
} else if (!strcasecmp(c->argv[2]->ptr,"save")) {
int vlen, j;
sds *v = sdssplitlen(o->ptr,sdslen(o->ptr)," ",1,&vlen);
/* Perform sanity check before setting the new config:
* - Even number of args
* - Seconds >= 1, changes >= 0 */
if (vlen & 1) {
sdsfreesplitres(v,vlen);
goto badfmt;
}
for (j = 0; j < vlen; j++) {
char *eptr;
long val;
val = strtoll(v[j], &eptr, 10);
if (eptr[0] != '\0' ||
((j & 1) == 0 && val < 1) ||
((j & 1) == 1 && val < 0)) {
sdsfreesplitres(v,vlen);
goto badfmt;
}
}
/* Finally set the new config */
resetServerSaveParams();
for (j = 0; j < vlen; j += 2) {
time_t seconds;
int changes;
seconds = strtoll(v[j],NULL,10);
changes = strtoll(v[j+1],NULL,10);
appendServerSaveParams(seconds, changes);
}
sdsfreesplitres(v,vlen);
} else {
addReplySds(c,sdscatprintf(sdsempty(),
"-ERR not supported CONFIG parameter %s\r\n",
(char*)c->argv[2]->ptr));
decrRefCount(o);
return;
}
decrRefCount(o);
addReply(c,shared.ok);
return;
badfmt: /* Bad format errors */
addReplySds(c,sdscatprintf(sdsempty(),
"-ERR invalid argument '%s' for CONFIG SET '%s'\r\n",
(char*)o->ptr,
(char*)c->argv[2]->ptr));
decrRefCount(o);
}
void configGetCommand(redisClient *c) {
robj *o = getDecodedObject(c->argv[2]);
robj *lenobj = createObject(REDIS_STRING,NULL);
char *pattern = o->ptr;
int matches = 0;
addReply(c,lenobj);
decrRefCount(lenobj);
if (stringmatch(pattern,"dbfilename",0)) {
addReplyBulkCString(c,"dbfilename");
addReplyBulkCString(c,server.dbfilename);
matches++;
}
if (stringmatch(pattern,"requirepass",0)) {
addReplyBulkCString(c,"requirepass");
addReplyBulkCString(c,server.requirepass);
matches++;
}
if (stringmatch(pattern,"masterauth",0)) {
addReplyBulkCString(c,"masterauth");
addReplyBulkCString(c,server.masterauth);
matches++;
}
if (stringmatch(pattern,"maxmemory",0)) {
char buf[128];
ll2string(buf,128,server.maxmemory);
addReplyBulkCString(c,"maxmemory");
addReplyBulkCString(c,buf);
matches++;
}
if (stringmatch(pattern,"timeout",0)) {
char buf[128];
ll2string(buf,128,server.maxidletime);
addReplyBulkCString(c,"timeout");
addReplyBulkCString(c,buf);
matches++;
}
if (stringmatch(pattern,"appendonly",0)) {
addReplyBulkCString(c,"appendonly");
addReplyBulkCString(c,server.appendonly ? "yes" : "no");
matches++;
}
if (stringmatch(pattern,"no-appendfsync-on-rewrite",0)) {
addReplyBulkCString(c,"no-appendfsync-on-rewrite");
addReplyBulkCString(c,server.no_appendfsync_on_rewrite ? "yes" : "no");
matches++;
}
if (stringmatch(pattern,"appendfsync",0)) {
char *policy;
switch(server.appendfsync) {
case APPENDFSYNC_NO: policy = "no"; break;
case APPENDFSYNC_EVERYSEC: policy = "everysec"; break;
case APPENDFSYNC_ALWAYS: policy = "always"; break;
default: policy = "unknown"; break; /* too harmless to panic */
}
addReplyBulkCString(c,"appendfsync");
addReplyBulkCString(c,policy);
matches++;
}
if (stringmatch(pattern,"save",0)) {
sds buf = sdsempty();
int j;
for (j = 0; j < server.saveparamslen; j++) {
buf = sdscatprintf(buf,"%ld %d",
server.saveparams[j].seconds,
server.saveparams[j].changes);
if (j != server.saveparamslen-1)
buf = sdscatlen(buf," ",1);
}
addReplyBulkCString(c,"save");
addReplyBulkCString(c,buf);
sdsfree(buf);
matches++;
}
decrRefCount(o);
lenobj->ptr = sdscatprintf(sdsempty(),"*%d\r\n",matches*2);
}
void configCommand(redisClient *c) {
if (!strcasecmp(c->argv[1]->ptr,"set")) {
if (c->argc != 4) goto badarity;
configSetCommand(c);
} else if (!strcasecmp(c->argv[1]->ptr,"get")) {
if (c->argc != 3) goto badarity;
configGetCommand(c);
} else if (!strcasecmp(c->argv[1]->ptr,"resetstat")) {
if (c->argc != 2) goto badarity;
server.stat_numcommands = 0;
server.stat_numconnections = 0;
server.stat_expiredkeys = 0;
server.stat_starttime = time(NULL);
addReply(c,shared.ok);
} else {
addReplySds(c,sdscatprintf(sdsempty(),
"-ERR CONFIG subcommand must be one of GET, SET, RESETSTAT\r\n"));
}
return;
badarity:
addReplySds(c,sdscatprintf(sdsempty(),
"-ERR Wrong number of arguments for CONFIG %s\r\n",
(char*) c->argv[1]->ptr));
}
#include "redis.h"
#include <signal.h>
/*-----------------------------------------------------------------------------
* C-level DB API
*----------------------------------------------------------------------------*/
robj *lookupKey(redisDb *db, robj *key) {
dictEntry *de = dictFind(db->dict,key->ptr);
if (de) {
robj *val = dictGetEntryVal(de);
if (server.vm_enabled) {
if (val->storage == REDIS_VM_MEMORY ||
val->storage == REDIS_VM_SWAPPING)
{
/* If we were swapping the object out, cancel the operation */
if (val->storage == REDIS_VM_SWAPPING)
vmCancelThreadedIOJob(val);
/* Update the access time for the aging algorithm. */
val->lru = server.lruclock;
} else {
int notify = (val->storage == REDIS_VM_LOADING);
/* Our value was swapped on disk. Bring it at home. */
redisAssert(val->type == REDIS_VMPOINTER);
val = vmLoadObject(val);
dictGetEntryVal(de) = val;
/* Clients blocked by the VM subsystem may be waiting for
* this key... */
if (notify) handleClientsBlockedOnSwappedKey(db,key);
}
}
return val;
} else {
return NULL;
}
}
robj *lookupKeyRead(redisDb *db, robj *key) {
expireIfNeeded(db,key);
return lookupKey(db,key);
}
robj *lookupKeyWrite(redisDb *db, robj *key) {
deleteIfVolatile(db,key);
touchWatchedKey(db,key);
return lookupKey(db,key);
}
robj *lookupKeyReadOrReply(redisClient *c, robj *key, robj *reply) {
robj *o = lookupKeyRead(c->db, key);
if (!o) addReply(c,reply);
return o;
}
robj *lookupKeyWriteOrReply(redisClient *c, robj *key, robj *reply) {
robj *o = lookupKeyWrite(c->db, key);
if (!o) addReply(c,reply);
return o;
}
/* Add the key to the DB. If the key already exists REDIS_ERR is returned,
* otherwise REDIS_OK is returned, and the caller should increment the
* refcount of 'val'. */
int dbAdd(redisDb *db, robj *key, robj *val) {
/* Perform a lookup before adding the key, as we need to copy the
* key value. */
if (dictFind(db->dict, key->ptr) != NULL) {
return REDIS_ERR;
} else {
sds copy = sdsdup(key->ptr);
dictAdd(db->dict, copy, val);
return REDIS_OK;
}
}
/* If the key does not exist, this is just like dbAdd(). Otherwise
* the value associated to the key is replaced with the new one.
*
* On update (key already existed) 0 is returned. Otherwise 1. */
int dbReplace(redisDb *db, robj *key, robj *val) {
if (dictFind(db->dict,key->ptr) == NULL) {
sds copy = sdsdup(key->ptr);
dictAdd(db->dict, copy, val);
return 1;
} else {
dictReplace(db->dict, key->ptr, val);
return 0;
}
}
int dbExists(redisDb *db, robj *key) {
return dictFind(db->dict,key->ptr) != NULL;
}
/* Return a random key, in form of a Redis object.
* If there are no keys, NULL is returned.
*
* The function makes sure to return keys not already expired. */
robj *dbRandomKey(redisDb *db) {
struct dictEntry *de;
while(1) {
sds key;
robj *keyobj;
de = dictGetRandomKey(db->dict);
if (de == NULL) return NULL;
key = dictGetEntryKey(de);
keyobj = createStringObject(key,sdslen(key));
if (dictFind(db->expires,key)) {
if (expireIfNeeded(db,keyobj)) {
decrRefCount(keyobj);
continue; /* search for another key. This expired. */
}
}
return keyobj;
}
}
/* Delete a key, value, and associated expiration entry if any, from the DB */
int dbDelete(redisDb *db, robj *key) {
/* Deleting an entry from the expires dict will not free the sds of
* the key, because it is shared with the main dictionary. */
if (dictSize(db->expires) > 0) dictDelete(db->expires,key->ptr);
return dictDelete(db->dict,key->ptr) == DICT_OK;
}
/* Empty the whole database */
long long emptyDb() {
int j;
long long removed = 0;
for (j = 0; j < server.dbnum; j++) {
removed += dictSize(server.db[j].dict);
dictEmpty(server.db[j].dict);
dictEmpty(server.db[j].expires);
}
return removed;
}
int selectDb(redisClient *c, int id) {
if (id < 0 || id >= server.dbnum)
return REDIS_ERR;
c->db = &server.db[id];
return REDIS_OK;
}
/*-----------------------------------------------------------------------------
* Type agnostic commands operating on the key space
*----------------------------------------------------------------------------*/
void flushdbCommand(redisClient *c) {
server.dirty += dictSize(c->db->dict);
touchWatchedKeysOnFlush(c->db->id);
dictEmpty(c->db->dict);
dictEmpty(c->db->expires);
addReply(c,shared.ok);
}
void flushallCommand(redisClient *c) {
touchWatchedKeysOnFlush(-1);
server.dirty += emptyDb();
addReply(c,shared.ok);
if (server.bgsavechildpid != -1) {
kill(server.bgsavechildpid,SIGKILL);
rdbRemoveTempFile(server.bgsavechildpid);
}
rdbSave(server.dbfilename);
server.dirty++;
}
void delCommand(redisClient *c) {
int deleted = 0, j;
for (j = 1; j < c->argc; j++) {
if (dbDelete(c->db,c->argv[j])) {
touchWatchedKey(c->db,c->argv[j]);
server.dirty++;
deleted++;
}
}
addReplyLongLong(c,deleted);
}
void existsCommand(redisClient *c) {
expireIfNeeded(c->db,c->argv[1]);
if (dbExists(c->db,c->argv[1])) {
addReply(c, shared.cone);
} else {
addReply(c, shared.czero);
}
}
void selectCommand(redisClient *c) {
int id = atoi(c->argv[1]->ptr);
if (selectDb(c,id) == REDIS_ERR) {
addReplySds(c,sdsnew("-ERR invalid DB index\r\n"));
} else {
addReply(c,shared.ok);
}
}
void randomkeyCommand(redisClient *c) {
robj *key;
if ((key = dbRandomKey(c->db)) == NULL) {
addReply(c,shared.nullbulk);
return;
}
addReplyBulk(c,key);
decrRefCount(key);
}
void keysCommand(redisClient *c) {
dictIterator *di;
dictEntry *de;
sds pattern = c->argv[1]->ptr;
int plen = sdslen(pattern);
unsigned long numkeys = 0;
robj *lenobj = createObject(REDIS_STRING,NULL);
di = dictGetIterator(c->db->dict);
addReply(c,lenobj);
decrRefCount(lenobj);
while((de = dictNext(di)) != NULL) {
sds key = dictGetEntryKey(de);
robj *keyobj;
if ((pattern[0] == '*' && pattern[1] == '\0') ||
stringmatchlen(pattern,plen,key,sdslen(key),0)) {
keyobj = createStringObject(key,sdslen(key));
if (expireIfNeeded(c->db,keyobj) == 0) {
addReplyBulk(c,keyobj);
numkeys++;
}
decrRefCount(keyobj);
}
}
dictReleaseIterator(di);
lenobj->ptr = sdscatprintf(sdsempty(),"*%lu\r\n",numkeys);
}
void dbsizeCommand(redisClient *c) {
addReplySds(c,
sdscatprintf(sdsempty(),":%lu\r\n",dictSize(c->db->dict)));
}
void lastsaveCommand(redisClient *c) {
addReplySds(c,
sdscatprintf(sdsempty(),":%lu\r\n",server.lastsave));
}
void typeCommand(redisClient *c) {
robj *o;
char *type;
o = lookupKeyRead(c->db,c->argv[1]);
if (o == NULL) {
type = "+none";
} else {
switch(o->type) {
case REDIS_STRING: type = "+string"; break;
case REDIS_LIST: type = "+list"; break;
case REDIS_SET: type = "+set"; break;
case REDIS_ZSET: type = "+zset"; break;
case REDIS_HASH: type = "+hash"; break;
default: type = "+unknown"; break;
}
}
addReplySds(c,sdsnew(type));
addReply(c,shared.crlf);
}
void saveCommand(redisClient *c) {
if (server.bgsavechildpid != -1) {
addReplySds(c,sdsnew("-ERR background save in progress\r\n"));
return;
}
if (rdbSave(server.dbfilename) == REDIS_OK) {
addReply(c,shared.ok);
} else {
addReply(c,shared.err);
}
}
void bgsaveCommand(redisClient *c) {
if (server.bgsavechildpid != -1) {
addReplySds(c,sdsnew("-ERR background save already in progress\r\n"));
return;
}
if (rdbSaveBackground(server.dbfilename) == REDIS_OK) {
char *status = "+Background saving started\r\n";
addReplySds(c,sdsnew(status));
} else {
addReply(c,shared.err);
}
}
void shutdownCommand(redisClient *c) {
if (prepareForShutdown() == REDIS_OK)
exit(0);
addReplySds(c, sdsnew("-ERR Errors trying to SHUTDOWN. Check logs.\r\n"));
}
void renameGenericCommand(redisClient *c, int nx) {
robj *o;
/* To use the same key as src and dst is probably an error */
if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) {
addReply(c,shared.sameobjecterr);
return;
}
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr)) == NULL)
return;
incrRefCount(o);
deleteIfVolatile(c->db,c->argv[2]);
if (dbAdd(c->db,c->argv[2],o) == REDIS_ERR) {
if (nx) {
decrRefCount(o);
addReply(c,shared.czero);
return;
}
dbReplace(c->db,c->argv[2],o);
}
dbDelete(c->db,c->argv[1]);
touchWatchedKey(c->db,c->argv[2]);
server.dirty++;
addReply(c,nx ? shared.cone : shared.ok);
}
void renameCommand(redisClient *c) {
renameGenericCommand(c,0);
}
void renamenxCommand(redisClient *c) {
renameGenericCommand(c,1);
}
void moveCommand(redisClient *c) {
robj *o;
redisDb *src, *dst;
int srcid;
/* Obtain source and target DB pointers */
src = c->db;
srcid = c->db->id;
if (selectDb(c,atoi(c->argv[2]->ptr)) == REDIS_ERR) {
addReply(c,shared.outofrangeerr);
return;
}
dst = c->db;
selectDb(c,srcid); /* Back to the source DB */
/* If the user is moving using as target the same
* DB as the source DB it is probably an error. */
if (src == dst) {
addReply(c,shared.sameobjecterr);
return;
}
/* Check if the element exists and get a reference */
o = lookupKeyWrite(c->db,c->argv[1]);
if (!o) {
addReply(c,shared.czero);
return;
}
/* Try to add the element to the target DB */
deleteIfVolatile(dst,c->argv[1]);
if (dbAdd(dst,c->argv[1],o) == REDIS_ERR) {
addReply(c,shared.czero);
return;
}
incrRefCount(o);
/* OK! key moved, free the entry in the source DB */
dbDelete(src,c->argv[1]);
server.dirty++;
addReply(c,shared.cone);
}
/*-----------------------------------------------------------------------------
* Expires API
*----------------------------------------------------------------------------*/
int removeExpire(redisDb *db, robj *key) {
/* An expire may only be removed if there is a corresponding entry in the
* main dict. Otherwise, the key will never be freed. */
redisAssert(dictFind(db->dict,key->ptr) != NULL);
if (dictDelete(db->expires,key->ptr) == DICT_OK) {
return 1;
} else {
return 0;
}
}
int setExpire(redisDb *db, robj *key, time_t when) {
dictEntry *de;
/* Reuse the sds from the main dict in the expire dict */
redisAssert((de = dictFind(db->dict,key->ptr)) != NULL);
if (dictAdd(db->expires,dictGetEntryKey(de),(void*)when) == DICT_ERR) {
return 0;
} else {
return 1;
}
}
/* Return the expire time of the specified key, or -1 if no expire
* is associated with this key (i.e. the key is non volatile) */
time_t getExpire(redisDb *db, robj *key) {
dictEntry *de;
/* No expire? return ASAP */
if (dictSize(db->expires) == 0 ||
(de = dictFind(db->expires,key->ptr)) == NULL) return -1;
/* The entry was found in the expire dict, this means it should also
* be present in the main dict (safety check). */
redisAssert(dictFind(db->dict,key->ptr) != NULL);
return (time_t) dictGetEntryVal(de);
}
int expireIfNeeded(redisDb *db, robj *key) {
time_t when = getExpire(db,key);
if (when < 0) return 0;
/* Return when this key has not expired */
if (time(NULL) <= when) return 0;
/* Delete the key */
server.stat_expiredkeys++;
server.dirty++;
return dbDelete(db,key);
}
int deleteIfVolatile(redisDb *db, robj *key) {
if (getExpire(db,key) < 0) return 0;
/* Delete the key */
server.stat_expiredkeys++;
server.dirty++;
return dbDelete(db,key);
}
/*-----------------------------------------------------------------------------
* Expires Commands
*----------------------------------------------------------------------------*/
void expireGenericCommand(redisClient *c, robj *key, robj *param, long offset) {
dictEntry *de;
time_t seconds;
if (getLongFromObjectOrReply(c, param, &seconds, NULL) != REDIS_OK) return;
seconds -= offset;
de = dictFind(c->db->dict,key->ptr);
if (de == NULL) {
addReply(c,shared.czero);
return;
}
if (seconds <= 0) {
if (dbDelete(c->db,key)) server.dirty++;
addReply(c, shared.cone);
return;
} else {
time_t when = time(NULL)+seconds;
if (setExpire(c->db,key,when)) {
addReply(c,shared.cone);
server.dirty++;
} else {
addReply(c,shared.czero);
}
return;
}
}
void expireCommand(redisClient *c) {
expireGenericCommand(c,c->argv[1],c->argv[2],0);
}
void expireatCommand(redisClient *c) {
expireGenericCommand(c,c->argv[1],c->argv[2],time(NULL));
}
void ttlCommand(redisClient *c) {
time_t expire;
int ttl = -1;
expire = getExpire(c->db,c->argv[1]);
if (expire != -1) {
ttl = (int) (expire-time(NULL));
if (ttl < 0) ttl = -1;
}
addReplySds(c,sdscatprintf(sdsempty(),":%d\r\n",ttl));
}
#include "redis.h"
#include "sha1.h" /* SHA1 is used for DEBUG DIGEST */
/* ================================= Debugging ============================== */
/* Compute the sha1 of string at 's' with 'len' bytes long.
* The SHA1 is then xored againt the string pointed by digest.
* Since xor is commutative, this operation is used in order to
* "add" digests relative to unordered elements.
*
* So digest(a,b,c,d) will be the same of digest(b,a,c,d) */
void xorDigest(unsigned char *digest, void *ptr, size_t len) {
SHA1_CTX ctx;
unsigned char hash[20], *s = ptr;
int j;
SHA1Init(&ctx);
SHA1Update(&ctx,s,len);
SHA1Final(hash,&ctx);
for (j = 0; j < 20; j++)
digest[j] ^= hash[j];
}
void xorObjectDigest(unsigned char *digest, robj *o) {
o = getDecodedObject(o);
xorDigest(digest,o->ptr,sdslen(o->ptr));
decrRefCount(o);
}
/* This function instead of just computing the SHA1 and xoring it
* against diget, also perform the digest of "digest" itself and
* replace the old value with the new one.
*
* So the final digest will be:
*
* digest = SHA1(digest xor SHA1(data))
*
* This function is used every time we want to preserve the order so
* that digest(a,b,c,d) will be different than digest(b,c,d,a)
*
* Also note that mixdigest("foo") followed by mixdigest("bar")
* will lead to a different digest compared to "fo", "obar".
*/
void mixDigest(unsigned char *digest, void *ptr, size_t len) {
SHA1_CTX ctx;
char *s = ptr;
xorDigest(digest,s,len);
SHA1Init(&ctx);
SHA1Update(&ctx,digest,20);
SHA1Final(digest,&ctx);
}
void mixObjectDigest(unsigned char *digest, robj *o) {
o = getDecodedObject(o);
mixDigest(digest,o->ptr,sdslen(o->ptr));
decrRefCount(o);
}
/* Compute the dataset digest. Since keys, sets elements, hashes elements
* are not ordered, we use a trick: every aggregate digest is the xor
* of the digests of their elements. This way the order will not change
* the result. For list instead we use a feedback entering the output digest
* as input in order to ensure that a different ordered list will result in
* a different digest. */
void computeDatasetDigest(unsigned char *final) {
unsigned char digest[20];
char buf[128];
dictIterator *di = NULL;
dictEntry *de;
int j;
uint32_t aux;
memset(final,0,20); /* Start with a clean result */
for (j = 0; j < server.dbnum; j++) {
redisDb *db = server.db+j;
if (dictSize(db->dict) == 0) continue;
di = dictGetIterator(db->dict);
/* hash the DB id, so the same dataset moved in a different
* DB will lead to a different digest */
aux = htonl(j);
mixDigest(final,&aux,sizeof(aux));
/* Iterate this DB writing every entry */
while((de = dictNext(di)) != NULL) {
sds key;
robj *keyobj, *o;
time_t expiretime;
memset(digest,0,20); /* This key-val digest */
key = dictGetEntryKey(de);
keyobj = createStringObject(key,sdslen(key));
mixDigest(digest,key,sdslen(key));
/* Make sure the key is loaded if VM is active */
o = lookupKeyRead(db,keyobj);
aux = htonl(o->type);
mixDigest(digest,&aux,sizeof(aux));
expiretime = getExpire(db,keyobj);
/* Save the key and associated value */
if (o->type == REDIS_STRING) {
mixObjectDigest(digest,o);
} else if (o->type == REDIS_LIST) {
listTypeIterator *li = listTypeInitIterator(o,0,REDIS_TAIL);
listTypeEntry entry;
while(listTypeNext(li,&entry)) {
robj *eleobj = listTypeGet(&entry);
mixObjectDigest(digest,eleobj);
decrRefCount(eleobj);
}
listTypeReleaseIterator(li);
} else if (o->type == REDIS_SET) {
dict *set = o->ptr;
dictIterator *di = dictGetIterator(set);
dictEntry *de;
while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
xorObjectDigest(digest,eleobj);
}
dictReleaseIterator(di);
} else if (o->type == REDIS_ZSET) {
zset *zs = o->ptr;
dictIterator *di = dictGetIterator(zs->dict);
dictEntry *de;
while((de = dictNext(di)) != NULL) {
robj *eleobj = dictGetEntryKey(de);
double *score = dictGetEntryVal(de);
unsigned char eledigest[20];
snprintf(buf,sizeof(buf),"%.17g",*score);
memset(eledigest,0,20);
mixObjectDigest(eledigest,eleobj);
mixDigest(eledigest,buf,strlen(buf));
xorDigest(digest,eledigest,20);
}
dictReleaseIterator(di);
} else if (o->type == REDIS_HASH) {
hashTypeIterator *hi;
robj *obj;
hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != REDIS_ERR) {
unsigned char eledigest[20];
memset(eledigest,0,20);
obj = hashTypeCurrent(hi,REDIS_HASH_KEY);
mixObjectDigest(eledigest,obj);
decrRefCount(obj);
obj = hashTypeCurrent(hi,REDIS_HASH_VALUE);
mixObjectDigest(eledigest,obj);
decrRefCount(obj);
xorDigest(digest,eledigest,20);
}
hashTypeReleaseIterator(hi);
} else {
redisPanic("Unknown object type");
}
/* If the key has an expire, add it to the mix */
if (expiretime != -1) xorDigest(digest,"!!expire!!",10);
/* We can finally xor the key-val digest to the final digest */
xorDigest(final,digest,20);
decrRefCount(keyobj);
}
dictReleaseIterator(di);
}
}
void debugCommand(redisClient *c) {
if (!strcasecmp(c->argv[1]->ptr,"segfault")) {
*((char*)-1) = 'x';
} else if (!strcasecmp(c->argv[1]->ptr,"reload")) {
if (rdbSave(server.dbfilename) != REDIS_OK) {
addReply(c,shared.err);
return;
}
emptyDb();
if (rdbLoad(server.dbfilename) != REDIS_OK) {
addReply(c,shared.err);
return;
}
redisLog(REDIS_WARNING,"DB reloaded by DEBUG RELOAD");
addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"loadaof")) {
emptyDb();
if (loadAppendOnlyFile(server.appendfilename) != REDIS_OK) {
addReply(c,shared.err);
return;
}
redisLog(REDIS_WARNING,"Append Only File loaded by DEBUG LOADAOF");
addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"object") && c->argc == 3) {
dictEntry *de = dictFind(c->db->dict,c->argv[2]->ptr);
robj *val;
if (!de) {
addReply(c,shared.nokeyerr);
return;
}
val = dictGetEntryVal(de);
if (!server.vm_enabled || (val->storage == REDIS_VM_MEMORY ||
val->storage == REDIS_VM_SWAPPING)) {
char *strenc;
strenc = strEncoding(val->encoding);
addReplySds(c,sdscatprintf(sdsempty(),
"+Value at:%p refcount:%d "
"encoding:%s serializedlength:%lld\r\n",
(void*)val, val->refcount,
strenc, (long long) rdbSavedObjectLen(val,NULL)));
} else {
vmpointer *vp = (vmpointer*) val;
addReplySds(c,sdscatprintf(sdsempty(),
"+Value swapped at: page %llu "
"using %llu pages\r\n",
(unsigned long long) vp->page,
(unsigned long long) vp->usedpages));
}
} else if (!strcasecmp(c->argv[1]->ptr,"swapin") && c->argc == 3) {
lookupKeyRead(c->db,c->argv[2]);
addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"swapout") && c->argc == 3) {
dictEntry *de = dictFind(c->db->dict,c->argv[2]->ptr);
robj *val;
vmpointer *vp;
if (!server.vm_enabled) {
addReplySds(c,sdsnew("-ERR Virtual Memory is disabled\r\n"));
return;
}
if (!de) {
addReply(c,shared.nokeyerr);
return;
}
val = dictGetEntryVal(de);
/* Swap it */
if (val->storage != REDIS_VM_MEMORY) {
addReplySds(c,sdsnew("-ERR This key is not in memory\r\n"));
} else if (val->refcount != 1) {
addReplySds(c,sdsnew("-ERR Object is shared\r\n"));
} else if ((vp = vmSwapObjectBlocking(val)) != NULL) {
dictGetEntryVal(de) = vp;
addReply(c,shared.ok);
} else {
addReply(c,shared.err);
}
} else if (!strcasecmp(c->argv[1]->ptr,"populate") && c->argc == 3) {
long keys, j;
robj *key, *val;
char buf[128];
if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != REDIS_OK)
return;
for (j = 0; j < keys; j++) {
snprintf(buf,sizeof(buf),"key:%lu",j);
key = createStringObject(buf,strlen(buf));
if (lookupKeyRead(c->db,key) != NULL) {
decrRefCount(key);
continue;
}
snprintf(buf,sizeof(buf),"value:%lu",j);
val = createStringObject(buf,strlen(buf));
dbAdd(c->db,key,val);
decrRefCount(key);
}
addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"digest") && c->argc == 2) {
unsigned char digest[20];
sds d = sdsnew("+");
int j;
computeDatasetDigest(digest);
for (j = 0; j < 20; j++)
d = sdscatprintf(d, "%02x",digest[j]);
d = sdscatlen(d,"\r\n",2);
addReplySds(c,d);
} else {
addReplySds(c,sdsnew(
"-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n"));
}
}
void _redisAssert(char *estr, char *file, int line) {
redisLog(REDIS_WARNING,"=== ASSERTION FAILED ===");
redisLog(REDIS_WARNING,"==> %s:%d '%s' is not true",file,line,estr);
#ifdef HAVE_BACKTRACE
redisLog(REDIS_WARNING,"(forcing SIGSEGV in order to print the stack trace)");
*((char*)-1) = 'x';
#endif
}
void _redisPanic(char *msg, char *file, int line) {
redisLog(REDIS_WARNING,"!!! Software Failure. Press left mouse button to continue");
redisLog(REDIS_WARNING,"Guru Meditation: %s #%s:%d",msg,file,line);
#ifdef HAVE_BACKTRACE
redisLog(REDIS_WARNING,"(forcing SIGSEGV in order to print the stack trace)");
*((char*)-1) = 'x';
#endif
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment