├── INSTALL ├── tests ├── tmp │ └── .gitignore ├── cluster │ ├── tmp │ │ └── .gitignore │ ├── tests │ │ ├── helpers │ │ │ └── onlydots.tcl │ │ ├── 01-faildet.tcl │ │ ├── 09-pubsub.tcl │ │ ├── 07-replica-migration.tcl │ │ ├── 02-failover.tcl │ │ ├── 00-base.tcl │ │ ├── includes │ │ │ └── init-tests.tcl │ │ ├── 06-slave-stop-cond.tcl │ │ └── 08-update-msg.tcl │ └── run.tcl ├── sentinel │ ├── tmp │ │ └── .gitignore │ ├── tests │ │ ├── 03-runtime-reconf.tcl │ │ ├── 04-slave-selection.tcl │ │ ├── 01-conf-update.tcl │ │ └── 05-manual.tcl │ └── run.tcl ├── assets │ ├── encodings.rdb │ ├── hash-zipmap.rdb │ └── default.conf ├── unit │ ├── printver.tcl │ ├── type │ │ ├── list-common.tcl │ │ └── list-2.tcl │ ├── limits.tcl │ ├── auth.tcl │ ├── memefficiency.tcl │ ├── quit.tcl │ ├── latency-monitor.tcl │ └── introspection.tcl ├── helpers │ ├── bg_complex_data.tcl │ └── gen_write_load.tcl ├── support │ └── tmpfile.tcl └── integration │ ├── aof-race.tcl │ └── convert-zipmap-hash-on-load.tcl ├── deps ├── jemalloc │ ├── config.stamp.in │ ├── VERSION │ ├── test │ │ ├── src │ │ │ ├── math.c │ │ │ ├── thd.c │ │ │ ├── mtx.c │ │ │ └── test.c │ │ ├── unit │ │ │ ├── prof_accum_a.c │ │ │ ├── prof_accum_b.c │ │ │ ├── prof_accum.h │ │ │ ├── prof_idump.c │ │ │ ├── mtx.c │ │ │ ├── prof_gdump.c │ │ │ ├── tsd.c │ │ │ ├── zero.c │ │ │ ├── prof_accum.c │ │ │ └── mq.c │ │ ├── include │ │ │ └── test │ │ │ │ ├── jemalloc_test_defs.h.in │ │ │ │ ├── thd.h │ │ │ │ └── mtx.h │ │ ├── integration │ │ │ ├── mremap.c │ │ │ ├── xallocx.c │ │ │ ├── MALLOCX_ARENA.c │ │ │ └── thread_arena.c │ │ └── test.sh.in │ ├── src │ │ ├── mb.c │ │ ├── hash.c │ │ ├── atomic.c │ │ └── extent.c │ ├── doc │ │ ├── jemalloc.html │ │ ├── html.xsl.in │ │ ├── manpages.xsl.in │ │ └── stylesheet.xsl │ ├── include │ │ ├── jemalloc │ │ │ ├── internal │ │ │ │ ├── private_unnamespace.sh │ │ │ │ ├── private_namespace.sh │ │ │ │ ├── public_unnamespace.sh │ │ │ │ ├── public_namespace.sh │ │ │ │ ├── chunk_mmap.h │ │ │ │ ├── base.h │ │ │ │ ├── chunk_dss.h │ │ │ │ ├── extent.h │ │ │ │ ├── jemalloc_internal_macros.h │ │ │ │ ├── huge.h │ │ │ │ ├── quarantine.h │ │ │ │ ├── prng.h │ │ │ │ ├── chunk.h │ │ │ │ └── qr.h │ │ │ ├── jemalloc_rename.sh │ │ │ ├── jemalloc.sh │ │ │ ├── jemalloc_defs.h.in │ │ │ ├── jemalloc_mangle.sh │ │ │ └── jemalloc_macros.h.in │ │ └── msvc_compat │ │ │ ├── stdbool.h │ │ │ └── strings.h │ ├── bin │ │ └── jemalloc.sh.in │ ├── autogen.sh │ ├── coverage.sh │ ├── README │ ├── .gitignore │ └── COPYING ├── linenoise │ ├── .gitignore │ ├── Makefile │ └── example.c ├── lua │ ├── doc │ │ ├── cover.png │ │ ├── logo.gif │ │ ├── manual.css │ │ ├── readme.html │ │ └── lua.css │ ├── etc │ │ ├── lua.ico │ │ ├── lua.hpp │ │ ├── lua.pc │ │ ├── all.c │ │ ├── min.c │ │ ├── Makefile │ │ ├── strict.lua │ │ ├── README │ │ ├── luavs.bat │ │ └── noparser.c │ ├── test │ │ ├── life.lua │ │ ├── echo.lua │ │ ├── hello.lua │ │ ├── printf.lua │ │ ├── env.lua │ │ ├── luac.lua │ │ ├── fibfor.lua │ │ ├── readonly.lua │ │ ├── table.lua │ │ ├── cf.lua │ │ ├── xd.lua │ │ ├── globals.lua │ │ ├── bisect.lua │ │ ├── fib.lua │ │ ├── factorial.lua │ │ ├── sieve.lua │ │ ├── trace-calls.lua │ │ ├── trace-globals.lua │ │ ├── README │ │ └── sort.lua │ ├── src │ │ ├── lapi.h │ │ ├── fpconv.h │ │ ├── linit.c │ │ ├── lstring.h │ │ ├── lundump.h │ │ ├── ldebug.h │ │ ├── ltm.h │ │ ├── lualib.h │ │ ├── lfunc.h │ │ ├── lvm.h │ │ ├── ltable.h │ │ ├── lmem.h │ │ ├── lzio.h │ │ ├── ltm.c │ │ ├── lzio.c │ │ ├── ldo.h │ │ ├── llex.h │ │ └── lmem.c │ ├── README │ └── COPYRIGHT ├── hiredis │ ├── .gitignore │ ├── .travis.yml │ ├── zmalloc.h │ ├── fmacros.h │ ├── CHANGELOG.md │ ├── examples │ │ ├── example-libev.c │ │ ├── example-libuv.c │ │ ├── example-libevent.c │ │ └── example-ae.c │ └── COPYING └── update-jemalloc.sh ├── utils ├── hyperloglog │ ├── .gitignore │ └── hll-err.rb ├── releasetools │ ├── 02_upload_tarball.sh │ ├── 01_create_tarball.sh │ ├── 03_release_hash.sh │ └── 00_test_release.sh ├── lru │ ├── README │ └── test-lru.rb ├── build-static-symbols.tcl ├── whatisdoing.sh ├── redis_init_script.tpl ├── redis_init_script ├── redis-copy.rb └── redis-sha1.rb ├── src ├── version.h ├── .gitignore ├── crc64.h ├── valgrind.sup ├── sha1.h ├── mkreleasehdr.sh ├── rand.h ├── pqsort.h ├── bio.h ├── util.h ├── solarisfixes.h ├── release.c ├── slowlog.h ├── fmacros.h ├── redisassert.h ├── intset.h └── sparkline.h ├── BUGS ├── Makefile ├── runtest ├── runtest-cluster ├── runtest-sentinel ├── .gitignore ├── 00-RELEASENOTES ├── COPYING └── CONTRIBUTING /INSTALL: -------------------------------------------------------------------------------- 1 | See README 2 | -------------------------------------------------------------------------------- /tests/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /deps/jemalloc/config.stamp.in: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /utils/hyperloglog/.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #define REDIS_VERSION "2.9.999" 2 | -------------------------------------------------------------------------------- /tests/cluster/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | redis_* 2 | sentinel_* 3 | -------------------------------------------------------------------------------- /tests/sentinel/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | redis_* 2 | sentinel_* 3 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | Please check https://github.com/antirez/redis/issues 2 | -------------------------------------------------------------------------------- /deps/jemalloc/VERSION: -------------------------------------------------------------------------------- 1 | 3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340 2 | -------------------------------------------------------------------------------- /deps/linenoise/.gitignore: -------------------------------------------------------------------------------- 1 | linenoise_example 2 | *.dSYM 3 | history.txt 4 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.gcda 2 | *.gcno 3 | *.gcov 4 | redis.info 5 | lcov-html 6 | -------------------------------------------------------------------------------- /deps/jemalloc/test/src/math.c: -------------------------------------------------------------------------------- 1 | #define MATH_C_ 2 | #include "test/jemalloc_test.h" 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_accum_a.c: -------------------------------------------------------------------------------- 1 | #include "prof_accum.h" 2 | 3 | alloc_n_gen(0) 4 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_accum_b.c: -------------------------------------------------------------------------------- 1 | #include "prof_accum.h" 2 | 3 | alloc_n_gen(1) 4 | -------------------------------------------------------------------------------- /deps/lua/doc/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/deps/lua/doc/cover.png -------------------------------------------------------------------------------- /deps/lua/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/deps/lua/doc/logo.gif -------------------------------------------------------------------------------- /deps/lua/etc/lua.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/deps/lua/etc/lua.ico -------------------------------------------------------------------------------- /deps/lua/test/life.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/deps/lua/test/life.lua -------------------------------------------------------------------------------- /deps/jemalloc/src/mb.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MB_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /tests/assets/encodings.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/tests/assets/encodings.rdb -------------------------------------------------------------------------------- /tests/sentinel/tests/03-runtime-reconf.tcl: -------------------------------------------------------------------------------- 1 | # Test runtime reconfiguration command SENTINEL SET. 2 | -------------------------------------------------------------------------------- /deps/jemalloc/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /tests/assets/hash-zipmap.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/tests/assets/hash-zipmap.rdb -------------------------------------------------------------------------------- /deps/hiredis/.gitignore: -------------------------------------------------------------------------------- 1 | /hiredis-test 2 | /examples/hiredis-example* 3 | /*.o 4 | /*.so 5 | /*.dylib 6 | /*.a 7 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/jemalloc.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattsta/redis/HEAD/deps/jemalloc/doc/jemalloc.html -------------------------------------------------------------------------------- /deps/jemalloc/src/atomic.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_ATOMIC_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /deps/hiredis/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | script: make && make check 7 | -------------------------------------------------------------------------------- /deps/lua/test/echo.lua: -------------------------------------------------------------------------------- 1 | -- echo command line arguments 2 | 3 | for i=0,table.getn(arg) do 4 | print(i,arg[i]) 5 | end 6 | -------------------------------------------------------------------------------- /deps/lua/test/hello.lua: -------------------------------------------------------------------------------- 1 | -- the first program in every language 2 | 3 | io.write("Hello world, from ",_VERSION,"!\n") 4 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/private_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#undef ${symbol}" 5 | done 6 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/private_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#define ${symbol} JEMALLOC_N(${symbol})" 5 | done 6 | -------------------------------------------------------------------------------- /src/crc64.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC64_H 2 | #define CRC64_H 3 | 4 | #include 5 | 6 | uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /deps/jemalloc/test/include/test/jemalloc_test_defs.h.in: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal_defs.h" 2 | 3 | /* For use by SFMT. */ 4 | #undef HAVE_SSE2 5 | #undef HAVE_ALTIVEC 6 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/public_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#undef je_${n}" 6 | done 7 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/public_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#define je_${n} JEMALLOC_N(${n})" 6 | done 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Top level makefile, the real shit is at src/Makefile 2 | 3 | default: all 4 | 5 | .DEFAULT: 6 | cd src && $(MAKE) $@ 7 | 8 | install: 9 | cd src && $(MAKE) $@ 10 | 11 | .PHONY: install 12 | -------------------------------------------------------------------------------- /deps/lua/test/printf.lua: -------------------------------------------------------------------------------- 1 | -- an implementation of printf 2 | 3 | function printf(...) 4 | io.write(string.format(...)) 5 | end 6 | 7 | printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date()) 8 | -------------------------------------------------------------------------------- /deps/jemalloc/bin/jemalloc.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | 7 | @LD_PRELOAD_VAR@=${libdir}/libjemalloc.@SOREV@ 8 | export @LD_PRELOAD_VAR@ 9 | exec "$@" 10 | -------------------------------------------------------------------------------- /deps/lua/test/env.lua: -------------------------------------------------------------------------------- 1 | -- read environment variables as if they were global variables 2 | 3 | local f=function (t,i) return os.getenv(i) end 4 | setmetatable(getfenv(),{__index=f}) 5 | 6 | -- an example 7 | print(a,USER,PATH) 8 | -------------------------------------------------------------------------------- /tests/unit/printver.tcl: -------------------------------------------------------------------------------- 1 | start_server {} { 2 | set i [r info] 3 | regexp {redis_version:(.*?)\r\n} $i - version 4 | regexp {redis_git_sha1:(.*?)\r\n} $i - sha1 5 | puts "Testing Redis version $version ($sha1)" 6 | } 7 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/html.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/manpages.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /deps/lua/etc/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /tests/sentinel/tests/04-slave-selection.tcl: -------------------------------------------------------------------------------- 1 | # Test slave selection algorithm. 2 | # 3 | # This unit should test: 4 | # 1) That when there are no suitable slaves no failover is performed. 5 | # 2) That among the available slaves, the one with better offset is picked. 6 | -------------------------------------------------------------------------------- /deps/lua/test/luac.lua: -------------------------------------------------------------------------------- 1 | -- bare-bones luac in Lua 2 | -- usage: lua luac.lua file.lua 3 | 4 | assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua") 5 | f=assert(io.open("luac.out","wb")) 6 | assert(f:write(string.dump(assert(loadfile(arg[1]))))) 7 | assert(f:close()) 8 | -------------------------------------------------------------------------------- /tests/unit/type/list-common.tcl: -------------------------------------------------------------------------------- 1 | # We need a value larger than list-max-ziplist-value to make sure 2 | # the list has the right encoding when it is swapped in again. 3 | array set largevalue {} 4 | set largevalue(ziplist) "hello" 5 | set largevalue(linkedlist) [string repeat "hello" 4] 6 | -------------------------------------------------------------------------------- /deps/jemalloc/test/include/test/thd.h: -------------------------------------------------------------------------------- 1 | /* Abstraction layer for threading in tests */ 2 | #ifdef _WIN32 3 | typedef HANDLE thd_t; 4 | #else 5 | typedef pthread_t thd_t; 6 | #endif 7 | 8 | void thd_create(thd_t *thd, void *(*proc)(void *), void *arg); 9 | void thd_join(thd_t thd, void **ret); 10 | -------------------------------------------------------------------------------- /src/valgrind.sup: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Cond 4 | fun:lzf_compress 5 | } 6 | 7 | { 8 | 9 | Memcheck:Value4 10 | fun:lzf_compress 11 | } 12 | 13 | { 14 | 15 | Memcheck:Value8 16 | fun:lzf_compress 17 | } 18 | -------------------------------------------------------------------------------- /deps/lua/test/fibfor.lua: -------------------------------------------------------------------------------- 1 | -- example of for with generator functions 2 | 3 | function generatefib (n) 4 | return coroutine.wrap(function () 5 | local a,b = 1, 1 6 | while a <= n do 7 | coroutine.yield(a) 8 | a, b = b, a+b 9 | end 10 | end) 11 | end 12 | 13 | for i in generatefib(1000) do print(i) end 14 | -------------------------------------------------------------------------------- /deps/lua/test/readonly.lua: -------------------------------------------------------------------------------- 1 | -- make global variables readonly 2 | 3 | local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end 4 | local g={} 5 | local G=getfenv() 6 | setmetatable(g,{__index=G,__newindex=f}) 7 | setfenv(1,g) 8 | 9 | -- an example 10 | rawset(g,"x",3) 11 | x=2 12 | y=1 -- cannot redefine `y' 13 | -------------------------------------------------------------------------------- /deps/update-jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | VER=$1 3 | URL="http://www.canonware.com/download/jemalloc/jemalloc-${VER}.tar.bz2" 4 | echo "Downloading $URL" 5 | curl $URL > /tmp/jemalloc.tar.bz2 6 | tar xvjf /tmp/jemalloc.tar.bz2 7 | rm -rf jemalloc 8 | mv jemalloc-${VER} jemalloc 9 | echo "Use git status, add all files and commit changes." 10 | -------------------------------------------------------------------------------- /runtest: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis test" 12 | exit 1 13 | fi 14 | $TCLSH tests/test_helper.tcl $* 15 | -------------------------------------------------------------------------------- /deps/hiredis/zmalloc.h: -------------------------------------------------------------------------------- 1 | /* Drop in replacement for zmalloc.h in order to just use libc malloc without 2 | * any wrappering. */ 3 | 4 | #ifndef ZMALLOC_H 5 | #define ZMALLOC_H 6 | 7 | #define zmalloc malloc 8 | #define zrealloc realloc 9 | #define zcalloc(x) calloc(x,1) 10 | #define zfree free 11 | #define zstrdup strdup 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/helpers/bg_complex_data.tcl: -------------------------------------------------------------------------------- 1 | source tests/support/redis.tcl 2 | source tests/support/util.tcl 3 | 4 | proc bg_complex_data {host port db ops} { 5 | set r [redis $host $port] 6 | $r select $db 7 | createComplexDataset $r $ops 8 | } 9 | 10 | bg_complex_data [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] 11 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/stylesheet.xsl: -------------------------------------------------------------------------------- 1 | 2 | ansi 3 | 4 | 5 | "" 6 | 7 | 8 | -------------------------------------------------------------------------------- /deps/lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/lua/test/table.lua: -------------------------------------------------------------------------------- 1 | -- make table, grouping all data for the same item 2 | -- input is 2 columns (item, data) 3 | 4 | local A 5 | while 1 do 6 | local l=io.read() 7 | if l==nil then break end 8 | local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$') 9 | if a~=A then A=a io.write("\n",a,":") end 10 | io.write(" ",b) 11 | end 12 | io.write("\n") 13 | -------------------------------------------------------------------------------- /runtest-cluster: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test" 12 | exit 1 13 | fi 14 | $TCLSH tests/cluster/run.tcl $* 15 | -------------------------------------------------------------------------------- /runtest-sentinel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test" 12 | exit 1 13 | fi 14 | $TCLSH tests/sentinel/run.tcl $* 15 | -------------------------------------------------------------------------------- /utils/releasetools/02_upload_tarball.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Uploading..." 3 | scp /tmp/redis-${1}.tar.gz antirez@antirez.com:/var/virtual/download.redis.io/httpdocs/releases/ 4 | echo "Updating web site... (press any key if it is a stable release, or Ctrl+C)" 5 | read x 6 | ssh antirez@antirez.com "cd /var/virtual/download.redis.io/httpdocs; ./update.sh ${1}" 7 | -------------------------------------------------------------------------------- /deps/jemalloc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in autoconf; do 4 | echo "$i" 5 | $i 6 | if [ $? -ne 0 ]; then 7 | echo "Error $? in $i" 8 | exit 1 9 | fi 10 | done 11 | 12 | echo "./configure --enable-autogen $@" 13 | ./configure --enable-autogen $@ 14 | if [ $? -ne 0 ]; then 15 | echo "Error $? in ./configure" 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /deps/lua/test/cf.lua: -------------------------------------------------------------------------------- 1 | -- temperature conversion table (celsius to farenheit) 2 | 3 | for c0=-20,50-1,10 do 4 | io.write("C ") 5 | for c=c0,c0+10-1 do 6 | io.write(string.format("%3.0f ",c)) 7 | end 8 | io.write("\n") 9 | 10 | io.write("F ") 11 | for c=c0,c0+10-1 do 12 | f=(9/5)*c+32 13 | io.write(string.format("%3.0f ",f)) 14 | end 15 | io.write("\n\n") 16 | end 17 | -------------------------------------------------------------------------------- /deps/jemalloc/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | objdir=$1 6 | suffix=$2 7 | shift 2 8 | objs=$@ 9 | 10 | gcov -b -p -f -o "${objdir}" ${objs} 11 | 12 | # Move gcov outputs so that subsequent gcov invocations won't clobber results 13 | # for the same sources with different compilation flags. 14 | for f in `find . -maxdepth 1 -type f -name '*.gcov'` ; do 15 | mv "${f}" "${f}.${suffix}" 16 | done 17 | -------------------------------------------------------------------------------- /utils/releasetools/01_create_tarball.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ $# != "1" ] 3 | then 4 | echo "Usage: ./mkrelease.sh " 5 | exit 1 6 | fi 7 | 8 | TAG=$1 9 | TARNAME="redis-${TAG}.tar" 10 | echo "Generating /tmp/${TARNAME}" 11 | cd ~/hack/redis 12 | git archive $TAG --prefix redis-${TAG}/ > /tmp/$TARNAME || exit 1 13 | echo "Gizipping the archive" 14 | rm -f /tmp/$TARNAME.gz 15 | gzip -9 /tmp/$TARNAME 16 | -------------------------------------------------------------------------------- /deps/linenoise/Makefile: -------------------------------------------------------------------------------- 1 | STD= 2 | WARN= -Wall 3 | OPT= -Os 4 | 5 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) 6 | R_LDFLAGS= $(LDFLAGS) 7 | DEBUG= -g 8 | 9 | R_CC=$(CC) $(R_CFLAGS) 10 | R_LD=$(CC) $(R_LDFLAGS) 11 | 12 | linenoise.o: linenoise.h linenoise.c 13 | 14 | linenoise_example: linenoise.o example.o 15 | $(R_LD) -o $@ $^ 16 | 17 | .c.o: 18 | $(R_CC) -c $< 19 | 20 | clean: 21 | rm -f linenoise_example *.o 22 | -------------------------------------------------------------------------------- /deps/jemalloc/include/msvc_compat/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef stdbool_h 2 | #define stdbool_h 3 | 4 | #include 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | typedef BOOL _Bool; 9 | 10 | #define bool _Bool 11 | #define true 1 12 | #define false 0 13 | 14 | #define __bool_true_false_are_defined 1 15 | 16 | #endif /* stdbool_h */ 17 | -------------------------------------------------------------------------------- /deps/lua/test/xd.lua: -------------------------------------------------------------------------------- 1 | -- hex dump 2 | -- usage: lua xd.lua < file 3 | 4 | local offset=0 5 | while true do 6 | local s=io.read(16) 7 | if s==nil then return end 8 | io.write(string.format("%08X ",offset)) 9 | string.gsub(s,"(.)", 10 | function (c) io.write(string.format("%02X ",string.byte(c))) end) 11 | io.write(string.rep(" ",3*(16-string.len(s)))) 12 | io.write(" ",string.gsub(s,"%c","."),"\n") 13 | offset=offset+16 14 | end 15 | -------------------------------------------------------------------------------- /utils/releasetools/03_release_hash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SHA=$(curl -s http://download.redis.io/releases/redis-${1}.tar.gz | shasum | cut -f 1 -d' ') 3 | ENTRY="hash redis-${1}.tar.gz sha1 $SHA http://download.redis.io/releases/redis-${1}.tar.gz" 4 | echo $ENTRY >> ~/hack/redis-hashes/README 5 | vi ~/hack/redis-hashes/README 6 | echo "Press any key to commit, Ctrl-C to abort)." 7 | read yes 8 | (cd ~/hack/redis-hashes; git commit -a -m "${1} hash."; git push) 9 | -------------------------------------------------------------------------------- /tests/helpers/gen_write_load.tcl: -------------------------------------------------------------------------------- 1 | source tests/support/redis.tcl 2 | 3 | proc gen_write_load {host port seconds} { 4 | set start_time [clock seconds] 5 | set r [redis $host $port 1] 6 | $r select 9 7 | while 1 { 8 | $r set [expr rand()] [expr rand()] 9 | if {[clock seconds]-$start_time > $seconds} { 10 | exit 0 11 | } 12 | } 13 | } 14 | 15 | gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] 16 | -------------------------------------------------------------------------------- /deps/lua/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | padding-top: 0.4em ; 20 | padding-bottom: 0.4em ; 21 | padding-left: 30px ; 22 | margin-left: -30px ; 23 | background-color: #E0E0FF ; 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | *.o 3 | *.log 4 | dump.rdb 5 | redis-benchmark 6 | redis-check-aof 7 | redis-check-dump 8 | redis-cli 9 | redis-sentinel 10 | redis-server 11 | doc-tools 12 | release 13 | misc/* 14 | src/release.h 15 | appendonly.aof 16 | SHORT_TERM_TODO 17 | release.h 18 | src/transfer.sh 19 | src/configs 20 | redis.ds 21 | src/redis.conf 22 | src/nodes.conf 23 | deps/lua/src/lua 24 | deps/lua/src/luac 25 | deps/lua/src/liblua.a 26 | .make-* 27 | .prerequisites 28 | *.dSYM 29 | -------------------------------------------------------------------------------- /tests/support/tmpfile.tcl: -------------------------------------------------------------------------------- 1 | set ::tmpcounter 0 2 | set ::tmproot "./tests/tmp" 3 | file mkdir $::tmproot 4 | 5 | # returns a dirname unique to this process to write to 6 | proc tmpdir {basename} { 7 | set dir [file join $::tmproot $basename.[pid].[incr ::tmpcounter]] 8 | file mkdir $dir 9 | set _ $dir 10 | } 11 | 12 | # return a filename unique to this process to write to 13 | proc tmpfile {basename} { 14 | file join $::tmproot $basename.[pid].[incr ::tmpcounter] 15 | } 16 | -------------------------------------------------------------------------------- /deps/lua/test/globals.lua: -------------------------------------------------------------------------------- 1 | -- reads luac listings and reports global variable usage 2 | -- lines where a global is written to are marked with "*" 3 | -- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua 4 | 5 | while 1 do 6 | local s=io.read() 7 | if s==nil then break end 8 | local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$") 9 | if ok then 10 | if op=="S" then op="*" else op="" end 11 | io.write(g,"\t",l,op,"\n") 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /deps/jemalloc/include/msvc_compat/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef strings_h 2 | #define strings_h 3 | 4 | /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided 5 | * for both */ 6 | #include 7 | #pragma intrinsic(_BitScanForward) 8 | static __forceinline int ffsl(long x) 9 | { 10 | unsigned long i; 11 | 12 | if (_BitScanForward(&i, x)) 13 | return (i + 1); 14 | return (0); 15 | } 16 | 17 | static __forceinline int ffs(int x) 18 | { 19 | 20 | return (ffsl(x)); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tests/unit/limits.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"limits"} overrides {maxclients 10}} { 2 | test {Check if maxclients works refusing connections} { 3 | set c 0 4 | catch { 5 | while {$c < 50} { 6 | incr c 7 | set rd [redis_deferring_client] 8 | $rd ping 9 | $rd read 10 | after 100 11 | } 12 | } e 13 | assert {$c > 8 && $c <= 10} 14 | set e 15 | } {*ERR max*reached*} 16 | } 17 | -------------------------------------------------------------------------------- /deps/hiredis/fmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_FMACRO_H 2 | #define __HIREDIS_FMACRO_H 3 | 4 | #if !defined(_BSD_SOURCE) 5 | #define _BSD_SOURCE 6 | #endif 7 | 8 | #if defined(_AIX) 9 | #define _ALL_SOURCE 10 | #endif 11 | 12 | #if defined(__sun__) 13 | #define _POSIX_C_SOURCE 200112L 14 | #elif defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) 15 | #define _XOPEN_SOURCE 600 16 | #else 17 | #define _XOPEN_SOURCE 18 | #endif 19 | 20 | #if __APPLE__ && __MACH__ 21 | #define _OSX 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tests/assets/default.conf: -------------------------------------------------------------------------------- 1 | # Redis configuration for testing. 2 | 3 | notify-keyspace-events KEA 4 | daemonize no 5 | pidfile /var/run/redis.pid 6 | port 6379 7 | timeout 0 8 | bind 127.0.0.1 9 | loglevel verbose 10 | logfile '' 11 | databases 16 12 | latency-monitor-threshold 1 13 | 14 | save 900 1 15 | save 300 10 16 | save 60 10000 17 | 18 | rdbcompression yes 19 | dbfilename dump.rdb 20 | dir ./ 21 | 22 | slave-serve-stale-data yes 23 | appendonly no 24 | appendfsync everysec 25 | no-appendfsync-on-rewrite no 26 | activerehashing yes 27 | -------------------------------------------------------------------------------- /src/sha1.h: -------------------------------------------------------------------------------- 1 | /* ================ sha1.h ================ */ 2 | /* 3 | SHA-1 in C 4 | By Steve Reid 5 | 100% Public Domain 6 | */ 7 | 8 | typedef struct { 9 | u_int32_t state[5]; 10 | u_int32_t count[2]; 11 | unsigned char buffer[64]; 12 | } SHA1_CTX; 13 | 14 | void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]); 15 | void SHA1Init(SHA1_CTX* context); 16 | void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len); 17 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 18 | -------------------------------------------------------------------------------- /tests/cluster/tests/helpers/onlydots.tcl: -------------------------------------------------------------------------------- 1 | # Read the standard input and only shows dots in the output, filtering out 2 | # all the other characters. Designed to avoid bufferization so that when 3 | # we get the output of redis-trib and want to show just the dots, we'll see 4 | # the dots as soon as redis-trib will output them. 5 | 6 | fconfigure stdin -buffering none 7 | 8 | while 1 { 9 | set c [read stdin 1] 10 | if {$c eq {}} { 11 | exit 0; # EOF 12 | } elseif {$c eq {.}} { 13 | puts -nonewline . 14 | flush stdout 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /utils/lru/README: -------------------------------------------------------------------------------- 1 | The test-lru.rb program can be used in order to check the behavior of the 2 | Redis approximated LRU algorithm against the theoretical output of true 3 | LRU algorithm. 4 | 5 | In order to use the program you need to recompile Redis setting the define 6 | REDIS_LRU_CLOCK_RESOLUTION to 1, by editing redis.h. 7 | This allows to execute the program in a fast way since the 1 ms resolution 8 | is enough for all the objects to have a different enough time stamp during 9 | the test. 10 | 11 | The program is executed like this: 12 | 13 | ruby test-lru.rb > /tmp/lru.html 14 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/jemalloc_rename.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | public_symbols_txt=$1 4 | 5 | cat < /dev/null || echo 00000000) | head -n1` 3 | GIT_DIRTY=`git diff --no-ext-diff 2> /dev/null | wc -l` 4 | BUILD_ID=`uname -n`"-"`date +%s` 5 | test -f release.h || touch release.h 6 | (cat release.h | grep SHA1 | grep $GIT_SHA1) && \ 7 | (cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already up-to-date 8 | echo "#define REDIS_GIT_SHA1 \"$GIT_SHA1\"" > release.h 9 | echo "#define REDIS_GIT_DIRTY \"$GIT_DIRTY\"" >> release.h 10 | echo "#define REDIS_BUILD_ID \"$BUILD_ID\"" >> release.h 11 | touch release.c # Force recompile of release.c 12 | -------------------------------------------------------------------------------- /deps/lua/src/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | # define FPCONV_G_FMT_BUFSIZE 32 8 | 9 | #ifdef USE_INTERNAL_FPCONV 10 | static inline void fpconv_init() 11 | { 12 | /* Do nothing - not required */ 13 | } 14 | #else 15 | extern void fpconv_init(); 16 | #endif 17 | 18 | extern int fpconv_g_fmt(char*, double, int); 19 | extern double fpconv_strtod(const char*, char**); 20 | 21 | /* vi:ai et sw=4 ts=4: 22 | */ 23 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | objroot=$1 4 | 5 | cat <" 5 | exit 1 6 | fi 7 | 8 | TAG=$1 9 | TARNAME="redis-${TAG}.tar.gz" 10 | DOWNLOADURL="http://download.redis.io/releases/${TARNAME}" 11 | 12 | ssh antirez@metal "export TERM=xterm; 13 | cd /tmp; 14 | rm -rf test_release_tmp_dir; 15 | cd test_release_tmp_dir; 16 | wget $DOWNLOADURL; 17 | tar xvzf $TARNAME; 18 | cd redis-${TAG}; 19 | make; 20 | ./runtest; 21 | ./runtest-sentinel; 22 | if [ -x runtest-cluster ]; then 23 | ./runtest-cluster; 24 | fi" 25 | -------------------------------------------------------------------------------- /deps/lua/test/fib.lua: -------------------------------------------------------------------------------- 1 | -- fibonacci function with cache 2 | 3 | -- very inefficient fibonacci function 4 | function fib(n) 5 | N=N+1 6 | if n<2 then 7 | return n 8 | else 9 | return fib(n-1)+fib(n-2) 10 | end 11 | end 12 | 13 | -- a general-purpose value cache 14 | function cache(f) 15 | local c={} 16 | return function (x) 17 | local y=c[x] 18 | if not y then 19 | y=f(x) 20 | c[x]=y 21 | end 22 | return y 23 | end 24 | end 25 | 26 | -- run and time it 27 | function test(s,f) 28 | N=0 29 | local c=os.clock() 30 | local v=f(n) 31 | local t=os.clock()-c 32 | print(s,n,v,t,N) 33 | end 34 | 35 | n=arg[1] or 24 -- for other values, do lua fib.lua XX 36 | n=tonumber(n) 37 | print("","n","value","time","evals") 38 | test("plain",fib) 39 | fib=cache(fib) 40 | test("cached",fib) 41 | -------------------------------------------------------------------------------- /deps/lua/etc/lua.pc: -------------------------------------------------------------------------------- 1 | # lua.pc -- pkg-config data for Lua 2 | 3 | # vars from install Makefile 4 | 5 | # grep '^V=' ../Makefile 6 | V= 5.1 7 | # grep '^R=' ../Makefile 8 | R= 5.1.5 9 | 10 | # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' 11 | prefix= /usr/local 12 | INSTALL_BIN= ${prefix}/bin 13 | INSTALL_INC= ${prefix}/include 14 | INSTALL_LIB= ${prefix}/lib 15 | INSTALL_MAN= ${prefix}/man/man1 16 | INSTALL_LMOD= ${prefix}/share/lua/${V} 17 | INSTALL_CMOD= ${prefix}/lib/lua/${V} 18 | 19 | # canonical vars 20 | exec_prefix=${prefix} 21 | libdir=${exec_prefix}/lib 22 | includedir=${prefix}/include 23 | 24 | Name: Lua 25 | Description: An Extensible Extension Language 26 | Version: ${R} 27 | Requires: 28 | Libs: -L${libdir} -llua -lm 29 | Cflags: -I${includedir} 30 | 31 | # (end of lua.pc) 32 | -------------------------------------------------------------------------------- /utils/whatisdoing.sh: -------------------------------------------------------------------------------- 1 | # This script is from http://poormansprofiler.org/ 2 | # 3 | # NOTE: Instead of using this script, you should use the Redis 4 | # Software Watchdog, which provides a similar functionality but in 5 | # a more reliable / easy to use way. 6 | # 7 | # Check http://redis.io/topics/latency for more information. 8 | 9 | #!/bin/bash 10 | nsamples=1 11 | sleeptime=0 12 | pid=$(ps auxww | grep '[r]edis-server' | awk '{print $2}') 13 | 14 | for x in $(seq 1 $nsamples) 15 | do 16 | gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid 17 | sleep $sleeptime 18 | done | \ 19 | awk ' 20 | BEGIN { s = ""; } 21 | /Thread/ { print s; s = ""; } 22 | /^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } } 23 | END { print s }' | \ 24 | sort | uniq -c | sort -r -n -k 1,1 25 | -------------------------------------------------------------------------------- /deps/hiredis/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 0.11.0 2 | 3 | * Increase the maximum multi-bulk reply depth to 7. 4 | 5 | * Increase the read buffer size from 2k to 16k. 6 | 7 | * Use poll(2) instead of select(2) to support large fds (>= 1024). 8 | 9 | ### 0.10.1 10 | 11 | * Makefile overhaul. Important to check out if you override one or more 12 | variables using environment variables or via arguments to the "make" tool. 13 | 14 | * Issue #45: Fix potential memory leak for a multi bulk reply with 0 elements 15 | being created by the default reply object functions. 16 | 17 | * Issue #43: Don't crash in an asynchronous context when Redis returns an error 18 | reply after the connection has been made (this happens when the maximum 19 | number of connections is reached). 20 | 21 | ### 0.10.0 22 | 23 | * See commit log. 24 | 25 | -------------------------------------------------------------------------------- /deps/lua/etc/all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * all.c -- Lua core, libraries and interpreter in a single file 3 | */ 4 | 5 | #define luaall_c 6 | 7 | #include "lapi.c" 8 | #include "lcode.c" 9 | #include "ldebug.c" 10 | #include "ldo.c" 11 | #include "ldump.c" 12 | #include "lfunc.c" 13 | #include "lgc.c" 14 | #include "llex.c" 15 | #include "lmem.c" 16 | #include "lobject.c" 17 | #include "lopcodes.c" 18 | #include "lparser.c" 19 | #include "lstate.c" 20 | #include "lstring.c" 21 | #include "ltable.c" 22 | #include "ltm.c" 23 | #include "lundump.c" 24 | #include "lvm.c" 25 | #include "lzio.c" 26 | 27 | #include "lauxlib.c" 28 | #include "lbaselib.c" 29 | #include "ldblib.c" 30 | #include "liolib.c" 31 | #include "linit.c" 32 | #include "lmathlib.c" 33 | #include "loadlib.c" 34 | #include "loslib.c" 35 | #include "lstrlib.c" 36 | #include "ltablib.c" 37 | 38 | #include "lua.c" 39 | -------------------------------------------------------------------------------- /deps/lua/test/factorial.lua: -------------------------------------------------------------------------------- 1 | -- function closures are powerful 2 | 3 | -- traditional fixed-point operator from functional programming 4 | Y = function (g) 5 | local a = function (f) return f(f) end 6 | return a(function (f) 7 | return g(function (x) 8 | local c=f(f) 9 | return c(x) 10 | end) 11 | end) 12 | end 13 | 14 | 15 | -- factorial without recursion 16 | F = function (f) 17 | return function (n) 18 | if n == 0 then return 1 19 | else return n*f(n-1) end 20 | end 21 | end 22 | 23 | factorial = Y(F) -- factorial is the fixed point of F 24 | 25 | -- now test it 26 | function test(x) 27 | io.write(x,"! = ",factorial(x),"\n") 28 | end 29 | 30 | for n=0,16 do 31 | test(n) 32 | end 33 | -------------------------------------------------------------------------------- /tests/unit/auth.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"auth"}} { 2 | test {AUTH fails if there is no password configured server side} { 3 | catch {r auth foo} err 4 | set _ $err 5 | } {ERR*no password*} 6 | } 7 | 8 | start_server {tags {"auth"} overrides {requirepass foobar}} { 9 | test {AUTH fails when a wrong password is given} { 10 | catch {r auth wrong!} err 11 | set _ $err 12 | } {ERR*invalid password} 13 | 14 | test {Arbitrary command gives an error when AUTH is required} { 15 | catch {r set foo bar} err 16 | set _ $err 17 | } {NOAUTH*} 18 | 19 | test {AUTH succeeds when the right password is given} { 20 | r auth foobar 21 | } {OK} 22 | 23 | test {Once AUTH succeeded we can actually send commands to the server} { 24 | r set foo 100 25 | r incr foo 26 | } {101} 27 | } 28 | -------------------------------------------------------------------------------- /deps/lua/test/sieve.lua: -------------------------------------------------------------------------------- 1 | -- the sieve of of Eratosthenes programmed with coroutines 2 | -- typical usage: lua -e N=1000 sieve.lua | column 3 | 4 | -- generate all the numbers from 2 to n 5 | function gen (n) 6 | return coroutine.wrap(function () 7 | for i=2,n do coroutine.yield(i) end 8 | end) 9 | end 10 | 11 | -- filter the numbers generated by `g', removing multiples of `p' 12 | function filter (p, g) 13 | return coroutine.wrap(function () 14 | while 1 do 15 | local n = g() 16 | if n == nil then return end 17 | if math.mod(n, p) ~= 0 then coroutine.yield(n) end 18 | end 19 | end) 20 | end 21 | 22 | N=N or 1000 -- from command line 23 | x = gen(N) -- generate primes up to N 24 | while 1 do 25 | local n = x() -- pick a number until done 26 | if n == nil then break end 27 | print(n) -- must be a prime number 28 | x = filter(n, x) -- now remove its multiples 29 | end 30 | -------------------------------------------------------------------------------- /deps/lua/test/trace-calls.lua: -------------------------------------------------------------------------------- 1 | -- trace calls 2 | -- example: lua -ltrace-calls bisect.lua 3 | 4 | local level=0 5 | 6 | local function hook(event) 7 | local t=debug.getinfo(3) 8 | io.write(level," >>> ",string.rep(" ",level)) 9 | if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end 10 | t=debug.getinfo(2) 11 | if event=="call" then 12 | level=level+1 13 | else 14 | level=level-1 if level<0 then level=0 end 15 | end 16 | if t.what=="main" then 17 | if event=="call" then 18 | io.write("begin ",t.short_src) 19 | else 20 | io.write("end ",t.short_src) 21 | end 22 | elseif t.what=="Lua" then 23 | -- table.foreach(t,print) 24 | io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") 25 | else 26 | io.write(event," ",t.name or "(C)"," [",t.what,"] ") 27 | end 28 | io.write("\n") 29 | end 30 | 31 | debug.sethook(hook,"cr") 32 | level=0 33 | -------------------------------------------------------------------------------- /deps/lua/test/trace-globals.lua: -------------------------------------------------------------------------------- 1 | -- trace assigments to global variables 2 | 3 | do 4 | -- a tostring that quotes strings. note the use of the original tostring. 5 | local _tostring=tostring 6 | local tostring=function(a) 7 | if type(a)=="string" then 8 | return string.format("%q",a) 9 | else 10 | return _tostring(a) 11 | end 12 | end 13 | 14 | local log=function (name,old,new) 15 | local t=debug.getinfo(3,"Sl") 16 | local line=t.currentline 17 | io.write(t.short_src) 18 | if line>=0 then io.write(":",line) end 19 | io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") 20 | end 21 | 22 | local g={} 23 | local set=function (t,name,value) 24 | log(name,g[name],value) 25 | g[name]=value 26 | end 27 | setmetatable(getfenv(),{__index=g,__newindex=set}) 28 | end 29 | 30 | -- an example 31 | 32 | a=1 33 | b=2 34 | a=10 35 | b=20 36 | b=nil 37 | b=200 38 | print(a,b,c) 39 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk_mmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | bool pages_purge(void *addr, size_t length); 13 | 14 | void *chunk_alloc_mmap(size_t size, size_t alignment, bool *zero); 15 | bool chunk_dealloc_mmap(void *chunk, size_t size); 16 | 17 | #endif /* JEMALLOC_H_EXTERNS */ 18 | /******************************************************************************/ 19 | #ifdef JEMALLOC_H_INLINES 20 | 21 | #endif /* JEMALLOC_H_INLINES */ 22 | /******************************************************************************/ 23 | -------------------------------------------------------------------------------- /deps/lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tests/cluster/tests/01-faildet.tcl: -------------------------------------------------------------------------------- 1 | # Check the basic monitoring and failover capabilities. 2 | 3 | source "../tests/includes/init-tests.tcl" 4 | 5 | test "Create a 5 nodes cluster" { 6 | create_cluster 5 5 7 | } 8 | 9 | test "Cluster should start ok" { 10 | assert_cluster_state ok 11 | } 12 | 13 | test "Killing two slave nodes" { 14 | kill_instance redis 5 15 | kill_instance redis 6 16 | } 17 | 18 | test "Cluster should be still up" { 19 | assert_cluster_state ok 20 | } 21 | 22 | test "Killing one master node" { 23 | kill_instance redis 0 24 | } 25 | 26 | # Note: the only slave of instance 0 is already down so no 27 | # failover is possible, that would change the state back to ok. 28 | test "Cluster should be down now" { 29 | assert_cluster_state fail 30 | } 31 | 32 | test "Restarting master node" { 33 | restart_instance redis 0 34 | } 35 | 36 | test "Cluster should be up again" { 37 | assert_cluster_state ok 38 | } 39 | -------------------------------------------------------------------------------- /deps/lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_accum.h: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 4 4 | #define NALLOCS_PER_THREAD 50 5 | #define DUMP_INTERVAL 1 6 | #define BT_COUNT_CHECK_INTERVAL 5 7 | 8 | #define alloc_n_proto(n) \ 9 | void *alloc_##n(unsigned bits); 10 | alloc_n_proto(0) 11 | alloc_n_proto(1) 12 | 13 | #define alloc_n_gen(n) \ 14 | void * \ 15 | alloc_##n(unsigned bits) \ 16 | { \ 17 | void *p; \ 18 | \ 19 | if (bits == 0) \ 20 | p = mallocx(1, 0); \ 21 | else { \ 22 | switch (bits & 0x1U) { \ 23 | case 0: \ 24 | p = (alloc_0(bits >> 1)); \ 25 | break; \ 26 | case 1: \ 27 | p = (alloc_1(bits >> 1)); \ 28 | break; \ 29 | default: not_reached(); \ 30 | } \ 31 | } \ 32 | /* Intentionally sabotage tail call optimization. */ \ 33 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ 34 | return (p); \ 35 | } 36 | -------------------------------------------------------------------------------- /deps/lua/etc/min.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int print(lua_State *L) 13 | { 14 | int n=lua_gettop(L); 15 | int i; 16 | for (i=1; i<=n; i++) 17 | { 18 | if (i>1) printf("\t"); 19 | if (lua_isstring(L,i)) 20 | printf("%s",lua_tostring(L,i)); 21 | else if (lua_isnil(L,i)) 22 | printf("%s","nil"); 23 | else if (lua_isboolean(L,i)) 24 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 25 | else 26 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 27 | } 28 | printf("\n"); 29 | return 0; 30 | } 31 | 32 | int main(void) 33 | { 34 | lua_State *L=lua_open(); 35 | lua_register(L,"print",print); 36 | if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 37 | lua_close(L); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /deps/lua/doc/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua documentation 4 | 5 | 6 | 7 | 8 | 9 |
10 |

