Check key expiration before deleting

Deleting an expired key should return 0, not success.

Fixes #1648
Add test for deleting an expired key

Verify proper expire-before-delete behavior.

This test passes with the expire-before-delete commit and fails
without it.
fix cluster node description showing wrong slot allocation
Missing return REDIS_ERR added to processMultibulkBuffer().

When we set a protocol error we should return with REDIS_ERR to let the
caller know it should stop processing the client.

Bug found in a code auditing related to issue #1699.
Merge pull request #1701 from kingsumos/node_description

fix cluster node description showing wrong slot allocation
fix null pointer access with no file pointer

I happen to be working on a system that lacks urandom. While the code does try
to handle this case and artificially create some bytes if the file pointer is
empty, it does try to close it unconditionally, leading to a segfault.
Fixed typos.
Merge pull request #1677 from mattsta/expire-before-delete

Check key expiration before deleting
Test: spawn_instance now supports additional config.
Sentinel test files / directories layout improved.

The test now runs in a self-contained directory.
The general abstractions to run the tests in an environment where
mutliple instances are executed at the same time was extrapolated into
instances.tcl, that will be reused to test Redis Cluster.
Lock nodes.conf to avoid multiple processes using the same file.

This was a common source of problems among users.
The solution adopted is not bullet-proof as if the user deletes the
nodes.conf file manually, and starts a new instance with the same
nodes.conf file path, two instances will use the same file. However
following this reasoning the user may drop a nuclear bomb into the
datacenter as well.
clusterLoadConfig() REDIS_ERR retval semantics refined.

We should return REDIS_ERR to signal we can't read the configuration
because there is no config file only after checking errno, othewise
we risk to rewrite an existing file that was not accessible for some
other reason.
While ANET_ERR is -1, check syscall retval for -1 itself.
Redis Cluster test framework skeleton.
Remove unused global variable commandTable
Add dynamic command loading

We can now add custom commands to Redis without recompiling.

Add commands by creating a shared library containing:
    - a table exporting your command definitions
      - (exactly the same as redisCommandTable has always been)
    - a string defining the name of your module

You can add modules in redis.conf with
    "module-add [module.so]"
or on the command line with
    redis-server --module-add module.so
or at runtime with
    "CONFIG SET MODULE-ADD [module.so]"

If you add a module twice, the second time will:
  - load the new module
  - unload the previous module
  - overwrite commands from the old module with
    commands in the new module
  - reset per-command stats/counters for each of
    the newly re-added commands

(Note: Any commands in the old module but not
in the new module will stick around.  To remove a command you
should keep it in your module and just give it a
noop definition or alias it to something simple like the
ping command.)

(Note: There is no way to remove or unload
a module.  You can only add modules and reload existing
modules by re-adding them.  To remove a module, restart
Redis.)

(Note: Running a master-replica or cluster setup with Redis
instances not containing the same set of modules will break
horribly.  Either fully distribute your modules or don't
use modules with replicated Redis.)

This commit contains these changes:
    - Make sure the Redis command table ends with a NULL entry
    - Rename populateCommandTable() to populateCommand(), and
      make it only process one command per invocation.
    - Replace all numcommands calculations with redisCommands.length.
    - Replace usage of redisCommandTable with redisCommands.table.
    - Replace the server startup call to populateCommandTable()
      with a call to loadDynamicCommands(NULL).  When given NULL,
      loadDynamicCommands reads the command table from the
      redis-server executable instead of an externally loaded module.
      Yes, that means the same mechanism used to import new commands
      from external modules bootstraps built-in commands too.
    - Add new INFO MODULES section to output all loaded
      modules, with their names, library filenames, original
      load timestamp, most recent load timestamp (for when
      modules are reloaded with CONFIG SET), and the list of
      commands the module provides.  Note: The redis-server itself
      is processed as a module, so it shows up as module <builtin>.
    - Add new configuration option 'module-add'.
    - Add new CONFIG SET option 'module-add'.

Example output of INFO MODULES:
    127.0.0.1:6379> info modules
    # Modules
    module_demo_ping:filename=ping.so,first_loaded=0,last_loaded=1395789529,commands=poong,pooooong,pooong
    module_<builtin>:filename=<builtin>,first_loaded=0,last_loaded=0,commands=get,set,setnx,setex,psetex,append,strlen,del,exists,setbit,getbit,setrange,getrange,substr,incr,decr,mget,rpush,lpush,rpushx,lpushx,linsert,rpop,lpop,brpop,brpoplpush,blpop,llen,lindex,lset,lrange,ltrim,lrem,rpoplpush,sadd,srem,smove,sismember,scard,spop,srandmember,sinter,sinterstore,sunion,sunionstore,sdiff,sdiffstore,smembers,sscan,zadd,zincrby,zrem,zremrangebyscore,zremrangebyrank,zunionstore,zinterstore,zrange,zrangebyscore,zrevrangebyscore,zcount,zrevrange,zcard,zscore,zrank,zrevrank,zscan,hset,hsetnx,hget,hmset,hmget,hincrby,hincrbyfloat,hdel,hlen,hkeys,hvals,hgetall,hexists,hscan,incrby,decrby,incrbyfloat,getset,mset,msetnx,randomkey,select,move,rename,renamenx,expire,expireat,pexpire,pexpireat,keys,scan,dbsize,auth,ping,echo,save,bgsave,bgrewriteaof,shutdown,lastsave,type,multi,exec,discard,sync,psync,replconf,flushdb,flushall,sort,info,monitor,ttl,pttl,persist,slaveof,debug,config,subscribe,unsubscribe,psubscribe,punsubscribe,publish,pubsub,watch,unwatch,cluster,restore,restore-asking,migrate,asking,readonly,readwrite,dump,object,client,eval,evalsha,slowlog,script,time,bitop,bitcount,bitpos,wait

(Note: {first,last}_loaded of 0 means it was loaded at startup from a configuration
directive or command line argument.  If loaded != 0, then the module
was evaluated after the server started using CONFIG SET MODULE-ADD [module.so])
Fix module reloading

Allow modules to be reloaded with the same filename.  Previously,
due to dlopen refcounting, loading the same module twice, even
if updated, wouldn't actually reload any module contents.

Now modules are loaded, checked for name, checked for existing
module, if existing module found, old module is unloaded, current
module is unloaded (at this point, refcount = 0), then the process
is re-started to load the module again, this time so it gets reloaded
because the prior refcount is now zero.

Got it?

Also fix a Linux compatability issue by removing RTLD_FIRST.
Remove unnecessary malloc

Hey, look, we're using c99 and can do things like this now.
Add redisModule struct with associated operations

Now we store incoming module definitions in a struct, giving
us room to collect all our details (except the command table)
in one place.

Of note, now modules can define initilization functions
and cleanup functions for load/unload symmetry.

Also, there's a version field to detect when you're running a module
built against a different version of Redis than you are currently
running.  The module will still load, but you'll get a warning
about the mismatched versions.

Also, added proper cleanup and closing/unloading of all modules
on shutdown.
Add number of loaded modules to INFO SERVER

Provide a quick entry point to look for debugging information. If
loaded_modules > 0, then any breakage is potentially the fault of
externally loaded modules.

Note: we are reporting on externally loaded modules.  The <builtin>
module isn't reported in the size.  loaded_modules gets incremented
for each module name loaded by configuration parameter 'module-add'
or by runtime 'CONFIG SET MODULE-ADD'.

When loaded_modules:0, INFO MODULES will still have output.  The
output will be the <builtin> module with all default Redis commands.