11 | Lua 12 | Documentation 13 |

14 | 15 | This is the documentation included in the source distribution of Lua 5.1.5. 16 | 17 | 25 | 26 | Lua's 27 | official web site 28 | contains updated documentation, 29 | especially the 30 | reference manual. 31 |

32 | 33 |


34 | 35 | Last update: 36 | Fri Feb 3 09:44:42 BRST 2012 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/base.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *base_alloc(size_t size); 13 | void *base_calloc(size_t number, size_t size); 14 | extent_node_t *base_node_alloc(void); 15 | void base_node_dealloc(extent_node_t *node); 16 | bool base_boot(void); 17 | void base_prefork(void); 18 | void base_postfork_parent(void); 19 | void base_postfork_child(void); 20 | 21 | #endif /* JEMALLOC_H_EXTERNS */ 22 | /******************************************************************************/ 23 | #ifdef JEMALLOC_H_INLINES 24 | 25 | #endif /* JEMALLOC_H_INLINES */ 26 | /******************************************************************************/ 27 | -------------------------------------------------------------------------------- /deps/lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /deps/lua/etc/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua etc 2 | 3 | TOP= .. 4 | LIB= $(TOP)/src 5 | INC= $(TOP)/src 6 | BIN= $(TOP)/src 7 | SRC= $(TOP)/src 8 | TST= $(TOP)/test 9 | 10 | CC= gcc 11 | CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS) 12 | MYCFLAGS= 13 | MYLDFLAGS= -Wl,-E 14 | MYLIBS= -lm 15 | #MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses 16 | RM= rm -f 17 | 18 | default: 19 | @echo 'Please choose a target: min noparser one strict clean' 20 | 21 | min: min.c 22 | $(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS) 23 | echo 'print"Hello there!"' | ./a.out 24 | 25 | noparser: noparser.o 26 | $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS) 27 | $(BIN)/luac $(TST)/hello.lua 28 | -./a.out luac.out 29 | -./a.out -e'a=1' 30 | 31 | one: 32 | $(CC) $(CFLAGS) all.c $(MYLIBS) 33 | ./a.out $(TST)/hello.lua 34 | 35 | strict: 36 | -$(BIN)/lua -e 'print(a);b=2' 37 | -$(BIN)/lua -lstrict -e 'print(a)' 38 | -$(BIN)/lua -e 'function f() b=2 end f()' 39 | -$(BIN)/lua -lstrict -e 'function f() b=2 end f()' 40 | 41 | clean: 42 | $(RM) a.out core core.* *.o luac.out 43 | 44 | .PHONY: default min noparser one strict clean 45 | -------------------------------------------------------------------------------- /deps/lua/etc/strict.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- strict.lua 3 | -- checks uses of undeclared global variables 4 | -- All global variables must be 'declared' through a regular assignment 5 | -- (even assigning nil will do) in a main chunk before being used 6 | -- anywhere or assigned to inside a function. 7 | -- 8 | 9 | local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget 10 | 11 | local mt = getmetatable(_G) 12 | if mt == nil then 13 | mt = {} 14 | setmetatable(_G, mt) 15 | end 16 | 17 | mt.__declared = {} 18 | 19 | local function what () 20 | local d = getinfo(3, "S") 21 | return d and d.what or "C" 22 | end 23 | 24 | mt.__newindex = function (t, n, v) 25 | if not mt.__declared[n] then 26 | local w = what() 27 | if w ~= "main" and w ~= "C" then 28 | error("assign to undeclared variable '"..n.."'", 2) 29 | end 30 | mt.__declared[n] = true 31 | end 32 | rawset(t, n, v) 33 | end 34 | 35 | mt.__index = function (t, n) 36 | if not mt.__declared[n] and what() ~= "C" then 37 | error("variable '"..n.."' is not declared", 2) 38 | end 39 | return rawget(t, n) 40 | end 41 | 42 | -------------------------------------------------------------------------------- /deps/lua/etc/README: -------------------------------------------------------------------------------- 1 | This directory contains some useful files and code. 2 | Unlike the code in ../src, everything here is in the public domain. 3 | 4 | If any of the makes fail, you're probably not using the same libraries 5 | used to build Lua. Set MYLIBS in Makefile accordingly. 6 | 7 | all.c 8 | Full Lua interpreter in a single file. 9 | Do "make one" for a demo. 10 | 11 | lua.hpp 12 | Lua header files for C++ using 'extern "C"'. 13 | 14 | lua.ico 15 | A Lua icon for Windows (and web sites: save as favicon.ico). 16 | Drawn by hand by Markus Gritsch . 17 | 18 | lua.pc 19 | pkg-config data for Lua 20 | 21 | luavs.bat 22 | Script to build Lua under "Visual Studio .NET Command Prompt". 23 | Run it from the toplevel as etc\luavs.bat. 24 | 25 | min.c 26 | A minimal Lua interpreter. 27 | Good for learning and for starting your own. 28 | Do "make min" for a demo. 29 | 30 | noparser.c 31 | Linking with noparser.o avoids loading the parsing modules in lualib.a. 32 | Do "make noparser" for a demo. 33 | 34 | strict.lua 35 | Traps uses of undeclared global variables. 36 | Do "make strict" for a demo. 37 | 38 | -------------------------------------------------------------------------------- /tests/unit/memefficiency.tcl: -------------------------------------------------------------------------------- 1 | proc test_memory_efficiency {range} { 2 | r flushall 3 | set base_mem [s used_memory] 4 | set written 0 5 | for {set j 0} {$j < 10000} {incr j} { 6 | set key key:$j 7 | set val [string repeat A [expr {int(rand()*$range)}]] 8 | r set $key $val 9 | incr written [string length $key] 10 | incr written [string length $val] 11 | incr written 2 ;# A separator is the minimum to store key-value data. 12 | } 13 | set current_mem [s used_memory] 14 | set used [expr {$current_mem-$base_mem}] 15 | set efficiency [expr {double($written)/$used}] 16 | return $efficiency 17 | } 18 | 19 | start_server {tags {"memefficiency"}} { 20 | foreach {size_range expected_min_efficiency} { 21 | 32 0.15 22 | 64 0.25 23 | 128 0.35 24 | 1024 0.75 25 | 16384 0.82 26 | } { 27 | test "Memory efficiency with values in range $size_range" { 28 | set efficiency [test_memory_efficiency $size_range] 29 | assert {$efficiency >= $expected_min_efficiency} 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /deps/jemalloc/src/extent.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | 6 | static inline int 7 | extent_szad_comp(extent_node_t *a, extent_node_t *b) 8 | { 9 | int ret; 10 | size_t a_size = a->size; 11 | size_t b_size = b->size; 12 | 13 | ret = (a_size > b_size) - (a_size < b_size); 14 | if (ret == 0) { 15 | uintptr_t a_addr = (uintptr_t)a->addr; 16 | uintptr_t b_addr = (uintptr_t)b->addr; 17 | 18 | ret = (a_addr > b_addr) - (a_addr < b_addr); 19 | } 20 | 21 | return (ret); 22 | } 23 | 24 | /* Generate red-black tree functions. */ 25 | rb_gen(, extent_tree_szad_, extent_tree_t, extent_node_t, link_szad, 26 | extent_szad_comp) 27 | 28 | static inline int 29 | extent_ad_comp(extent_node_t *a, extent_node_t *b) 30 | { 31 | uintptr_t a_addr = (uintptr_t)a->addr; 32 | uintptr_t b_addr = (uintptr_t)b->addr; 33 | 34 | return ((a_addr > b_addr) - (a_addr < b_addr)); 35 | } 36 | 37 | /* Generate red-black tree functions. */ 38 | rb_gen(, extent_tree_ad_, extent_tree_t, extent_node_t, link_ad, 39 | extent_ad_comp) 40 | -------------------------------------------------------------------------------- /deps/jemalloc/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general purpose malloc(3) implementation that emphasizes 2 | fragmentation avoidance and scalable concurrency support. jemalloc first came 3 | into use as the FreeBSD libc allocator in 2005, and since then it has found its 4 | way into numerous applications that rely on its predictable behavior. In 2010 5 | jemalloc development efforts broadened to include developer support features 6 | such as heap profiling, Valgrind integration, and extensive monitoring/tuning 7 | hooks. Modern jemalloc releases continue to be integrated back into FreeBSD, 8 | and therefore versatility remains critical. Ongoing development efforts trend 9 | toward making jemalloc among the best allocators for a broad range of demanding 10 | applications, and eliminating/mitigating weaknesses that have practical 11 | repercussions for real world applications. 12 | 13 | The COPYING file contains copyright and licensing information. 14 | 15 | The INSTALL file contains information on how to configure, build, and install 16 | jemalloc. 17 | 18 | The ChangeLog file contains a brief summary of changes for each release. 19 | 20 | URL: http://www.canonware.com/jemalloc/ 21 | -------------------------------------------------------------------------------- /tests/unit/quit.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"quit"}} { 2 | proc format_command {args} { 3 | set cmd "*[llength $args]\r\n" 4 | foreach a $args { 5 | append cmd "$[string length $a]\r\n$a\r\n" 6 | } 7 | set _ $cmd 8 | } 9 | 10 | test "QUIT returns OK" { 11 | reconnect 12 | assert_equal OK [r quit] 13 | assert_error * {r ping} 14 | } 15 | 16 | test "Pipelined commands after QUIT must not be executed" { 17 | reconnect 18 | r write [format_command quit] 19 | r write [format_command set foo bar] 20 | r flush 21 | assert_equal OK [r read] 22 | assert_error * {r read} 23 | 24 | reconnect 25 | assert_equal {} [r get foo] 26 | } 27 | 28 | test "Pipelined commands after QUIT that exceed read buffer size" { 29 | reconnect 30 | r write [format_command quit] 31 | r write [format_command set foo [string repeat "x" 1024]] 32 | r flush 33 | assert_equal OK [r read] 34 | assert_error * {r read} 35 | 36 | reconnect 37 | assert_equal {} [r get foo] 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /deps/lua/etc/luavs.bat: -------------------------------------------------------------------------------- 1 | @rem Script to build Lua under "Visual Studio .NET Command Prompt". 2 | @rem Do not run from this directory; run it from the toplevel: etc\luavs.bat . 3 | @rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. 4 | @rem (contributed by David Manura and Mike Pall) 5 | 6 | @setlocal 7 | @set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE 8 | @set MYLINK=link /nologo 9 | @set MYMT=mt /nologo 10 | 11 | cd src 12 | %MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c 13 | del lua.obj luac.obj 14 | %MYLINK% /DLL /out:lua51.dll l*.obj 15 | if exist lua51.dll.manifest^ 16 | %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 17 | %MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c 18 | %MYLINK% /out:lua.exe lua.obj lua51.lib 19 | if exist lua.exe.manifest^ 20 | %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe 21 | %MYCOMPILE% l*.c print.c 22 | del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^ 23 | loslib.obj ltablib.obj lstrlib.obj loadlib.obj 24 | %MYLINK% /out:luac.exe *.obj 25 | if exist luac.exe.manifest^ 26 | %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe 27 | del *.obj *.manifest 28 | cd .. 29 | -------------------------------------------------------------------------------- /deps/lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /deps/jemalloc/test/integration/mremap.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_mremap) 4 | { 5 | int err; 6 | size_t sz, lg_chunk, chunksize, i; 7 | char *p, *q; 8 | 9 | sz = sizeof(lg_chunk); 10 | err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0); 11 | assert_d_eq(err, 0, "Error in mallctl(): %s", strerror(err)); 12 | chunksize = ((size_t)1U) << lg_chunk; 13 | 14 | p = (char *)malloc(chunksize); 15 | assert_ptr_not_null(p, "malloc(%zu) --> %p", chunksize, p); 16 | memset(p, 'a', chunksize); 17 | 18 | q = (char *)realloc(p, chunksize * 2); 19 | assert_ptr_not_null(q, "realloc(%p, %zu) --> %p", p, chunksize * 2, 20 | q); 21 | for (i = 0; i < chunksize; i++) { 22 | assert_c_eq(q[i], 'a', 23 | "realloc() should preserve existing bytes across copies"); 24 | } 25 | 26 | p = q; 27 | 28 | q = (char *)realloc(p, chunksize); 29 | assert_ptr_not_null(q, "realloc(%p, %zu) --> %p", p, chunksize, q); 30 | for (i = 0; i < chunksize; i++) { 31 | assert_c_eq(q[i], 'a', 32 | "realloc() should preserve existing bytes across copies"); 33 | } 34 | 35 | free(q); 36 | } 37 | TEST_END 38 | 39 | int 40 | main(void) 41 | { 42 | 43 | return (test( 44 | test_mremap)); 45 | } 46 | -------------------------------------------------------------------------------- /tests/cluster/tests/09-pubsub.tcl: -------------------------------------------------------------------------------- 1 | # Test PUBLISH propagation across the cluster. 2 | 3 | source "../tests/includes/init-tests.tcl" 4 | 5 | test "Create a 5 nodes cluster" { 6 | create_cluster 5 5 7 | } 8 | 9 | proc test_cluster_publish {instance instances} { 10 | # Subscribe all the instances but the one we use to send. 11 | for {set j 0} {$j < $instances} {incr j} { 12 | if {$j != $instance} { 13 | R $j deferred 1 14 | R $j subscribe testchannel 15 | R $j read; # Read the subscribe reply 16 | } 17 | } 18 | 19 | set data [randomValue] 20 | R $instance PUBLISH testchannel $data 21 | 22 | # Read the message back from all the nodes. 23 | for {set j 0} {$j < $instances} {incr j} { 24 | if {$j != $instance} { 25 | set msg [R $j read] 26 | assert {$data eq [lindex $msg 2]} 27 | R $j unsubscribe testchannel 28 | R $j read; # Read the unsubscribe reply 29 | R $j deferred 0 30 | } 31 | } 32 | } 33 | 34 | test "Test publishing to master" { 35 | test_cluster_publish 0 10 36 | } 37 | 38 | test "Test publishing to slave" { 39 | test_cluster_publish 5 10 40 | } 41 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_idump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef JEMALLOC_PROF 4 | const char *malloc_conf = 5 | "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0," 6 | "lg_prof_interval:0"; 7 | #endif 8 | 9 | static bool did_prof_dump_open; 10 | 11 | static int 12 | prof_dump_open_intercept(bool propagate_err, const char *filename) 13 | { 14 | int fd; 15 | 16 | did_prof_dump_open = true; 17 | 18 | fd = open("/dev/null", O_WRONLY); 19 | assert_d_ne(fd, -1, "Unexpected open() failure"); 20 | 21 | return (fd); 22 | } 23 | 24 | TEST_BEGIN(test_idump) 25 | { 26 | bool active; 27 | void *p; 28 | 29 | test_skip_if(!config_prof); 30 | 31 | active = true; 32 | assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)), 33 | 0, "Unexpected mallctl failure while activating profiling"); 34 | 35 | prof_dump_open = prof_dump_open_intercept; 36 | 37 | did_prof_dump_open = false; 38 | p = mallocx(1, 0); 39 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 40 | dallocx(p, 0); 41 | assert_true(did_prof_dump_open, "Expected a profile dump"); 42 | } 43 | TEST_END 44 | 45 | int 46 | main(void) 47 | { 48 | 49 | return (test( 50 | test_idump)); 51 | } 52 | -------------------------------------------------------------------------------- /utils/redis_init_script.tpl: -------------------------------------------------------------------------------- 1 | 2 | case "$1" in 3 | start) 4 | if [ -f $PIDFILE ] 5 | then 6 | echo "$PIDFILE exists, process is already running or crashed" 7 | else 8 | echo "Starting Redis server..." 9 | $EXEC $CONF 10 | fi 11 | ;; 12 | stop) 13 | if [ ! -f $PIDFILE ] 14 | then 15 | echo "$PIDFILE does not exist, process is not running" 16 | else 17 | PID=$(cat $PIDFILE) 18 | echo "Stopping ..." 19 | $CLIEXEC -p $REDISPORT shutdown 20 | while [ -x /proc/${PID} ] 21 | do 22 | echo "Waiting for Redis to shutdown ..." 23 | sleep 1 24 | done 25 | echo "Redis stopped" 26 | fi 27 | ;; 28 | status) 29 | PID=$(cat $PIDFILE) 30 | if [ ! -x /proc/${PID} ] 31 | then 32 | echo 'Redis is not running' 33 | else 34 | echo "Redis is running ($PID)" 35 | fi 36 | ;; 37 | restart) 38 | $0 stop 39 | $0 start 40 | ;; 41 | *) 42 | echo "Please use start, stop, restart or status as first argument" 43 | ;; 44 | esac 45 | -------------------------------------------------------------------------------- /deps/jemalloc/test/test.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case @abi@ in 4 | macho) 5 | export DYLD_FALLBACK_LIBRARY_PATH="@objroot@lib" 6 | ;; 7 | pecoff) 8 | export PATH="${PATH}:@objroot@lib" 9 | ;; 10 | *) 11 | ;; 12 | esac 13 | 14 | # Corresponds to test_status_t. 15 | pass_code=0 16 | skip_code=1 17 | fail_code=2 18 | 19 | pass_count=0 20 | skip_count=0 21 | fail_count=0 22 | for t in $@; do 23 | if [ $pass_count -ne 0 -o $skip_count -ne 0 -o $fail_count != 0 ] ; then 24 | echo 25 | fi 26 | echo "=== ${t} ===" 27 | ${t}@exe@ @abs_srcroot@ @abs_objroot@ 28 | result_code=$? 29 | case ${result_code} in 30 | ${pass_code}) 31 | pass_count=$((pass_count+1)) 32 | ;; 33 | ${skip_code}) 34 | skip_count=$((skip_count+1)) 35 | ;; 36 | ${fail_code}) 37 | fail_count=$((fail_count+1)) 38 | ;; 39 | *) 40 | echo "Test harness error" 1>&2 41 | exit 1 42 | esac 43 | done 44 | 45 | total_count=`expr ${pass_count} + ${skip_count} + ${fail_count}` 46 | echo 47 | echo "Test suite summary: pass: ${pass_count}/${total_count}, skip: ${skip_count}/${total_count}, fail: ${fail_count}/${total_count}" 48 | 49 | if [ ${fail_count} -eq 0 ] ; then 50 | exit 0 51 | else 52 | exit 1 53 | fi 54 | -------------------------------------------------------------------------------- /deps/lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /deps/lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /deps/lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /deps/lua/test/README: -------------------------------------------------------------------------------- 1 | These are simple tests for Lua. Some of them contain useful code. 2 | They are meant to be run to make sure Lua is built correctly and also 3 | to be read, to see how Lua programs look. 4 | 5 | Here is a one-line summary of each program: 6 | 7 | bisect.lua bisection method for solving non-linear equations 8 | cf.lua temperature conversion table (celsius to farenheit) 9 | echo.lua echo command line arguments 10 | env.lua environment variables as automatic global variables 11 | factorial.lua factorial without recursion 12 | fib.lua fibonacci function with cache 13 | fibfor.lua fibonacci numbers with coroutines and generators 14 | globals.lua report global variable usage 15 | hello.lua the first program in every language 16 | life.lua Conway's Game of Life 17 | luac.lua bare-bones luac 18 | printf.lua an implementation of printf 19 | readonly.lua make global variables readonly 20 | sieve.lua the sieve of of Eratosthenes programmed with coroutines 21 | sort.lua two implementations of a sort function 22 | table.lua make table, grouping all data for the same item 23 | trace-calls.lua trace calls 24 | trace-globals.lua trace assigments to global variables 25 | xd.lua hex dump 26 | 27 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 2 4 | #define NINCRS 2000000 5 | 6 | TEST_BEGIN(test_mtx_basic) 7 | { 8 | mtx_t mtx; 9 | 10 | assert_false(mtx_init(&mtx), "Unexpected mtx_init() failure"); 11 | mtx_lock(&mtx); 12 | mtx_unlock(&mtx); 13 | mtx_fini(&mtx); 14 | } 15 | TEST_END 16 | 17 | typedef struct { 18 | mtx_t mtx; 19 | unsigned x; 20 | } thd_start_arg_t; 21 | 22 | static void * 23 | thd_start(void *varg) 24 | { 25 | thd_start_arg_t *arg = (thd_start_arg_t *)varg; 26 | unsigned i; 27 | 28 | for (i = 0; i < NINCRS; i++) { 29 | mtx_lock(&arg->mtx); 30 | arg->x++; 31 | mtx_unlock(&arg->mtx); 32 | } 33 | return (NULL); 34 | } 35 | 36 | TEST_BEGIN(test_mtx_race) 37 | { 38 | thd_start_arg_t arg; 39 | thd_t thds[NTHREADS]; 40 | unsigned i; 41 | 42 | assert_false(mtx_init(&arg.mtx), "Unexpected mtx_init() failure"); 43 | arg.x = 0; 44 | for (i = 0; i < NTHREADS; i++) 45 | thd_create(&thds[i], thd_start, (void *)&arg); 46 | for (i = 0; i < NTHREADS; i++) 47 | thd_join(thds[i], NULL); 48 | assert_u_eq(arg.x, NTHREADS * NINCRS, 49 | "Race-related counter corruption"); 50 | } 51 | TEST_END 52 | 53 | int 54 | main(void) 55 | { 56 | 57 | return (test( 58 | test_mtx_basic, 59 | test_mtx_race)); 60 | } 61 | -------------------------------------------------------------------------------- /utils/redis_init_script: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Simple Redis init.d script conceived to work on Linux systems 4 | # as it does use of the /proc filesystem. 5 | 6 | REDISPORT=6379 7 | EXEC=/usr/local/bin/redis-server 8 | CLIEXEC=/usr/local/bin/redis-cli 9 | 10 | PIDFILE=/var/run/redis_${REDISPORT}.pid 11 | CONF="/etc/redis/${REDISPORT}.conf" 12 | 13 | case "$1" in 14 | start) 15 | if [ -f $PIDFILE ] 16 | then 17 | echo "$PIDFILE exists, process is already running or crashed" 18 | else 19 | echo "Starting Redis server..." 20 | $EXEC $CONF 21 | fi 22 | ;; 23 | stop) 24 | if [ ! -f $PIDFILE ] 25 | then 26 | echo "$PIDFILE does not exist, process is not running" 27 | else 28 | PID=$(cat $PIDFILE) 29 | echo "Stopping ..." 30 | $CLIEXEC -p $REDISPORT shutdown 31 | while [ -x /proc/${PID} ] 32 | do 33 | echo "Waiting for Redis to shutdown ..." 34 | sleep 1 35 | done 36 | echo "Redis stopped" 37 | fi 38 | ;; 39 | *) 40 | echo "Please use start or stop as first argument" 41 | ;; 42 | esac 43 | -------------------------------------------------------------------------------- /deps/jemalloc/test/integration/xallocx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_same_size) 4 | { 5 | void *p; 6 | size_t sz, tsz; 7 | 8 | p = mallocx(42, 0); 9 | assert_ptr_not_null(p, "Unexpected mallocx() error"); 10 | sz = sallocx(p, 0); 11 | 12 | tsz = xallocx(p, sz, 0, 0); 13 | assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz); 14 | 15 | dallocx(p, 0); 16 | } 17 | TEST_END 18 | 19 | TEST_BEGIN(test_extra_no_move) 20 | { 21 | void *p; 22 | size_t sz, tsz; 23 | 24 | p = mallocx(42, 0); 25 | assert_ptr_not_null(p, "Unexpected mallocx() error"); 26 | sz = sallocx(p, 0); 27 | 28 | tsz = xallocx(p, sz, sz-42, 0); 29 | assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz); 30 | 31 | dallocx(p, 0); 32 | } 33 | TEST_END 34 | 35 | TEST_BEGIN(test_no_move_fail) 36 | { 37 | void *p; 38 | size_t sz, tsz; 39 | 40 | p = mallocx(42, 0); 41 | assert_ptr_not_null(p, "Unexpected mallocx() error"); 42 | sz = sallocx(p, 0); 43 | 44 | tsz = xallocx(p, sz + 5, 0, 0); 45 | assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz); 46 | 47 | dallocx(p, 0); 48 | } 49 | TEST_END 50 | 51 | int 52 | main(void) 53 | { 54 | 55 | return (test( 56 | test_same_size, 57 | test_extra_no_move, 58 | test_no_move_fail)); 59 | } 60 | -------------------------------------------------------------------------------- /deps/lua/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /deps/jemalloc/test/src/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | bool 4 | mtx_init(mtx_t *mtx) 5 | { 6 | 7 | #ifdef _WIN32 8 | if (!InitializeCriticalSectionAndSpinCount(&mtx->lock, _CRT_SPINCOUNT)) 9 | return (true); 10 | #elif (defined(JEMALLOC_OSSPIN)) 11 | mtx->lock = 0; 12 | #else 13 | pthread_mutexattr_t attr; 14 | 15 | if (pthread_mutexattr_init(&attr) != 0) 16 | return (true); 17 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); 18 | if (pthread_mutex_init(&mtx->lock, &attr) != 0) { 19 | pthread_mutexattr_destroy(&attr); 20 | return (true); 21 | } 22 | pthread_mutexattr_destroy(&attr); 23 | #endif 24 | return (false); 25 | } 26 | 27 | void 28 | mtx_fini(mtx_t *mtx) 29 | { 30 | 31 | #ifdef _WIN32 32 | #elif (defined(JEMALLOC_OSSPIN)) 33 | #else 34 | pthread_mutex_destroy(&mtx->lock); 35 | #endif 36 | } 37 | 38 | void 39 | mtx_lock(mtx_t *mtx) 40 | { 41 | 42 | #ifdef _WIN32 43 | EnterCriticalSection(&mtx->lock); 44 | #elif (defined(JEMALLOC_OSSPIN)) 45 | OSSpinLockLock(&mtx->lock); 46 | #else 47 | pthread_mutex_lock(&mtx->lock); 48 | #endif 49 | } 50 | 51 | void 52 | mtx_unlock(mtx_t *mtx) 53 | { 54 | 55 | #ifdef _WIN32 56 | LeaveCriticalSection(&mtx->lock); 57 | #elif (defined(JEMALLOC_OSSPIN)) 58 | OSSpinLockUnlock(&mtx->lock); 59 | #else 60 | pthread_mutex_unlock(&mtx->lock); 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /deps/lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk_dss.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef enum { 5 | dss_prec_disabled = 0, 6 | dss_prec_primary = 1, 7 | dss_prec_secondary = 2, 8 | 9 | dss_prec_limit = 3 10 | } dss_prec_t; 11 | #define DSS_PREC_DEFAULT dss_prec_secondary 12 | #define DSS_DEFAULT "secondary" 13 | 14 | #endif /* JEMALLOC_H_TYPES */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_STRUCTS 17 | 18 | extern const char *dss_prec_names[]; 19 | 20 | #endif /* JEMALLOC_H_STRUCTS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_EXTERNS 23 | 24 | dss_prec_t chunk_dss_prec_get(void); 25 | bool chunk_dss_prec_set(dss_prec_t dss_prec); 26 | void *chunk_alloc_dss(size_t size, size_t alignment, bool *zero); 27 | bool chunk_in_dss(void *chunk); 28 | bool chunk_dss_boot(void); 29 | void chunk_dss_prefork(void); 30 | void chunk_dss_postfork_parent(void); 31 | void chunk_dss_postfork_child(void); 32 | 33 | #endif /* JEMALLOC_H_EXTERNS */ 34 | /******************************************************************************/ 35 | #ifdef JEMALLOC_H_INLINES 36 | 37 | #endif /* JEMALLOC_H_INLINES */ 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_gdump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef JEMALLOC_PROF 4 | const char *malloc_conf = "prof:true,prof_active:false,prof_gdump:true"; 5 | #endif 6 | 7 | static bool did_prof_dump_open; 8 | 9 | static int 10 | prof_dump_open_intercept(bool propagate_err, const char *filename) 11 | { 12 | int fd; 13 | 14 | did_prof_dump_open = true; 15 | 16 | fd = open("/dev/null", O_WRONLY); 17 | assert_d_ne(fd, -1, "Unexpected open() failure"); 18 | 19 | return (fd); 20 | } 21 | 22 | TEST_BEGIN(test_gdump) 23 | { 24 | bool active; 25 | void *p, *q; 26 | 27 | test_skip_if(!config_prof); 28 | 29 | active = true; 30 | assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)), 31 | 0, "Unexpected mallctl failure while activating profiling"); 32 | 33 | prof_dump_open = prof_dump_open_intercept; 34 | 35 | did_prof_dump_open = false; 36 | p = mallocx(chunksize, 0); 37 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 38 | assert_true(did_prof_dump_open, "Expected a profile dump"); 39 | 40 | did_prof_dump_open = false; 41 | q = mallocx(chunksize, 0); 42 | assert_ptr_not_null(q, "Unexpected mallocx() failure"); 43 | assert_true(did_prof_dump_open, "Expected a profile dump"); 44 | 45 | dallocx(p, 0); 46 | dallocx(q, 0); 47 | } 48 | TEST_END 49 | 50 | int 51 | main(void) 52 | { 53 | 54 | return (test( 55 | test_gdump)); 56 | } 57 | -------------------------------------------------------------------------------- /utils/redis-copy.rb: -------------------------------------------------------------------------------- 1 | # redis-copy.rb - Copyright (C) 2009-2010 Salvatore Sanfilippo 2 | # BSD license, See the COPYING file for more information. 3 | # 4 | # Copy the whole dataset from one Redis instance to another one 5 | # 6 | # WARNING: this utility is deprecated and serves as a legacy adapter 7 | # for the more-robust redis-copy gem. 8 | 9 | require 'shellwords' 10 | 11 | def redisCopy(opts={}) 12 | src = "#{opts[:srchost]}:#{opts[:srcport]}" 13 | dst = "#{opts[:dsthost]}:#{opts[:dstport]}" 14 | `redis-copy #{src.shellescape} #{dst.shellescape}` 15 | rescue Errno::ENOENT 16 | $stderr.puts 'This utility requires the redis-copy executable', 17 | 'from the redis-copy gem on https://rubygems.org', 18 | 'To install it, run `gem install redis-copy`.' 19 | exit 1 20 | end 21 | 22 | $stderr.puts "This utility is deprecated. Use the redis-copy gem instead." 23 | if ARGV.length != 4 24 | puts "Usage: redis-copy.rb " 25 | exit 1 26 | end 27 | puts "WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready." 28 | STDIN.gets 29 | srchost = ARGV[0] 30 | srcport = ARGV[1] 31 | dsthost = ARGV[2] 32 | dstport = ARGV[3] 33 | puts "Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}" 34 | redisCopy(:srchost => srchost, :srcport => srcport.to_i, 35 | :dsthost => dsthost, :dstport => dstport.to_i) 36 | -------------------------------------------------------------------------------- /tests/integration/aof-race.tcl: -------------------------------------------------------------------------------- 1 | set defaults { appendonly {yes} appendfilename {appendonly.aof} } 2 | set server_path [tmpdir server.aof] 3 | set aof_path "$server_path/appendonly.aof" 4 | 5 | proc start_server_aof {overrides code} { 6 | upvar defaults defaults srv srv server_path server_path 7 | set config [concat $defaults $overrides] 8 | start_server [list overrides $config] $code 9 | } 10 | 11 | tags {"aof"} { 12 | # Specific test for a regression where internal buffers were not properly 13 | # cleaned after a child responsible for an AOF rewrite exited. This buffer 14 | # was subsequently appended to the new AOF, resulting in duplicate commands. 15 | start_server_aof [list dir $server_path] { 16 | set client [redis [srv host] [srv port]] 17 | set bench [open "|src/redis-benchmark -q -p [srv port] -c 20 -n 20000 incr foo" "r+"] 18 | after 100 19 | 20 | # Benchmark should be running by now: start background rewrite 21 | $client bgrewriteaof 22 | 23 | # Read until benchmark pipe reaches EOF 24 | while {[string length [read $bench]] > 0} {} 25 | 26 | # Check contents of foo 27 | assert_equal 20000 [$client get foo] 28 | } 29 | 30 | # Restart server to replay AOF 31 | start_server_aof [list dir $server_path] { 32 | set client [redis [srv host] [srv port]] 33 | assert_equal 20000 [$client get foo] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/sentinel/tests/01-conf-update.tcl: -------------------------------------------------------------------------------- 1 | # Test Sentinel configuration consistency after partitions heal. 2 | 3 | source "../tests/includes/init-tests.tcl" 4 | 5 | test "We can failover with Sentinel 1 crashed" { 6 | set old_port [RI $master_id tcp_port] 7 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 8 | assert {[lindex $addr 1] == $old_port} 9 | 10 | # Crash Sentinel 1 11 | kill_instance sentinel 1 12 | 13 | kill_instance redis $master_id 14 | foreach_sentinel_id id { 15 | if {$id != 1} { 16 | wait_for_condition 1000 50 { 17 | [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port 18 | } else { 19 | fail "Sentinel $id did not received failover info" 20 | } 21 | } 22 | } 23 | restart_instance redis $master_id 24 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 25 | set master_id [get_instance_id_by_port redis [lindex $addr 1]] 26 | } 27 | 28 | test "After Sentinel 1 is restarted, its config gets updated" { 29 | restart_instance sentinel 1 30 | wait_for_condition 1000 50 { 31 | [lindex [S 1 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port 32 | } else { 33 | fail "Restarted Sentinel did not received failover info" 34 | } 35 | } 36 | 37 | test "New master [join $addr {:}] role matches" { 38 | assert {[RI $master_id role] eq {master}} 39 | } 40 | -------------------------------------------------------------------------------- /tests/cluster/tests/07-replica-migration.tcl: -------------------------------------------------------------------------------- 1 | # Replica migration test. 2 | # Check that orphaned masters are joined by replicas of masters having 3 | # multiple replicas attached, according to the migration barrier settings. 4 | 5 | source "../tests/includes/init-tests.tcl" 6 | 7 | # Create a cluster with 5 master and 10 slaves, so that we have 2 8 | # slaves for each master. 9 | test "Create a 5 nodes cluster" { 10 | create_cluster 5 10 11 | } 12 | 13 | test "Cluster is up" { 14 | assert_cluster_state ok 15 | } 16 | 17 | test "Each master should have two replicas attached" { 18 | foreach_redis_id id { 19 | if {$id < 5} { 20 | wait_for_condition 1000 50 { 21 | [llength [lindex [R 0 role] 2]] == 2 22 | } else { 23 | fail "Master #$id does not have 2 slaves as expected" 24 | } 25 | } 26 | } 27 | } 28 | 29 | test "Killing all the slaves of master #0 and #1" { 30 | kill_instance redis 5 31 | kill_instance redis 10 32 | kill_instance redis 6 33 | kill_instance redis 11 34 | after 4000 35 | } 36 | 37 | foreach_redis_id id { 38 | if {$id < 5} { 39 | test "Master #$id should have at least one replica" { 40 | wait_for_condition 1000 50 { 41 | [llength [lindex [R $id role] 2]] >= 1 42 | } else { 43 | fail "Master #$id has no replicas" 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /deps/lua/etc/noparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The code below can be used to make a Lua core that does not contain the 3 | * parsing modules (lcode, llex, lparser), which represent 35% of the total core. 4 | * You'll only be able to load binary files and strings, precompiled with luac. 5 | * (Of course, you'll have to build luac with the original parsing modules!) 6 | * 7 | * To use this module, simply compile it ("make noparser" does that) and list 8 | * its object file before the Lua libraries. The linker should then not load 9 | * the parsing modules. To try it, do "make luab". 10 | * 11 | * If you also want to avoid the dump module (ldump.o), define NODUMP. 12 | * #define NODUMP 13 | */ 14 | 15 | #define LUA_CORE 16 | 17 | #include "llex.h" 18 | #include "lparser.h" 19 | #include "lzio.h" 20 | 21 | LUAI_FUNC void luaX_init (lua_State *L) { 22 | UNUSED(L); 23 | } 24 | 25 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { 26 | UNUSED(z); 27 | UNUSED(buff); 28 | UNUSED(name); 29 | lua_pushliteral(L,"parser not loaded"); 30 | lua_error(L); 31 | return NULL; 32 | } 33 | 34 | #ifdef NODUMP 35 | #include "lundump.h" 36 | 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { 38 | UNUSED(f); 39 | UNUSED(w); 40 | UNUSED(data); 41 | UNUSED(strip); 42 | #if 1 43 | UNUSED(L); 44 | return 0; 45 | #else 46 | lua_pushliteral(L,"dumper not loaded"); 47 | lua_error(L); 48 | #endif 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/jemalloc_mangle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | public_symbols_txt=$1 4 | symbol_prefix=$2 5 | 6 | cat < $current_epoch 38 | } else { 39 | fail "No failover detected" 40 | } 41 | } 42 | 43 | test "Cluster should eventually be up again" { 44 | assert_cluster_state ok 45 | } 46 | 47 | test "Cluster is writable" { 48 | cluster_write_test 1 49 | } 50 | 51 | test "Instance #5 is now a master" { 52 | assert {[RI 5 role] eq {master}} 53 | } 54 | 55 | test "Restarting the previously killed master node" { 56 | restart_instance redis 0 57 | } 58 | 59 | test "Instance #0 gets converted into a slave" { 60 | wait_for_condition 1000 50 { 61 | [RI 0 role] eq {slave} 62 | } else { 63 | fail "Old master was not converted into slave" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/unit/type/list-2.tcl: -------------------------------------------------------------------------------- 1 | start_server { 2 | tags {"list"} 3 | overrides { 4 | "list-max-ziplist-value" 16 5 | "list-max-ziplist-entries" 256 6 | } 7 | } { 8 | source "tests/unit/type/list-common.tcl" 9 | 10 | foreach {type large} [array get largevalue] { 11 | tags {"slow"} { 12 | test "LTRIM stress testing - $type" { 13 | set mylist {} 14 | set startlen 32 15 | r del mylist 16 | 17 | # Start with the large value to ensure the 18 | # right encoding is used. 19 | r rpush mylist $large 20 | lappend mylist $large 21 | 22 | for {set i 0} {$i < $startlen} {incr i} { 23 | set str [randomInt 9223372036854775807] 24 | r rpush mylist $str 25 | lappend mylist $str 26 | } 27 | 28 | for {set i 0} {$i < 1000} {incr i} { 29 | set min [expr {int(rand()*$startlen)}] 30 | set max [expr {$min+int(rand()*$startlen)}] 31 | set mylist [lrange $mylist $min $max] 32 | r ltrim mylist $min $max 33 | assert_equal $mylist [r lrange mylist 0 -1] 34 | 35 | for {set j [r llen mylist]} {$j < $startlen} {incr j} { 36 | set str [randomInt 9223372036854775807] 37 | r rpush mylist $str 38 | lappend mylist $str 39 | } 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /deps/hiredis/examples/example-libev.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 11 | redisReply *reply = r; 12 | if (reply == NULL) return; 13 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 14 | 15 | /* Disconnect after receiving the reply to GET */ 16 | redisAsyncDisconnect(c); 17 | } 18 | 19 | void connectCallback(const redisAsyncContext *c, int status) { 20 | if (status != REDIS_OK) { 21 | printf("Error: %s\n", c->errstr); 22 | return; 23 | } 24 | printf("Connected...\n"); 25 | } 26 | 27 | void disconnectCallback(const redisAsyncContext *c, int status) { 28 | if (status != REDIS_OK) { 29 | printf("Error: %s\n", c->errstr); 30 | return; 31 | } 32 | printf("Disconnected...\n"); 33 | } 34 | 35 | int main (int argc, char **argv) { 36 | signal(SIGPIPE, SIG_IGN); 37 | 38 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 39 | if (c->err) { 40 | /* Let *c leak for now... */ 41 | printf("Error: %s\n", c->errstr); 42 | return 1; 43 | } 44 | 45 | redisLibevAttach(EV_DEFAULT_ c); 46 | redisAsyncSetConnectCallback(c,connectCallback); 47 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 48 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 49 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 50 | ev_loop(EV_DEFAULT_ 0); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /deps/lua/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /deps/lua/doc/lua.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000 ; 3 | background-color: #FFFFFF ; 4 | font-family: Helvetica, Arial, sans-serif ; 5 | text-align: justify ; 6 | margin-right: 30px ; 7 | margin-left: 30px ; 8 | } 9 | 10 | h1, h2, h3, h4 { 11 | font-family: Verdana, Geneva, sans-serif ; 12 | font-weight: normal ; 13 | font-style: italic ; 14 | } 15 | 16 | h2 { 17 | padding-top: 0.4em ; 18 | padding-bottom: 0.4em ; 19 | padding-left: 30px ; 20 | padding-right: 30px ; 21 | margin-left: -30px ; 22 | background-color: #E0E0FF ; 23 | } 24 | 25 | h3 { 26 | padding-left: 0.5em ; 27 | border-left: solid #E0E0FF 1em ; 28 | } 29 | 30 | table h3 { 31 | padding-left: 0px ; 32 | border-left: none ; 33 | } 34 | 35 | a:link { 36 | color: #000080 ; 37 | background-color: inherit ; 38 | text-decoration: none ; 39 | } 40 | 41 | a:visited { 42 | background-color: inherit ; 43 | text-decoration: none ; 44 | } 45 | 46 | a:link:hover, a:visited:hover { 47 | color: #000080 ; 48 | background-color: #E0E0FF ; 49 | } 50 | 51 | a:link:active, a:visited:active { 52 | color: #FF0000 ; 53 | } 54 | 55 | hr { 56 | border: 0 ; 57 | height: 1px ; 58 | color: #a0a0a0 ; 59 | background-color: #a0a0a0 ; 60 | } 61 | 62 | :target { 63 | background-color: #F8F8F8 ; 64 | padding: 8px ; 65 | border: solid #a0a0a0 2px ; 66 | } 67 | 68 | .footer { 69 | color: gray ; 70 | font-size: small ; 71 | } 72 | 73 | input[type=text] { 74 | border: solid #a0a0a0 2px ; 75 | border-radius: 2em ; 76 | -moz-border-radius: 2em ; 77 | background-image: url('images/search.png') ; 78 | background-repeat: no-repeat; 79 | background-position: 4px center ; 80 | padding-left: 20px ; 81 | height: 2em ; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /deps/hiredis/examples/example-libuv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 11 | redisReply *reply = r; 12 | if (reply == NULL) return; 13 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 14 | 15 | /* Disconnect after receiving the reply to GET */ 16 | redisAsyncDisconnect(c); 17 | } 18 | 19 | void connectCallback(const redisAsyncContext *c, int status) { 20 | if (status != REDIS_OK) { 21 | printf("Error: %s\n", c->errstr); 22 | return; 23 | } 24 | printf("Connected...\n"); 25 | } 26 | 27 | void disconnectCallback(const redisAsyncContext *c, int status) { 28 | if (status != REDIS_OK) { 29 | printf("Error: %s\n", c->errstr); 30 | return; 31 | } 32 | printf("Disconnected...\n"); 33 | } 34 | 35 | int main (int argc, char **argv) { 36 | signal(SIGPIPE, SIG_IGN); 37 | uv_loop_t* loop = uv_default_loop(); 38 | 39 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 40 | if (c->err) { 41 | /* Let *c leak for now... */ 42 | printf("Error: %s\n", c->errstr); 43 | return 1; 44 | } 45 | 46 | redisLibuvAttach(c,loop); 47 | redisAsyncSetConnectCallback(c,connectCallback); 48 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 49 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 50 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 51 | uv_run(loop, UV_RUN_DEFAULT); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /deps/hiredis/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2011, Salvatore Sanfilippo 2 | Copyright (c) 2010-2011, Pieter Noordhuis 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Redis nor the names of its contributors may be used 17 | to endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Note: by contributing code to the Redis project in any form, including sending 2 | a pull request via Github, a code fragment or patch via private email or 3 | public discussion groups, you agree to release your code under the terms 4 | of the BSD license that you can find in the COPYING file included in the Redis 5 | source distribution. You will include BSD license in the COPYING file within 6 | each source file that you contribute. 7 | 8 | # IMPORTANT: HOW TO USE REDIS GITHUB ISSUES 9 | 10 | * Github issues SHOULD ONLY BE USED to report bugs, and for DETAILED feature 11 | requests. Everything else belongs to the Redis Google Group. 12 | 13 | PLEASE DO NOT POST GENERAL QUESTIONS that are not about bugs or suspected 14 | bugs in the Github issues system. We'll be very happy to help you and provide 15 | all the support in the Redis Google Group. 16 | 17 | Redis Google Group address: 18 | 19 | https://groups.google.com/forum/?fromgroups#!forum/redis-db 20 | 21 | # How to provide a patch for a new feature 22 | 23 | 1. If it is a major feature or a semantical change, write an RCP (Redis Change Proposal). Check the documentation here: https://github.com/redis/redis-rcp 24 | 25 | 2. If in step 1 you get an acknowledge from the project leaders, use the 26 | following procedure to submit a patch: 27 | 28 | a. Fork Redis on github ( http://help.github.com/fork-a-repo/ ) 29 | b. Create a topic branch (git checkout -b my_branch) 30 | c. Push to your branch (git push origin my_branch) 31 | d. Initiate a pull request on github ( http://help.github.com/send-pull-requests/ ) 32 | e. Done :) 33 | 34 | For minor fixes just open a pull request on Github. 35 | 36 | Thanks! 37 | -------------------------------------------------------------------------------- /deps/hiredis/examples/example-libevent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 11 | redisReply *reply = r; 12 | if (reply == NULL) return; 13 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 14 | 15 | /* Disconnect after receiving the reply to GET */ 16 | redisAsyncDisconnect(c); 17 | } 18 | 19 | void connectCallback(const redisAsyncContext *c, int status) { 20 | if (status != REDIS_OK) { 21 | printf("Error: %s\n", c->errstr); 22 | return; 23 | } 24 | printf("Connected...\n"); 25 | } 26 | 27 | void disconnectCallback(const redisAsyncContext *c, int status) { 28 | if (status != REDIS_OK) { 29 | printf("Error: %s\n", c->errstr); 30 | return; 31 | } 32 | printf("Disconnected...\n"); 33 | } 34 | 35 | int main (int argc, char **argv) { 36 | signal(SIGPIPE, SIG_IGN); 37 | struct event_base *base = event_base_new(); 38 | 39 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 40 | if (c->err) { 41 | /* Let *c leak for now... */ 42 | printf("Error: %s\n", c->errstr); 43 | return 1; 44 | } 45 | 46 | redisLibeventAttach(c,base); 47 | redisAsyncSetConnectCallback(c,connectCallback); 48 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 49 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 50 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 51 | event_base_dispatch(base); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /deps/lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /tests/unit/latency-monitor.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"latency-monitor"}} { 2 | # Set a threshold high enough to avoid spurious latency events. 3 | r config set latency-monitor-threshold 200 4 | r latency reset 5 | 6 | test {Test latency events logging} { 7 | r debug sleep 0.3 8 | after 1100 9 | r debug sleep 0.4 10 | after 1100 11 | r debug sleep 0.5 12 | assert {[r latency history command] >= 3} 13 | } 14 | 15 | test {LATENCY HISTORY output is ok} { 16 | set min 250 17 | set max 450 18 | foreach event [r latency history command] { 19 | lassign $event time latency 20 | assert {$latency >= $min && $latency <= $max} 21 | incr min 100 22 | incr max 100 23 | set last_time $time ; # Used in the next test 24 | } 25 | } 26 | 27 | test {LATENCY LATEST output is ok} { 28 | foreach event [r latency latest] { 29 | lassign $event eventname time latency max 30 | assert {$eventname eq "command"} 31 | assert {$max >= 450 & $max <= 650} 32 | assert {$time == $last_time} 33 | break 34 | } 35 | } 36 | 37 | test {LATENCY HISTORY / RESET with wrong event name is fine} { 38 | assert {[llength [r latency history blabla]] == 0} 39 | assert {[r latency reset blabla] == 0} 40 | } 41 | 42 | test {LATENCY DOCTOR produces some output} { 43 | assert {[string length [r latency doctor]] > 0} 44 | } 45 | 46 | test {LATENCY RESET is able to reset events} { 47 | assert {[r latency reset] > 0} 48 | assert {[r latency latest] eq {}} 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/tsd.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define THREAD_DATA 0x72b65c10 4 | 5 | typedef unsigned int data_t; 6 | 7 | static bool data_cleanup_executed; 8 | 9 | void 10 | data_cleanup(void *arg) 11 | { 12 | data_t *data = (data_t *)arg; 13 | 14 | assert_x_eq(*data, THREAD_DATA, 15 | "Argument passed into cleanup function should match tsd value"); 16 | data_cleanup_executed = true; 17 | } 18 | 19 | malloc_tsd_protos(, data, data_t) 20 | malloc_tsd_externs(data, data_t) 21 | #define DATA_INIT 0x12345678 22 | malloc_tsd_data(, data, data_t, DATA_INIT) 23 | malloc_tsd_funcs(, data, data_t, DATA_INIT, data_cleanup) 24 | 25 | static void * 26 | thd_start(void *arg) 27 | { 28 | data_t d = (data_t)(uintptr_t)arg; 29 | assert_x_eq(*data_tsd_get(), DATA_INIT, 30 | "Initial tsd get should return initialization value"); 31 | 32 | data_tsd_set(&d); 33 | assert_x_eq(*data_tsd_get(), d, 34 | "After tsd set, tsd get should return value that was set"); 35 | 36 | d = 0; 37 | assert_x_eq(*data_tsd_get(), (data_t)(uintptr_t)arg, 38 | "Resetting local data should have no effect on tsd"); 39 | 40 | return (NULL); 41 | } 42 | 43 | TEST_BEGIN(test_tsd_main_thread) 44 | { 45 | 46 | thd_start((void *) 0xa5f3e329); 47 | } 48 | TEST_END 49 | 50 | TEST_BEGIN(test_tsd_sub_thread) 51 | { 52 | thd_t thd; 53 | 54 | data_cleanup_executed = false; 55 | thd_create(&thd, thd_start, (void *)THREAD_DATA); 56 | thd_join(thd, NULL); 57 | assert_true(data_cleanup_executed, 58 | "Cleanup function should have executed"); 59 | } 60 | TEST_END 61 | 62 | int 63 | main(void) 64 | { 65 | 66 | data_tsd_boot(); 67 | 68 | return (test( 69 | test_tsd_main_thread, 70 | test_tsd_sub_thread)); 71 | } 72 | -------------------------------------------------------------------------------- /deps/jemalloc/.gitignore: -------------------------------------------------------------------------------- 1 | /*.gcov.* 2 | 3 | /autom4te.cache/ 4 | 5 | /bin/jemalloc.sh 6 | 7 | /config.stamp 8 | /config.log 9 | /config.status 10 | /configure 11 | 12 | /doc/html.xsl 13 | /doc/manpages.xsl 14 | /doc/jemalloc.xml 15 | /doc/jemalloc.html 16 | /doc/jemalloc.3 17 | 18 | /lib/ 19 | 20 | /Makefile 21 | 22 | /include/jemalloc/internal/jemalloc_internal.h 23 | /include/jemalloc/internal/jemalloc_internal_defs.h 24 | /include/jemalloc/internal/private_namespace.h 25 | /include/jemalloc/internal/private_unnamespace.h 26 | /include/jemalloc/internal/public_namespace.h 27 | /include/jemalloc/internal/public_symbols.txt 28 | /include/jemalloc/internal/public_unnamespace.h 29 | /include/jemalloc/internal/size_classes.h 30 | /include/jemalloc/jemalloc.h 31 | /include/jemalloc/jemalloc_defs.h 32 | /include/jemalloc/jemalloc_macros.h 33 | /include/jemalloc/jemalloc_mangle.h 34 | /include/jemalloc/jemalloc_mangle_jet.h 35 | /include/jemalloc/jemalloc_protos.h 36 | /include/jemalloc/jemalloc_protos_jet.h 37 | /include/jemalloc/jemalloc_rename.h 38 | 39 | /src/*.[od] 40 | /src/*.gcda 41 | /src/*.gcno 42 | 43 | /test/test.sh 44 | test/include/test/jemalloc_test.h 45 | test/include/test/jemalloc_test_defs.h 46 | 47 | /test/integration/[A-Za-z]* 48 | !/test/integration/[A-Za-z]*.* 49 | /test/integration/*.[od] 50 | /test/integration/*.gcda 51 | /test/integration/*.gcno 52 | /test/integration/*.out 53 | 54 | /test/src/*.[od] 55 | /test/src/*.gcda 56 | /test/src/*.gcno 57 | 58 | /test/stress/[A-Za-z]* 59 | !/test/stress/[A-Za-z]*.* 60 | /test/stress/*.[od] 61 | /test/stress/*.gcda 62 | /test/stress/*.gcno 63 | /test/stress/*.out 64 | 65 | /test/unit/[A-Za-z]* 66 | !/test/unit/[A-Za-z]*.* 67 | /test/unit/*.[od] 68 | /test/unit/*.gcda 69 | /test/unit/*.gcno 70 | /test/unit/*.out 71 | 72 | /VERSION 73 | -------------------------------------------------------------------------------- /deps/lua/test/sort.lua: -------------------------------------------------------------------------------- 1 | -- two implementations of a sort function 2 | -- this is an example only. Lua has now a built-in function "sort" 3 | 4 | -- extracted from Programming Pearls, page 110 5 | function qsort(x,l,u,f) 6 | if ly end) 58 | show("after reverse selection sort",x) 59 | qsort(x,1,n,function (x,y) return x. 5 | All rights reserved. 6 | Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | Copyright (C) 2009-2014 Facebook, Inc. All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 1. Redistributions of source code must retain the above copyright notice(s), 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * JEMALLOC_ALWAYS_INLINE and JEMALLOC_INLINE are used within header files for 3 | * functions that are static inline functions if inlining is enabled, and 4 | * single-definition library-private functions if inlining is disabled. 5 | * 6 | * JEMALLOC_ALWAYS_INLINE_C and JEMALLOC_INLINE_C are for use in .c files, in 7 | * which case the denoted functions are always static, regardless of whether 8 | * inlining is enabled. 9 | */ 10 | #if defined(JEMALLOC_DEBUG) || defined(JEMALLOC_CODE_COVERAGE) 11 | /* Disable inlining to make debugging/profiling easier. */ 12 | # define JEMALLOC_ALWAYS_INLINE 13 | # define JEMALLOC_ALWAYS_INLINE_C static 14 | # define JEMALLOC_INLINE 15 | # define JEMALLOC_INLINE_C static 16 | # define inline 17 | #else 18 | # define JEMALLOC_ENABLE_INLINE 19 | # ifdef JEMALLOC_HAVE_ATTR 20 | # define JEMALLOC_ALWAYS_INLINE \ 21 | static inline JEMALLOC_ATTR(unused) JEMALLOC_ATTR(always_inline) 22 | # define JEMALLOC_ALWAYS_INLINE_C \ 23 | static inline JEMALLOC_ATTR(always_inline) 24 | # else 25 | # define JEMALLOC_ALWAYS_INLINE static inline 26 | # define JEMALLOC_ALWAYS_INLINE_C static inline 27 | # endif 28 | # define JEMALLOC_INLINE static inline 29 | # define JEMALLOC_INLINE_C static inline 30 | # ifdef _MSC_VER 31 | # define inline _inline 32 | # endif 33 | #endif 34 | 35 | #ifdef JEMALLOC_CC_SILENCE 36 | # define UNUSED JEMALLOC_ATTR(unused) 37 | #else 38 | # define UNUSED 39 | #endif 40 | 41 | #define ZU(z) ((size_t)z) 42 | #define QU(q) ((uint64_t)q) 43 | #define QI(q) ((int64_t)q) 44 | 45 | #ifndef __DECONST 46 | # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 47 | #endif 48 | 49 | #ifndef JEMALLOC_HAS_RESTRICT 50 | # define restrict 51 | #endif 52 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/zero.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef JEMALLOC_FILL 4 | const char *malloc_conf = 5 | "abort:false,junk:false,zero:true,redzone:false,quarantine:0"; 6 | #endif 7 | 8 | static void 9 | test_zero(size_t sz_min, size_t sz_max) 10 | { 11 | char *s; 12 | size_t sz_prev, sz, i; 13 | 14 | sz_prev = 0; 15 | s = (char *)mallocx(sz_min, 0); 16 | assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 17 | 18 | for (sz = sallocx(s, 0); sz <= sz_max; 19 | sz_prev = sz, sz = sallocx(s, 0)) { 20 | if (sz_prev > 0) { 21 | assert_c_eq(s[0], 'a', 22 | "Previously allocated byte %zu/%zu is corrupted", 23 | ZU(0), sz_prev); 24 | assert_c_eq(s[sz_prev-1], 'a', 25 | "Previously allocated byte %zu/%zu is corrupted", 26 | sz_prev-1, sz_prev); 27 | } 28 | 29 | for (i = sz_prev; i < sz; i++) { 30 | assert_c_eq(s[i], 0x0, 31 | "Newly allocated byte %zu/%zu isn't zero-filled", 32 | i, sz); 33 | s[i] = 'a'; 34 | } 35 | 36 | if (xallocx(s, sz+1, 0, 0) == sz) { 37 | s = (char *)rallocx(s, sz+1, 0); 38 | assert_ptr_not_null((void *)s, 39 | "Unexpected rallocx() failure"); 40 | } 41 | } 42 | 43 | dallocx(s, 0); 44 | } 45 | 46 | TEST_BEGIN(test_zero_small) 47 | { 48 | 49 | test_skip_if(!config_fill); 50 | test_zero(1, SMALL_MAXCLASS-1); 51 | } 52 | TEST_END 53 | 54 | TEST_BEGIN(test_zero_large) 55 | { 56 | 57 | test_skip_if(!config_fill); 58 | test_zero(SMALL_MAXCLASS+1, arena_maxclass); 59 | } 60 | TEST_END 61 | 62 | TEST_BEGIN(test_zero_huge) 63 | { 64 | 65 | test_skip_if(!config_fill); 66 | test_zero(arena_maxclass+1, chunksize*2); 67 | } 68 | TEST_END 69 | 70 | int 71 | main(void) 72 | { 73 | 74 | return (test( 75 | test_zero_small, 76 | test_zero_large, 77 | test_zero_huge)); 78 | } 79 | -------------------------------------------------------------------------------- /deps/lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /tests/cluster/tests/00-base.tcl: -------------------------------------------------------------------------------- 1 | # Check the basic monitoring and failover capabilities. 2 | 3 | source "../tests/includes/init-tests.tcl" 4 | 5 | if {$::simulate_error} { 6 | test "This test will fail" { 7 | fail "Simulated error" 8 | } 9 | } 10 | 11 | test "Different nodes have different IDs" { 12 | set ids {} 13 | set numnodes 0 14 | foreach_redis_id id { 15 | incr numnodes 16 | # Every node should just know itself. 17 | set nodeid [dict get [get_myself $id] id] 18 | assert {$nodeid ne {}} 19 | lappend ids $nodeid 20 | } 21 | set numids [llength [lsort -unique $ids]] 22 | assert {$numids == $numnodes} 23 | } 24 | 25 | test "It is possible to perform slot allocation" { 26 | cluster_allocate_slots 5 27 | } 28 | 29 | test "After the join, every node gets a different config epoch" { 30 | set trynum 60 31 | while {[incr trynum -1] != 0} { 32 | # We check that this condition is true for *all* the nodes. 33 | set ok 1 ; # Will be set to 0 every time a node is not ok. 34 | foreach_redis_id id { 35 | set epochs {} 36 | foreach n [get_cluster_nodes $id] { 37 | lappend epochs [dict get $n config_epoch] 38 | } 39 | if {[lsort $epochs] != [lsort -unique $epochs]} { 40 | set ok 0 ; # At least one collision! 41 | } 42 | } 43 | if {$ok} break 44 | after 1000 45 | puts -nonewline . 46 | flush stdout 47 | } 48 | if {$trynum == 0} { 49 | fail "Config epoch conflict resolution is not working." 50 | } 51 | } 52 | 53 | test "Nodes should report cluster_state is ok now" { 54 | assert_cluster_state ok 55 | } 56 | 57 | test "It is possible to write and read from the cluster" { 58 | cluster_write_test 0 59 | } 60 | -------------------------------------------------------------------------------- /deps/hiredis/examples/example-ae.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* Put event loop in the global scope, so it can be explicitly stopped */ 11 | static aeEventLoop *loop; 12 | 13 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 14 | redisReply *reply = r; 15 | if (reply == NULL) return; 16 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 17 | 18 | /* Disconnect after receiving the reply to GET */ 19 | redisAsyncDisconnect(c); 20 | } 21 | 22 | void connectCallback(const redisAsyncContext *c, int status) { 23 | if (status != REDIS_OK) { 24 | printf("Error: %s\n", c->errstr); 25 | aeStop(loop); 26 | return; 27 | } 28 | 29 | printf("Connected...\n"); 30 | } 31 | 32 | void disconnectCallback(const redisAsyncContext *c, int status) { 33 | if (status != REDIS_OK) { 34 | printf("Error: %s\n", c->errstr); 35 | aeStop(loop); 36 | return; 37 | } 38 | 39 | printf("Disconnected...\n"); 40 | aeStop(loop); 41 | } 42 | 43 | int main (int argc, char **argv) { 44 | signal(SIGPIPE, SIG_IGN); 45 | 46 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 47 | if (c->err) { 48 | /* Let *c leak for now... */ 49 | printf("Error: %s\n", c->errstr); 50 | return 1; 51 | } 52 | 53 | loop = aeCreateEventLoop(64); 54 | redisAeAttach(loop, c); 55 | redisAsyncSetConnectCallback(c,connectCallback); 56 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 57 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 58 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 59 | aeMain(loop); 60 | return 0; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef REDIS_RANDOM_H 31 | #define REDIS_RANDOM_H 32 | 33 | int32_t redisLrand48(); 34 | void redisSrand48(int32_t seedval); 35 | 36 | #define REDIS_LRAND48_MAX INT32_MAX 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/huge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | /* Huge allocation statistics. */ 13 | extern uint64_t huge_nmalloc; 14 | extern uint64_t huge_ndalloc; 15 | extern size_t huge_allocated; 16 | 17 | /* Protects chunk-related data structures. */ 18 | extern malloc_mutex_t huge_mtx; 19 | 20 | void *huge_malloc(size_t size, bool zero, dss_prec_t dss_prec); 21 | void *huge_palloc(size_t size, size_t alignment, bool zero, 22 | dss_prec_t dss_prec); 23 | bool huge_ralloc_no_move(void *ptr, size_t oldsize, size_t size, 24 | size_t extra); 25 | void *huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, 26 | size_t alignment, bool zero, bool try_tcache_dalloc, dss_prec_t dss_prec); 27 | #ifdef JEMALLOC_JET 28 | typedef void (huge_dalloc_junk_t)(void *, size_t); 29 | extern huge_dalloc_junk_t *huge_dalloc_junk; 30 | #endif 31 | void huge_dalloc(void *ptr, bool unmap); 32 | size_t huge_salloc(const void *ptr); 33 | dss_prec_t huge_dss_prec_get(arena_t *arena); 34 | prof_ctx_t *huge_prof_ctx_get(const void *ptr); 35 | void huge_prof_ctx_set(const void *ptr, prof_ctx_t *ctx); 36 | bool huge_boot(void); 37 | void huge_prefork(void); 38 | void huge_postfork_parent(void); 39 | void huge_postfork_child(void); 40 | 41 | #endif /* JEMALLOC_H_EXTERNS */ 42 | /******************************************************************************/ 43 | #ifdef JEMALLOC_H_INLINES 44 | 45 | #endif /* JEMALLOC_H_INLINES */ 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /deps/jemalloc/test/integration/thread_arena.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 10 4 | 5 | void * 6 | thd_start(void *arg) 7 | { 8 | unsigned main_arena_ind = *(unsigned *)arg; 9 | void *p; 10 | unsigned arena_ind; 11 | size_t size; 12 | int err; 13 | 14 | p = malloc(1); 15 | assert_ptr_not_null(p, "Error in malloc()"); 16 | free(p); 17 | 18 | size = sizeof(arena_ind); 19 | if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, 20 | sizeof(main_arena_ind)))) { 21 | char buf[BUFERROR_BUF]; 22 | 23 | buferror(err, buf, sizeof(buf)); 24 | test_fail("Error in mallctl(): %s", buf); 25 | } 26 | 27 | size = sizeof(arena_ind); 28 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { 29 | char buf[BUFERROR_BUF]; 30 | 31 | buferror(err, buf, sizeof(buf)); 32 | test_fail("Error in mallctl(): %s", buf); 33 | } 34 | assert_u_eq(arena_ind, main_arena_ind, 35 | "Arena index should be same as for main thread"); 36 | 37 | return (NULL); 38 | } 39 | 40 | TEST_BEGIN(test_thread_arena) 41 | { 42 | void *p; 43 | unsigned arena_ind; 44 | size_t size; 45 | int err; 46 | thd_t thds[NTHREADS]; 47 | unsigned i; 48 | 49 | p = malloc(1); 50 | assert_ptr_not_null(p, "Error in malloc()"); 51 | 52 | size = sizeof(arena_ind); 53 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { 54 | char buf[BUFERROR_BUF]; 55 | 56 | buferror(err, buf, sizeof(buf)); 57 | test_fail("Error in mallctl(): %s", buf); 58 | } 59 | 60 | for (i = 0; i < NTHREADS; i++) { 61 | thd_create(&thds[i], thd_start, 62 | (void *)&arena_ind); 63 | } 64 | 65 | for (i = 0; i < NTHREADS; i++) { 66 | intptr_t join_ret; 67 | thd_join(thds[i], (void *)&join_ret); 68 | assert_zd_eq(join_ret, 0, "Unexpected thread join error"); 69 | } 70 | } 71 | TEST_END 72 | 73 | int 74 | main(void) 75 | { 76 | 77 | return (test( 78 | test_thread_arena)); 79 | } 80 | -------------------------------------------------------------------------------- /utils/redis-sha1.rb: -------------------------------------------------------------------------------- 1 | # redis-sha1.rb - Copyright (C) 2009 Salvatore Sanfilippo 2 | # BSD license, See the COPYING file for more information. 3 | # 4 | # Performs the SHA1 sum of the whole datset. 5 | # This is useful to spot bugs in persistence related code and to make sure 6 | # Slaves and Masters are in SYNC. 7 | # 8 | # If you hack this code make sure to sort keys and set elements as this are 9 | # unsorted elements. Otherwise the sum may differ with equal dataset. 10 | 11 | require 'rubygems' 12 | require 'redis' 13 | require 'digest/sha1' 14 | 15 | def redisSha1(opts={}) 16 | sha1="" 17 | r = Redis.new(opts) 18 | r.keys('*').sort.each{|k| 19 | vtype = r.type?(k) 20 | if vtype == "string" 21 | len = 1 22 | sha1 = Digest::SHA1.hexdigest(sha1+k) 23 | sha1 = Digest::SHA1.hexdigest(sha1+r.get(k)) 24 | elsif vtype == "list" 25 | len = r.llen(k) 26 | if len != 0 27 | sha1 = Digest::SHA1.hexdigest(sha1+k) 28 | sha1 = Digest::SHA1.hexdigest(sha1+r.list_range(k,0,-1).join("\x01")) 29 | end 30 | elsif vtype == "set" 31 | len = r.scard(k) 32 | if len != 0 33 | sha1 = Digest::SHA1.hexdigest(sha1+k) 34 | sha1 = Digest::SHA1.hexdigest(sha1+r.set_members(k).to_a.sort.join("\x02")) 35 | end 36 | elsif vtype == "zset" 37 | len = r.zcard(k) 38 | if len != 0 39 | sha1 = Digest::SHA1.hexdigest(sha1+k) 40 | sha1 = Digest::SHA1.hexdigest(sha1+r.zrange(k,0,-1).join("\x01")) 41 | end 42 | end 43 | # puts "#{k} => #{sha1}" if len != 0 44 | } 45 | sha1 46 | end 47 | 48 | host = ARGV[0] || "127.0.0.1" 49 | port = ARGV[1] || "6379" 50 | db = ARGV[2] || "0" 51 | puts "Performing SHA1 of Redis server #{host} #{port} DB: #{db}" 52 | p "Dataset SHA1: #{redisSha1(:host => host, :port => port.to_i, :db => db)}" 53 | -------------------------------------------------------------------------------- /deps/lua/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /deps/lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/pqsort.h: -------------------------------------------------------------------------------- 1 | /* The following is the NetBSD libc qsort implementation modified in order to 2 | * support partial sorting of ranges for Redis. 3 | * 4 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of Redis nor the names of its contributors may be used 16 | * to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * See the pqsort.c file for the original copyright notice. */ 32 | 33 | #ifndef __PQSORT_H 34 | #define __PQSORT_H 35 | 36 | void 37 | pqsort(void *a, size_t n, size_t es, 38 | int (*cmp) (const void *, const void *), size_t lrange, size_t rrange); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /deps/lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/quarantine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct quarantine_obj_s quarantine_obj_t; 5 | typedef struct quarantine_s quarantine_t; 6 | 7 | /* Default per thread quarantine size if valgrind is enabled. */ 8 | #define JEMALLOC_VALGRIND_QUARANTINE_DEFAULT (ZU(1) << 24) 9 | 10 | #endif /* JEMALLOC_H_TYPES */ 11 | /******************************************************************************/ 12 | #ifdef JEMALLOC_H_STRUCTS 13 | 14 | struct quarantine_obj_s { 15 | void *ptr; 16 | size_t usize; 17 | }; 18 | 19 | struct quarantine_s { 20 | size_t curbytes; 21 | size_t curobjs; 22 | size_t first; 23 | #define LG_MAXOBJS_INIT 10 24 | size_t lg_maxobjs; 25 | quarantine_obj_t objs[1]; /* Dynamically sized ring buffer. */ 26 | }; 27 | 28 | #endif /* JEMALLOC_H_STRUCTS */ 29 | /******************************************************************************/ 30 | #ifdef JEMALLOC_H_EXTERNS 31 | 32 | quarantine_t *quarantine_init(size_t lg_maxobjs); 33 | void quarantine(void *ptr); 34 | void quarantine_cleanup(void *arg); 35 | bool quarantine_boot(void); 36 | 37 | #endif /* JEMALLOC_H_EXTERNS */ 38 | /******************************************************************************/ 39 | #ifdef JEMALLOC_H_INLINES 40 | 41 | #ifndef JEMALLOC_ENABLE_INLINE 42 | malloc_tsd_protos(JEMALLOC_ATTR(unused), quarantine, quarantine_t *) 43 | 44 | void quarantine_alloc_hook(void); 45 | #endif 46 | 47 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_QUARANTINE_C_)) 48 | malloc_tsd_externs(quarantine, quarantine_t *) 49 | malloc_tsd_funcs(JEMALLOC_ALWAYS_INLINE, quarantine, quarantine_t *, NULL, 50 | quarantine_cleanup) 51 | 52 | JEMALLOC_ALWAYS_INLINE void 53 | quarantine_alloc_hook(void) 54 | { 55 | quarantine_t *quarantine; 56 | 57 | assert(config_fill && opt_quarantine); 58 | 59 | quarantine = *quarantine_tsd_get(); 60 | if (quarantine == NULL) 61 | quarantine_init(LG_MAXOBJS_INIT); 62 | } 63 | #endif 64 | 65 | #endif /* JEMALLOC_H_INLINES */ 66 | /******************************************************************************/ 67 | 68 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/prof_accum.c: -------------------------------------------------------------------------------- 1 | #include "prof_accum.h" 2 | 3 | #ifdef JEMALLOC_PROF 4 | const char *malloc_conf = 5 | "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0"; 6 | #endif 7 | 8 | static int 9 | prof_dump_open_intercept(bool propagate_err, const char *filename) 10 | { 11 | int fd; 12 | 13 | fd = open("/dev/null", O_WRONLY); 14 | assert_d_ne(fd, -1, "Unexpected open() failure"); 15 | 16 | return (fd); 17 | } 18 | 19 | static void * 20 | alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration) 21 | { 22 | 23 | return (alloc_0(thd_ind*NALLOCS_PER_THREAD + iteration)); 24 | } 25 | 26 | static void * 27 | thd_start(void *varg) 28 | { 29 | unsigned thd_ind = *(unsigned *)varg; 30 | size_t bt_count_prev, bt_count; 31 | unsigned i_prev, i; 32 | 33 | i_prev = 0; 34 | bt_count_prev = 0; 35 | for (i = 0; i < NALLOCS_PER_THREAD; i++) { 36 | void *p = alloc_from_permuted_backtrace(thd_ind, i); 37 | dallocx(p, 0); 38 | if (i % DUMP_INTERVAL == 0) { 39 | assert_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0), 40 | 0, "Unexpected error while dumping heap profile"); 41 | } 42 | 43 | if (i % BT_COUNT_CHECK_INTERVAL == 0 || 44 | i+1 == NALLOCS_PER_THREAD) { 45 | bt_count = prof_bt_count(); 46 | assert_zu_le(bt_count_prev+(i-i_prev), bt_count, 47 | "Expected larger backtrace count increase"); 48 | i_prev = i; 49 | bt_count_prev = bt_count; 50 | } 51 | } 52 | 53 | return (NULL); 54 | } 55 | 56 | TEST_BEGIN(test_idump) 57 | { 58 | bool active; 59 | thd_t thds[NTHREADS]; 60 | unsigned thd_args[NTHREADS]; 61 | unsigned i; 62 | 63 | test_skip_if(!config_prof); 64 | 65 | active = true; 66 | assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)), 67 | 0, "Unexpected mallctl failure while activating profiling"); 68 | 69 | prof_dump_open = prof_dump_open_intercept; 70 | 71 | for (i = 0; i < NTHREADS; i++) { 72 | thd_args[i] = i; 73 | thd_create(&thds[i], thd_start, (void *)&thd_args[i]); 74 | } 75 | for (i = 0; i < NTHREADS; i++) 76 | thd_join(thds[i], NULL); 77 | } 78 | TEST_END 79 | 80 | int 81 | main(void) 82 | { 83 | 84 | return (test( 85 | test_idump)); 86 | } 87 | -------------------------------------------------------------------------------- /tests/cluster/tests/includes/init-tests.tcl: -------------------------------------------------------------------------------- 1 | # Initialization tests -- most units will start including this. 2 | 3 | test "(init) Restart killed instances" { 4 | foreach type {redis} { 5 | foreach_${type}_id id { 6 | if {[get_instance_attrib $type $id pid] == -1} { 7 | puts -nonewline "$type/$id " 8 | flush stdout 9 | restart_instance $type $id 10 | } 11 | } 12 | } 13 | } 14 | 15 | test "Cluster nodes are reachable" { 16 | foreach_redis_id id { 17 | # Every node should be reachable. 18 | wait_for_condition 1000 50 { 19 | ([catch {R $id ping} ping_reply] == 0) && 20 | ($ping_reply eq {PONG}) 21 | } else { 22 | catch {R $id ping} err 23 | fail "Node #$id keeps replying '$err' to PING." 24 | } 25 | } 26 | } 27 | 28 | test "Cluster nodes hard reset" { 29 | foreach_redis_id id { 30 | catch {R $id flushall} ; # May fail for readonly slaves. 31 | R $id cluster reset hard 32 | R $id cluster set-config-epoch [expr {$id+1}] 33 | R $id config set cluster-node-timeout 3000 34 | R $id config set cluster-slave-validity-factor 10 35 | R $id config rewrite 36 | } 37 | } 38 | 39 | test "Cluster Join and auto-discovery test" { 40 | # Join node 0 with 1, 1 with 2, ... and so forth. 41 | # If auto-discovery works all nodes will know every other node 42 | # eventually. 43 | set ids {} 44 | foreach_redis_id id {lappend ids $id} 45 | for {set j 0} {$j < [expr [llength $ids]-1]} {incr j} { 46 | set a [lindex $ids $j] 47 | set b [lindex $ids [expr $j+1]] 48 | set b_port [get_instance_attrib redis $b port] 49 | R $a cluster meet 127.0.0.1 $b_port 50 | } 51 | 52 | foreach_redis_id id { 53 | wait_for_condition 1000 50 { 54 | [llength [get_cluster_nodes $id]] == [llength $ids] 55 | } else { 56 | fail "Cluster failed to join into a full mesh." 57 | } 58 | } 59 | } 60 | 61 | test "Before slots allocation, all nodes report cluster failure" { 62 | assert_cluster_state fail 63 | } 64 | -------------------------------------------------------------------------------- /tests/unit/introspection.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"introspection"}} { 2 | test {CLIENT LIST} { 3 | r client list 4 | } {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=* obl=0 oll=0 omem=0 events=r cmd=client*} 5 | 6 | test {MONITOR can log executed commands} { 7 | set rd [redis_deferring_client] 8 | $rd monitor 9 | r set foo bar 10 | r get foo 11 | list [$rd read] [$rd read] [$rd read] 12 | } {*OK*"set" "foo"*"get" "foo"*} 13 | 14 | test {MONITOR can log commands issued by the scripting engine} { 15 | set rd [redis_deferring_client] 16 | $rd monitor 17 | r eval {redis.call('set',KEYS[1],ARGV[1])} 1 foo bar 18 | $rd read ;# Discard the OK 19 | assert_match {*eval*} [$rd read] 20 | assert_match {*lua*"set"*"foo"*"bar"*} [$rd read] 21 | } 22 | 23 | test {CLIENT GETNAME should return NIL if name is not assigned} { 24 | r client getname 25 | } {} 26 | 27 | test {CLIENT LIST shows empty fields for unassigned names} { 28 | r client list 29 | } {*name= *} 30 | 31 | test {CLIENT SETNAME does not accept spaces} { 32 | catch {r client setname "foo bar"} e 33 | set e 34 | } {ERR*} 35 | 36 | test {CLIENT SETNAME can assign a name to this connection} { 37 | assert_equal [r client setname myname] {OK} 38 | r client list 39 | } {*name=myname*} 40 | 41 | test {CLIENT SETNAME can change the name of an existing connection} { 42 | assert_equal [r client setname someothername] {OK} 43 | r client list 44 | } {*name=someothername*} 45 | 46 | test {After CLIENT SETNAME, connection can still be closed} { 47 | set rd [redis_deferring_client] 48 | $rd client setname foobar 49 | assert_equal [$rd read] "OK" 50 | assert_match {*foobar*} [r client list] 51 | $rd close 52 | # Now the client should no longer be listed 53 | wait_for_condition 50 100 { 54 | [string match {*foobar*} [r client list]] == 0 55 | } else { 56 | fail "Client still listed in CLIENT LIST after SETNAME." 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /deps/jemalloc/test/unit/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NSENDERS 3 4 | #define NMSGS 100000 5 | 6 | typedef struct mq_msg_s mq_msg_t; 7 | struct mq_msg_s { 8 | mq_msg(mq_msg_t) link; 9 | }; 10 | mq_gen(static, mq_, mq_t, mq_msg_t, link) 11 | 12 | TEST_BEGIN(test_mq_basic) 13 | { 14 | mq_t mq; 15 | mq_msg_t msg; 16 | 17 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 18 | assert_u_eq(mq_count(&mq), 0, "mq should be empty"); 19 | assert_ptr_null(mq_tryget(&mq), 20 | "mq_tryget() should fail when the queue is empty"); 21 | 22 | mq_put(&mq, &msg); 23 | assert_u_eq(mq_count(&mq), 1, "mq should contain one message"); 24 | assert_ptr_eq(mq_tryget(&mq), &msg, "mq_tryget() should return msg"); 25 | 26 | mq_put(&mq, &msg); 27 | assert_ptr_eq(mq_get(&mq), &msg, "mq_get() should return msg"); 28 | 29 | mq_fini(&mq); 30 | } 31 | TEST_END 32 | 33 | static void * 34 | thd_receiver_start(void *arg) 35 | { 36 | mq_t *mq = (mq_t *)arg; 37 | unsigned i; 38 | 39 | for (i = 0; i < (NSENDERS * NMSGS); i++) { 40 | mq_msg_t *msg = mq_get(mq); 41 | assert_ptr_not_null(msg, "mq_get() should never return NULL"); 42 | dallocx(msg, 0); 43 | } 44 | return (NULL); 45 | } 46 | 47 | static void * 48 | thd_sender_start(void *arg) 49 | { 50 | mq_t *mq = (mq_t *)arg; 51 | unsigned i; 52 | 53 | for (i = 0; i < NMSGS; i++) { 54 | mq_msg_t *msg; 55 | void *p; 56 | p = mallocx(sizeof(mq_msg_t), 0); 57 | assert_ptr_not_null(p, "Unexpected allocm() failure"); 58 | msg = (mq_msg_t *)p; 59 | mq_put(mq, msg); 60 | } 61 | return (NULL); 62 | } 63 | 64 | TEST_BEGIN(test_mq_threaded) 65 | { 66 | mq_t mq; 67 | thd_t receiver; 68 | thd_t senders[NSENDERS]; 69 | unsigned i; 70 | 71 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 72 | 73 | thd_create(&receiver, thd_receiver_start, (void *)&mq); 74 | for (i = 0; i < NSENDERS; i++) 75 | thd_create(&senders[i], thd_sender_start, (void *)&mq); 76 | 77 | thd_join(receiver, NULL); 78 | for (i = 0; i < NSENDERS; i++) 79 | thd_join(senders[i], NULL); 80 | 81 | mq_fini(&mq); 82 | } 83 | TEST_END 84 | 85 | int 86 | main(void) 87 | { 88 | return (test( 89 | test_mq_basic, 90 | test_mq_threaded)); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /src/bio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* Exported API */ 31 | void bioInit(void); 32 | void bioCreateBackgroundJob(int type, void *arg1, void *arg2, void *arg3); 33 | unsigned long long bioPendingJobsOfType(int type); 34 | void bioWaitPendingJobsLE(int type, unsigned long long num); 35 | time_t bioOlderJobOfType(int type); 36 | void bioKillThreads(void); 37 | 38 | /* Background job opcodes */ 39 | #define REDIS_BIO_CLOSE_FILE 0 /* Deferred close(2) syscall. */ 40 | #define REDIS_BIO_AOF_FSYNC 1 /* Deferred AOF fsync. */ 41 | #define REDIS_BIO_NUM_OPS 2 42 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/prng.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | /* 5 | * Simple linear congruential pseudo-random number generator: 6 | * 7 | * prng(y) = (a*x + c) % m 8 | * 9 | * where the following constants ensure maximal period: 10 | * 11 | * a == Odd number (relatively prime to 2^n), and (a-1) is a multiple of 4. 12 | * c == Odd number (relatively prime to 2^n). 13 | * m == 2^32 14 | * 15 | * See Knuth's TAOCP 3rd Ed., Vol. 2, pg. 17 for details on these constraints. 16 | * 17 | * This choice of m has the disadvantage that the quality of the bits is 18 | * proportional to bit position. For example. the lowest bit has a cycle of 2, 19 | * the next has a cycle of 4, etc. For this reason, we prefer to use the upper 20 | * bits. 21 | * 22 | * Macro parameters: 23 | * uint32_t r : Result. 24 | * unsigned lg_range : (0..32], number of least significant bits to return. 25 | * uint32_t state : Seed value. 26 | * const uint32_t a, c : See above discussion. 27 | */ 28 | #define prng32(r, lg_range, state, a, c) do { \ 29 | assert(lg_range > 0); \ 30 | assert(lg_range <= 32); \ 31 | \ 32 | r = (state * (a)) + (c); \ 33 | state = r; \ 34 | r >>= (32 - lg_range); \ 35 | } while (false) 36 | 37 | /* Same as prng32(), but 64 bits of pseudo-randomness, using uint64_t. */ 38 | #define prng64(r, lg_range, state, a, c) do { \ 39 | assert(lg_range > 0); \ 40 | assert(lg_range <= 64); \ 41 | \ 42 | r = (state * (a)) + (c); \ 43 | state = r; \ 44 | r >>= (64 - lg_range); \ 45 | } while (false) 46 | 47 | #endif /* JEMALLOC_H_TYPES */ 48 | /******************************************************************************/ 49 | #ifdef JEMALLOC_H_STRUCTS 50 | 51 | #endif /* JEMALLOC_H_STRUCTS */ 52 | /******************************************************************************/ 53 | #ifdef JEMALLOC_H_EXTERNS 54 | 55 | #endif /* JEMALLOC_H_EXTERNS */ 56 | /******************************************************************************/ 57 | #ifdef JEMALLOC_H_INLINES 58 | 59 | #endif /* JEMALLOC_H_INLINES */ 60 | /******************************************************************************/ 61 | -------------------------------------------------------------------------------- /deps/jemalloc/test/src/test.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static unsigned test_count = 0; 4 | static test_status_t test_counts[test_status_count] = {0, 0, 0}; 5 | static test_status_t test_status = test_status_pass; 6 | static const char * test_name = ""; 7 | 8 | JEMALLOC_ATTR(format(printf, 1, 2)) 9 | void 10 | test_skip(const char *format, ...) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, format); 15 | malloc_vcprintf(NULL, NULL, format, ap); 16 | va_end(ap); 17 | malloc_printf("\n"); 18 | test_status = test_status_skip; 19 | } 20 | 21 | JEMALLOC_ATTR(format(printf, 1, 2)) 22 | void 23 | test_fail(const char *format, ...) 24 | { 25 | va_list ap; 26 | 27 | va_start(ap, format); 28 | malloc_vcprintf(NULL, NULL, format, ap); 29 | va_end(ap); 30 | malloc_printf("\n"); 31 | test_status = test_status_fail; 32 | } 33 | 34 | static const char * 35 | test_status_string(test_status_t test_status) 36 | { 37 | 38 | switch (test_status) { 39 | case test_status_pass: return "pass"; 40 | case test_status_skip: return "skip"; 41 | case test_status_fail: return "fail"; 42 | default: not_reached(); 43 | } 44 | } 45 | 46 | void 47 | p_test_init(const char *name) 48 | { 49 | 50 | test_count++; 51 | test_status = test_status_pass; 52 | test_name = name; 53 | } 54 | 55 | void 56 | p_test_fini(void) 57 | { 58 | 59 | test_counts[test_status]++; 60 | malloc_printf("%s: %s\n", test_name, test_status_string(test_status)); 61 | } 62 | 63 | test_status_t 64 | p_test(test_t* t, ...) 65 | { 66 | test_status_t ret = test_status_pass; 67 | va_list ap; 68 | 69 | va_start(ap, t); 70 | for (; t != NULL; t = va_arg(ap, test_t*)) { 71 | t(); 72 | if (test_status > ret) 73 | ret = test_status; 74 | } 75 | va_end(ap); 76 | 77 | malloc_printf("--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n", 78 | test_status_string(test_status_pass), 79 | test_counts[test_status_pass], test_count, 80 | test_status_string(test_status_skip), 81 | test_counts[test_status_skip], test_count, 82 | test_status_string(test_status_fail), 83 | test_counts[test_status_fail], test_count); 84 | 85 | return (ret); 86 | } 87 | 88 | void 89 | p_test_fail(const char *prefix, const char *message) 90 | { 91 | 92 | malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message); 93 | test_status = test_status_fail; 94 | } 95 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef __REDIS_UTIL_H 31 | #define __REDIS_UTIL_H 32 | 33 | #include "sds.h" 34 | 35 | int stringmatchlen(const char *p, int plen, const char *s, int slen, int nocase); 36 | int stringmatch(const char *p, const char *s, int nocase); 37 | long long memtoll(const char *p, int *err); 38 | int ll2string(char *s, size_t len, long long value); 39 | int string2ll(const char *s, size_t slen, long long *value); 40 | int string2l(const char *s, size_t slen, long *value); 41 | int d2string(char *buf, size_t len, double value); 42 | sds getAbsolutePath(char *filename); 43 | int pathIsBaseName(char *path); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/jemalloc_macros.h.in: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define JEMALLOC_VERSION "@jemalloc_version@" 5 | #define JEMALLOC_VERSION_MAJOR @jemalloc_version_major@ 6 | #define JEMALLOC_VERSION_MINOR @jemalloc_version_minor@ 7 | #define JEMALLOC_VERSION_BUGFIX @jemalloc_version_bugfix@ 8 | #define JEMALLOC_VERSION_NREV @jemalloc_version_nrev@ 9 | #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@" 10 | 11 | # define MALLOCX_LG_ALIGN(la) (la) 12 | # if LG_SIZEOF_PTR == 2 13 | # define MALLOCX_ALIGN(a) (ffs(a)-1) 14 | # else 15 | # define MALLOCX_ALIGN(a) \ 16 | ((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31) 17 | # endif 18 | # define MALLOCX_ZERO ((int)0x40) 19 | /* Bias arena index bits so that 0 encodes "MALLOCX_ARENA() unspecified". */ 20 | # define MALLOCX_ARENA(a) ((int)(((a)+1) << 8)) 21 | 22 | #ifdef JEMALLOC_EXPERIMENTAL 23 | # define ALLOCM_LG_ALIGN(la) (la) 24 | # if LG_SIZEOF_PTR == 2 25 | # define ALLOCM_ALIGN(a) (ffs(a)-1) 26 | # else 27 | # define ALLOCM_ALIGN(a) \ 28 | ((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31) 29 | # endif 30 | # define ALLOCM_ZERO ((int)0x40) 31 | # define ALLOCM_NO_MOVE ((int)0x80) 32 | /* Bias arena index bits so that 0 encodes "ALLOCM_ARENA() unspecified". */ 33 | # define ALLOCM_ARENA(a) ((int)(((a)+1) << 8)) 34 | # define ALLOCM_SUCCESS 0 35 | # define ALLOCM_ERR_OOM 1 36 | # define ALLOCM_ERR_NOT_MOVED 2 37 | #endif 38 | 39 | #ifdef JEMALLOC_HAVE_ATTR 40 | # define JEMALLOC_ATTR(s) __attribute__((s)) 41 | # define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default")) 42 | # define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) 43 | # define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) 44 | # define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) 45 | #elif _MSC_VER 46 | # define JEMALLOC_ATTR(s) 47 | # ifdef DLLEXPORT 48 | # define JEMALLOC_EXPORT __declspec(dllexport) 49 | # else 50 | # define JEMALLOC_EXPORT __declspec(dllimport) 51 | # endif 52 | # define JEMALLOC_ALIGNED(s) __declspec(align(s)) 53 | # define JEMALLOC_SECTION(s) __declspec(allocate(s)) 54 | # define JEMALLOC_NOINLINE __declspec(noinline) 55 | #else 56 | # define JEMALLOC_ATTR(s) 57 | # define JEMALLOC_EXPORT 58 | # define JEMALLOC_ALIGNED(s) 59 | # define JEMALLOC_SECTION(s) 60 | # define JEMALLOC_NOINLINE 61 | #endif 62 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | /* 5 | * Size and alignment of memory chunks that are allocated by the OS's virtual 6 | * memory system. 7 | */ 8 | #define LG_CHUNK_DEFAULT 22 9 | 10 | /* Return the chunk address for allocation address a. */ 11 | #define CHUNK_ADDR2BASE(a) \ 12 | ((void *)((uintptr_t)(a) & ~chunksize_mask)) 13 | 14 | /* Return the chunk offset of address a. */ 15 | #define CHUNK_ADDR2OFFSET(a) \ 16 | ((size_t)((uintptr_t)(a) & chunksize_mask)) 17 | 18 | /* Return the smallest chunk multiple that is >= s. */ 19 | #define CHUNK_CEILING(s) \ 20 | (((s) + chunksize_mask) & ~chunksize_mask) 21 | 22 | #endif /* JEMALLOC_H_TYPES */ 23 | /******************************************************************************/ 24 | #ifdef JEMALLOC_H_STRUCTS 25 | 26 | #endif /* JEMALLOC_H_STRUCTS */ 27 | /******************************************************************************/ 28 | #ifdef JEMALLOC_H_EXTERNS 29 | 30 | extern size_t opt_lg_chunk; 31 | extern const char *opt_dss; 32 | 33 | /* Protects stats_chunks; currently not used for any other purpose. */ 34 | extern malloc_mutex_t chunks_mtx; 35 | /* Chunk statistics. */ 36 | extern chunk_stats_t stats_chunks; 37 | 38 | extern rtree_t *chunks_rtree; 39 | 40 | extern size_t chunksize; 41 | extern size_t chunksize_mask; /* (chunksize - 1). */ 42 | extern size_t chunk_npages; 43 | extern size_t map_bias; /* Number of arena chunk header pages. */ 44 | extern size_t arena_maxclass; /* Max size class for arenas. */ 45 | 46 | void *chunk_alloc(size_t size, size_t alignment, bool base, bool *zero, 47 | dss_prec_t dss_prec); 48 | void chunk_unmap(void *chunk, size_t size); 49 | void chunk_dealloc(void *chunk, size_t size, bool unmap); 50 | bool chunk_boot(void); 51 | void chunk_prefork(void); 52 | void chunk_postfork_parent(void); 53 | void chunk_postfork_child(void); 54 | 55 | #endif /* JEMALLOC_H_EXTERNS */ 56 | /******************************************************************************/ 57 | #ifdef JEMALLOC_H_INLINES 58 | 59 | #endif /* JEMALLOC_H_INLINES */ 60 | /******************************************************************************/ 61 | 62 | #include "jemalloc/internal/chunk_dss.h" 63 | #include "jemalloc/internal/chunk_mmap.h" 64 | -------------------------------------------------------------------------------- /src/solarisfixes.h: -------------------------------------------------------------------------------- 1 | /* Solaris specific fixes. 2 | * 3 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #if defined(__GNUC__) 32 | #include 33 | #undef isnan 34 | #define isnan(x) \ 35 | __extension__({ __typeof (x) __x_a = (x); \ 36 | __builtin_expect(__x_a != __x_a, 0); }) 37 | 38 | #undef isfinite 39 | #define isfinite(x) \ 40 | __extension__ ({ __typeof (x) __x_f = (x); \ 41 | __builtin_expect(!isnan(__x_f - __x_f), 1); }) 42 | 43 | #undef isinf 44 | #define isinf(x) \ 45 | __extension__ ({ __typeof (x) __x_i = (x); \ 46 | __builtin_expect(!isnan(__x_i) && !isfinite(__x_i), 0); }) 47 | 48 | #define u_int uint 49 | #define u_int32_t uint32_t 50 | #endif /* __GNUC__ */ 51 | -------------------------------------------------------------------------------- /src/release.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* Every time the Redis Git SHA1 or Dirty status changes only this small 31 | * file is recompiled, as we access this information in all the other 32 | * files using this functions. */ 33 | 34 | #include 35 | 36 | #include "release.h" 37 | #include "version.h" 38 | #include "crc64.h" 39 | 40 | char *redisGitSHA1(void) { 41 | return REDIS_GIT_SHA1; 42 | } 43 | 44 | char *redisGitDirty(void) { 45 | return REDIS_GIT_DIRTY; 46 | } 47 | 48 | uint64_t redisBuildId(void) { 49 | char *buildid = REDIS_VERSION REDIS_BUILD_ID REDIS_GIT_DIRTY REDIS_GIT_SHA1; 50 | 51 | return crc64(0,(unsigned char*)buildid,strlen(buildid)); 52 | } 53 | -------------------------------------------------------------------------------- /src/slowlog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #define SLOWLOG_ENTRY_MAX_ARGC 32 31 | #define SLOWLOG_ENTRY_MAX_STRING 128 32 | 33 | /* This structure defines an entry inside the slow log list */ 34 | typedef struct slowlogEntry { 35 | robj **argv; 36 | int argc; 37 | long long id; /* Unique entry identifier. */ 38 | long long duration; /* Time spent by the query, in nanoseconds. */ 39 | time_t time; /* Unix time at which the query was executed. */ 40 | } slowlogEntry; 41 | 42 | /* Exported API */ 43 | void slowlogInit(void); 44 | void slowlogPushEntryIfNeeded(robj **argv, int argc, long long duration); 45 | 46 | /* Exported commands */ 47 | void slowlogCommand(redisClient *c); 48 | -------------------------------------------------------------------------------- /src/fmacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _REDIS_FMACRO_H 31 | #define _REDIS_FMACRO_H 32 | 33 | #define _BSD_SOURCE 34 | 35 | #if defined(__linux__) 36 | #define _GNU_SOURCE 37 | #define _DEFAULT_SOURCE 38 | #endif 39 | 40 | #if defined(_AIX) 41 | #define _ALL_SOURCE 42 | #endif 43 | 44 | #if defined(__linux__) || defined(__OpenBSD__) 45 | #define _XOPEN_SOURCE 700 46 | /* 47 | * On NetBSD, _XOPEN_SOURCE undefines _NETBSD_SOURCE and 48 | * thus hides inet_aton etc. 49 | */ 50 | #elif !defined(__NetBSD__) 51 | #define _XOPEN_SOURCE 52 | #endif 53 | 54 | #if defined(__sun) 55 | #define _POSIX_C_SOURCE 199506L 56 | #endif 57 | 58 | #define _LARGEFILE_SOURCE 59 | #define _FILE_OFFSET_BITS 64 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /tests/cluster/tests/06-slave-stop-cond.tcl: -------------------------------------------------------------------------------- 1 | # Slave stop condition test 2 | # Check that if there is a disconnection time limit, the slave will not try 3 | # to failover its master. 4 | 5 | source "../tests/includes/init-tests.tcl" 6 | 7 | # Create a cluster with 5 master and 5 slaves. 8 | test "Create a 5 nodes cluster" { 9 | create_cluster 5 5 10 | } 11 | 12 | test "Cluster is up" { 13 | assert_cluster_state ok 14 | } 15 | 16 | test "The first master has actually one slave" { 17 | assert {[llength [lindex [R 0 role] 2]] == 1} 18 | } 19 | 20 | test {Slaves of #0 is instance #5 as expected} { 21 | set port0 [get_instance_attrib redis 0 port] 22 | assert {[lindex [R 5 role] 2] == $port0} 23 | } 24 | 25 | test "Instance #5 synced with the master" { 26 | wait_for_condition 1000 50 { 27 | [RI 5 master_link_status] eq {up} 28 | } else { 29 | fail "Instance #5 master link status is not up" 30 | } 31 | } 32 | 33 | test "Lower the slave validity factor of #5 to the value of 2" { 34 | assert {[R 5 config set cluster-slave-validity-factor 2] eq {OK}} 35 | } 36 | 37 | test "Break master-slave link and prevent further reconnections" { 38 | # Stop the slave with a multi/exec transaction so that the master will 39 | # be killed as soon as it can accept writes again. 40 | R 5 multi 41 | R 5 client kill 127.0.0.1:$port0 42 | # here we should sleep 6 or more seconds (node_timeout * slave_validity) 43 | # but the actual validity time is actually incremented by the 44 | # repl-ping-slave-period value which is 10 seconds by default. So we 45 | # need to wait more than 16 seconds. 46 | R 5 debug sleep 20 47 | R 5 deferred 1 48 | R 5 exec 49 | 50 | # Prevent the master from accepting new slaves. 51 | # Use a large pause value since we'll kill it anyway. 52 | R 0 CLIENT PAUSE 60000 53 | 54 | # Wait for the slave to return available again 55 | R 5 deferred 0 56 | assert {[R 5 read] eq {OK OK}} 57 | 58 | # Kill the master so that a reconnection will not be possible. 59 | kill_instance redis 0 60 | } 61 | 62 | test "Slave #5 is reachable and alive" { 63 | assert {[R 5 ping] eq {PONG}} 64 | } 65 | 66 | test "Slave #5 should not be able to failover" { 67 | after 10000 68 | assert {[RI 5 role] eq {slave}} 69 | } 70 | 71 | test "Cluster should be down" { 72 | assert_cluster_state fail 73 | } 74 | -------------------------------------------------------------------------------- /tests/cluster/tests/08-update-msg.tcl: -------------------------------------------------------------------------------- 1 | # Test UPDATE messages sent by other nodes when the currently authorirative 2 | # master is unavaialble. The test is performed in the following steps: 3 | # 4 | # 1) Master goes down. 5 | # 2) Slave failover and becomes new master. 6 | # 3) New master is partitoned away. 7 | # 4) Old master returns. 8 | # 5) At this point we expect the old master to turn into a slave ASAP because 9 | # of the UPDATE messages it will receive from the other nodes when its 10 | # configuration will be found to be outdated. 11 | 12 | source "../tests/includes/init-tests.tcl" 13 | 14 | test "Create a 5 nodes cluster" { 15 | create_cluster 5 5 16 | } 17 | 18 | test "Cluster is up" { 19 | assert_cluster_state ok 20 | } 21 | 22 | test "Cluster is writable" { 23 | cluster_write_test 0 24 | } 25 | 26 | test "Instance #5 is a slave" { 27 | assert {[RI 5 role] eq {slave}} 28 | } 29 | 30 | test "Instance #5 synced with the master" { 31 | wait_for_condition 1000 50 { 32 | [RI 5 master_link_status] eq {up} 33 | } else { 34 | fail "Instance #5 master link status is not up" 35 | } 36 | } 37 | 38 | set current_epoch [CI 1 cluster_current_epoch] 39 | 40 | test "Killing one master node" { 41 | kill_instance redis 0 42 | } 43 | 44 | test "Wait for failover" { 45 | wait_for_condition 1000 50 { 46 | [CI 1 cluster_current_epoch] > $current_epoch 47 | } else { 48 | fail "No failover detected" 49 | } 50 | } 51 | 52 | test "Cluster should eventually be up again" { 53 | assert_cluster_state ok 54 | } 55 | 56 | test "Cluster is writable" { 57 | cluster_write_test 1 58 | } 59 | 60 | test "Instance #5 is now a master" { 61 | assert {[RI 5 role] eq {master}} 62 | } 63 | 64 | test "Killing the new master #5" { 65 | kill_instance redis 5 66 | } 67 | 68 | test "Cluster should be down now" { 69 | assert_cluster_state fail 70 | } 71 | 72 | test "Restarting the old master node" { 73 | restart_instance redis 0 74 | } 75 | 76 | test "Instance #0 gets converted into a slave" { 77 | wait_for_condition 1000 50 { 78 | [RI 0 role] eq {slave} 79 | } else { 80 | fail "Old master was not converted into slave" 81 | } 82 | } 83 | 84 | test "Restarting the new master node" { 85 | restart_instance redis 5 86 | } 87 | 88 | test "Cluster is up again" { 89 | assert_cluster_state ok 90 | } 91 | -------------------------------------------------------------------------------- /src/redisassert.h: -------------------------------------------------------------------------------- 1 | /* redisassert.h -- Drop in replacemnet assert.h that prints the stack trace 2 | * in the Redis logs. 3 | * 4 | * This file should be included instead of "assert.h" inside libraries used by 5 | * Redis that are using assertions, so instead of Redis disappearing with 6 | * SIGABORT, we get the details and stack trace inside the log file. 7 | * 8 | * ---------------------------------------------------------------------------- 9 | * 10 | * Copyright (c) 2006-2012, Salvatore Sanfilippo 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * * Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * * Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * * Neither the name of Redis nor the names of its contributors may be used 22 | * to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #ifndef __REDIS_ASSERT_H__ 39 | #define __REDIS_ASSERT_H__ 40 | 41 | #include /* for _exit() */ 42 | 43 | #define assert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1))) 44 | 45 | void _redisAssert(char *estr, char *file, int line); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /utils/lru/test-lru.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'redis' 3 | 4 | r = Redis.new 5 | r.config("SET","maxmemory","2000000") 6 | r.config("SET","maxmemory-policy","allkeys-lru") 7 | r.config("SET","maxmemory-samples",5) 8 | r.config("RESETSTAT") 9 | r.flushall 10 | 11 | puts < 13 | 14 | 34 |
 35 | EOF
 36 | 
 37 | # Fill
 38 | oldsize = r.dbsize
 39 | id = 0
 40 | while true
 41 |     id += 1
 42 |     r.set(id,"foo")
 43 |     newsize = r.dbsize
 44 |     break if newsize == oldsize
 45 |     oldsize = newsize
 46 | end
 47 | 
 48 | inserted = r.dbsize
 49 | first_set_max_id = id
 50 | puts "#{r.dbsize} keys inserted"
 51 | 
 52 | # Access keys sequentially
 53 | 
 54 | puts "Access keys sequentially"
 55 | (1..first_set_max_id).each{|id|
 56 |     r.get(id)
 57 | #    sleep 0.001
 58 | }
 59 | 
 60 | # Insert more 50% keys. We expect that the new keys
 61 | half = inserted/2
 62 | puts "Insert enough keys to evict half the keys we inserted"
 63 | add = 0
 64 | while true
 65 |     add += 1
 66 |     id += 1
 67 |     r.set(id,"foo")
 68 |     break if r.info['evicted_keys'].to_i >= half
 69 | end
 70 | 
 71 | puts "#{add} additional keys added."
 72 | puts "#{r.dbsize} keys in DB"
 73 | 
 74 | # Check if evicted keys respect LRU
 75 | # We consider errors from 1 to N progressively more serious as they violate
 76 | # more the access pattern.
 77 | 
 78 | errors = 0
 79 | e = 1
 80 | edecr = 1.0/(first_set_max_id/2)
 81 | (1..(first_set_max_id/2)).each{|id|
 82 |     e -= edecr if e > 0
 83 |     e = 0 if e < 0
 84 |     if r.exists(id)
 85 |         errors += e
 86 |     end
 87 | }
 88 | 
 89 | puts "#{errors} errors!"
 90 | puts "
" 91 | 92 | # Generate the graphical representation 93 | (1..id).each{|id| 94 | # Mark first set and added items in a different way. 95 | c = "box" 96 | if id <= first_set_max_id 97 | c << " old" 98 | else 99 | c << " new" 100 | end 101 | 102 | # Add class if exists 103 | c << " ex" if r.exists(id) 104 | puts "
" 105 | } 106 | 107 | # Close HTML page 108 | 109 | puts < 111 | 112 | EOF 113 | -------------------------------------------------------------------------------- /deps/linenoise/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "linenoise.h" 5 | 6 | 7 | void completion(const char *buf, linenoiseCompletions *lc) { 8 | if (buf[0] == 'h') { 9 | linenoiseAddCompletion(lc,"hello"); 10 | linenoiseAddCompletion(lc,"hello there"); 11 | } 12 | } 13 | 14 | int main(int argc, char **argv) { 15 | char *line; 16 | char *prgname = argv[0]; 17 | 18 | /* Parse options, with --multiline we enable multi line editing. */ 19 | while(argc > 1) { 20 | argc--; 21 | argv++; 22 | if (!strcmp(*argv,"--multiline")) { 23 | linenoiseSetMultiLine(1); 24 | printf("Multi-line mode enabled.\n"); 25 | } else if (!strcmp(*argv,"--keycodes")) { 26 | linenoisePrintKeyCodes(); 27 | exit(0); 28 | } else { 29 | fprintf(stderr, "Usage: %s [--multiline] [--keycodes]\n", prgname); 30 | exit(1); 31 | } 32 | } 33 | 34 | /* Set the completion callback. This will be called every time the 35 | * user uses the key. */ 36 | linenoiseSetCompletionCallback(completion); 37 | 38 | /* Load history from file. The history file is just a plain text file 39 | * where entries are separated by newlines. */ 40 | linenoiseHistoryLoad("history.txt"); /* Load the history at startup */ 41 | 42 | /* Now this is the main loop of the typical linenoise-based application. 43 | * The call to linenoise() will block as long as the user types something 44 | * and presses enter. 45 | * 46 | * The typed string is returned as a malloc() allocated string by 47 | * linenoise, so the user needs to free() it. */ 48 | while((line = linenoise("hello> ")) != NULL) { 49 | /* Do something with the string. */ 50 | if (line[0] != '\0' && line[0] != '/') { 51 | printf("echo: '%s'\n", line); 52 | linenoiseHistoryAdd(line); /* Add to the history. */ 53 | linenoiseHistorySave("history.txt"); /* Save the history on disk. */ 54 | } else if (!strncmp(line,"/historylen",11)) { 55 | /* The "/historylen" command will change the history len. */ 56 | int len = atoi(line+11); 57 | linenoiseHistorySetMaxLen(len); 58 | } else if (line[0] == '/') { 59 | printf("Unreconized command: %s\n", line); 60 | } 61 | free(line); 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/intset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Pieter Noordhuis 3 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef __INTSET_H 32 | #define __INTSET_H 33 | #include 34 | 35 | typedef struct intset { 36 | uint32_t encoding; 37 | uint32_t length; 38 | int8_t contents[]; 39 | } intset; 40 | 41 | intset *intsetNew(void); 42 | intset *intsetAdd(intset *is, int64_t value, uint8_t *success); 43 | intset *intsetRemove(intset *is, int64_t value, int *success); 44 | uint8_t intsetFind(intset *is, int64_t value); 45 | int64_t intsetRandom(intset *is); 46 | int intsetRandomMembers(intset *is, int64_t* value, int count); 47 | uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value); 48 | uint32_t intsetLen(intset *is); 49 | size_t intsetBlobLen(intset *is); 50 | 51 | #endif // __INTSET_H 52 | -------------------------------------------------------------------------------- /deps/lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /deps/lua/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/qr.h: -------------------------------------------------------------------------------- 1 | /* Ring definitions. */ 2 | #define qr(a_type) \ 3 | struct { \ 4 | a_type *qre_next; \ 5 | a_type *qre_prev; \ 6 | } 7 | 8 | /* Ring functions. */ 9 | #define qr_new(a_qr, a_field) do { \ 10 | (a_qr)->a_field.qre_next = (a_qr); \ 11 | (a_qr)->a_field.qre_prev = (a_qr); \ 12 | } while (0) 13 | 14 | #define qr_next(a_qr, a_field) ((a_qr)->a_field.qre_next) 15 | 16 | #define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev) 17 | 18 | #define qr_before_insert(a_qrelm, a_qr, a_field) do { \ 19 | (a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \ 20 | (a_qr)->a_field.qre_next = (a_qrelm); \ 21 | (a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \ 22 | (a_qrelm)->a_field.qre_prev = (a_qr); \ 23 | } while (0) 24 | 25 | #define qr_after_insert(a_qrelm, a_qr, a_field) \ 26 | do \ 27 | { \ 28 | (a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \ 29 | (a_qr)->a_field.qre_prev = (a_qrelm); \ 30 | (a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \ 31 | (a_qrelm)->a_field.qre_next = (a_qr); \ 32 | } while (0) 33 | 34 | #define qr_meld(a_qr_a, a_qr_b, a_field) do { \ 35 | void *t; \ 36 | (a_qr_a)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \ 37 | (a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_a); \ 38 | t = (a_qr_a)->a_field.qre_prev; \ 39 | (a_qr_a)->a_field.qre_prev = (a_qr_b)->a_field.qre_prev; \ 40 | (a_qr_b)->a_field.qre_prev = t; \ 41 | } while (0) 42 | 43 | /* qr_meld() and qr_split() are functionally equivalent, so there's no need to 44 | * have two copies of the code. */ 45 | #define qr_split(a_qr_a, a_qr_b, a_field) \ 46 | qr_meld((a_qr_a), (a_qr_b), a_field) 47 | 48 | #define qr_remove(a_qr, a_field) do { \ 49 | (a_qr)->a_field.qre_prev->a_field.qre_next \ 50 | = (a_qr)->a_field.qre_next; \ 51 | (a_qr)->a_field.qre_next->a_field.qre_prev \ 52 | = (a_qr)->a_field.qre_prev; \ 53 | (a_qr)->a_field.qre_next = (a_qr); \ 54 | (a_qr)->a_field.qre_prev = (a_qr); \ 55 | } while (0) 56 | 57 | #define qr_foreach(var, a_qr, a_field) \ 58 | for ((var) = (a_qr); \ 59 | (var) != NULL; \ 60 | (var) = (((var)->a_field.qre_next != (a_qr)) \ 61 | ? (var)->a_field.qre_next : NULL)) 62 | 63 | #define qr_reverse_foreach(var, a_qr, a_field) \ 64 | for ((var) = ((a_qr) != NULL) ? qr_prev(a_qr, a_field) : NULL; \ 65 | (var) != NULL; \ 66 | (var) = (((var) != (a_qr)) \ 67 | ? (var)->a_field.qre_prev : NULL)) 68 | -------------------------------------------------------------------------------- /src/sparkline.h: -------------------------------------------------------------------------------- 1 | /* sparkline.h -- ASCII Sparklines header file 2 | * 3 | * --------------------------------------------------------------------------- 4 | * 5 | * Copyright(C) 2011-2014 Salvatore Sanfilippo 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef __SPARKLINE_H 31 | #define __SPARKLINE_H 32 | 33 | /* A sequence is represented of many "samples" */ 34 | struct sample { 35 | double value; 36 | char *label; 37 | }; 38 | 39 | struct sequence { 40 | int length; 41 | int labels; 42 | struct sample *samples; 43 | double min, max; 44 | }; 45 | 46 | #define SPARKLINE_NO_FLAGS 0 47 | #define SPARKLINE_FILL 1 /* Fill the area under the curve. */ 48 | #define SPARKLINE_LOG_SCALE 2 /* Use logarithmic scale. */ 49 | 50 | struct sequence *createSparklineSequence(void); 51 | void sparklineSequenceAddSample(struct sequence *seq, double value, char *label); 52 | void freeSparklineSequence(struct sequence *seq); 53 | sds sparklineRenderRange(sds output, struct sequence *seq, int rows, int offset, int len, int flags); 54 | sds sparklineRender(sds output, struct sequence *seq, int columns, int rows, int flags); 55 | 56 | #endif /* __SPARKLINE_H */ 57 | --------------------------------------------------------------------------------