Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding redis example config and init files

  • Loading branch information...
commit 597c515a3e0f1d332fe2209505cde5479f57e8ef 1 parent 5478cd2
Russell Branca authored May 26, 2011
48  doc/redis-server
... ...
@@ -0,0 +1,48 @@
  1
+#!/bin/sh
  2
+
  3
+# Init script borrowed from base redis example
  4
+# 
  5
+# Copyright (c) 2006-2009, Salvatore Sanfilippo
  6
+# All rights reserved.
  7
+# 
  8
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  9
+# 
  10
+#     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  11
+#     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  12
+#     * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  13
+# 
  14
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15
+
  16
+REDISPORT=6379
  17
+EXEC=/usr/local/bin/redis-server
  18
+
  19
+PIDFILE=/var/run/redis.pid
  20
+CONF="/etc/redis.conf"
  21
+
  22
+case "$1" in
  23
+    start)
  24
+        if [ -f $PIDFILE ]
  25
+        then
  26
+                echo -n "$PIDFILE exists, process is already running or crashed\n"
  27
+        else
  28
+                echo -n "Starting Redis server...\n"
  29
+                $EXEC $CONF
  30
+        fi
  31
+        ;;
  32
+    stop)
  33
+        if [ ! -f $PIDFILE ]
  34
+        then
  35
+                echo -n "$PIDFILE does not exist, process is not running\n"
  36
+        else
  37
+		PID=$(cat $PIDFILE)
  38
+                echo -n "Stopping ...\n"
  39
+                echo -n "SHUTDOWN\r\n" | nc localhost $REDISPORT &
  40
+                while [ -x /proc/${PIDFILE} ]
  41
+                do
  42
+                    echo "Waiting for Redis to shutdown ..."
  43
+                    sleep 1
  44
+                done
  45
+                echo "Redis stopped"
  46
+        fi
  47
+        ;;
  48
+esac
430  doc/redis.conf
... ...
@@ -0,0 +1,430 @@
  1
+# Config file borrowed from base redis example
  2
+# 
  3
+# Copyright (c) 2006-2009, Salvatore Sanfilippo
  4
+# All rights reserved.
  5
+# 
  6
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  7
+# 
  8
+#     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  9
+#     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  10
+#     * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  11
+# 
  12
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13
+
  14
+# Redis configuration file example
  15
+
  16
+# Note on units: when memory size is needed, it is possible to specifiy
  17
+# it in the usual form of 1k 5GB 4M and so forth:
  18
+#
  19
+# 1k => 1000 bytes
  20
+# 1kb => 1024 bytes
  21
+# 1m => 1000000 bytes
  22
+# 1mb => 1024*1024 bytes
  23
+# 1g => 1000000000 bytes
  24
+# 1gb => 1024*1024*1024 bytes
  25
+#
  26
+# units are case insensitive so 1GB 1Gb 1gB are all the same.
  27
+
  28
+# By default Redis does not run as a daemon. Use 'yes' if you need it.
  29
+# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  30
+daemonize yes
  31
+
  32
+# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
  33
+# default. You can specify a custom pid file location here.
  34
+pidfile /var/run/redis.pid
  35
+
  36
+# Accept connections on the specified port, default is 6379.
  37
+# If port 0 is specified Redis will not listen on a TCP socket.
  38
+port 6379
  39
+
  40
+# If you want you can bind a single interface, if the bind option is not
  41
+# specified all the interfaces will listen for incoming connections.
  42
+#
  43
+bind 127.0.0.1
  44
+
  45
+# Specify the path for the unix socket that will be used to listen for
  46
+# incoming connections. There is no default, so Redis will not listen
  47
+# on a unix socket when not specified.
  48
+#
  49
+# unixsocket /tmp/redis.sock
  50
+
  51
+# Close the connection after a client is idle for N seconds (0 to disable)
  52
+timeout 300
  53
+
  54
+# Set server verbosity to 'debug'
  55
+# it can be one of:
  56
+# debug (a lot of information, useful for development/testing)
  57
+# verbose (many rarely useful info, but not a mess like the debug level)
  58
+# notice (moderately verbose, what you want in production probably)
  59
+# warning (only very important / critical messages are logged)
  60
+loglevel notice
  61
+
  62
+# Specify the log file name. Also 'stdout' can be used to force
  63
+# Redis to log on the standard output. Note that if you use standard
  64
+# output for logging but daemonize, logs will be sent to /dev/null
  65
+logfile /var/log/redis/redis.log
  66
+
  67
+# To enable logging to the system logger, just set 'syslog-enabled' to yes,
  68
+# and optionally update the other syslog parameters to suit your needs.
  69
+# syslog-enabled no
  70
+
  71
+# Specify the syslog identity.
  72
+# syslog-ident redis
  73
+
  74
+# Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.
  75
+# syslog-facility local0
  76
+
  77
+# Set the number of databases. The default database is DB 0, you can select
  78
+# a different one on a per-connection basis using SELECT <dbid> where
  79
+# dbid is a number between 0 and 'databases'-1
  80
+databases 16
  81
+
  82
+################################ SNAPSHOTTING  #################################
  83
+#
  84
+# Save the DB on disk:
  85
+#
  86
+#   save <seconds> <changes>
  87
+#
  88
+#   Will save the DB if both the given number of seconds and the given
  89
+#   number of write operations against the DB occurred.
  90
+#
  91
+#   In the example below the behaviour will be to save:
  92
+#   after 900 sec (15 min) if at least 1 key changed
  93
+#   after 300 sec (5 min) if at least 10 keys changed
  94
+#   after 60 sec if at least 10000 keys changed
  95
+#
  96
+#   Note: you can disable saving at all commenting all the "save" lines.
  97
+
  98
+save 900 1
  99
+save 300 10
  100
+save 60 10000
  101
+
  102
+# Compress string objects using LZF when dump .rdb databases?
  103
+# For default that's set to 'yes' as it's almost always a win.
  104
+# If you want to save some CPU in the saving child set it to 'no' but
  105
+# the dataset will likely be bigger if you have compressible values or keys.
  106
+rdbcompression yes
  107
+
  108
+# The filename where to dump the DB
  109
+dbfilename dump.rdb
  110
+
  111
+# The working directory.
  112
+#
  113
+# The DB will be written inside this directory, with the filename specified
  114
+# above using the 'dbfilename' configuration directive.
  115
+# 
  116
+# Also the Append Only File will be created inside this directory.
  117
+# 
  118
+# Note that you must specify a directory here, not a file name.
  119
+dir /var/lib/redis
  120
+
  121
+################################# REPLICATION #################################
  122
+
  123
+# Master-Slave replication. Use slaveof to make a Redis instance a copy of
  124
+# another Redis server. Note that the configuration is local to the slave
  125
+# so for example it is possible to configure the slave to save the DB with a
  126
+# different interval, or to listen to another port, and so on.
  127
+#
  128
+# slaveof <masterip> <masterport>
  129
+
  130
+# If the master is password protected (using the "requirepass" configuration
  131
+# directive below) it is possible to tell the slave to authenticate before
  132
+# starting the replication synchronization process, otherwise the master will
  133
+# refuse the slave request.
  134
+#
  135
+# masterauth <master-password>
  136
+
  137
+# When a slave lost the connection with the master, or when the replication
  138
+# is still in progress, the slave can act in two different ways:
  139
+#
  140
+# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
  141
+#    still reply to client requests, possibly with out of data data, or the
  142
+#    data set may just be empty if this is the first synchronization.
  143
+#
  144
+# 2) if slave-serve-stale data is set to 'no' the slave will reply with
  145
+#    an error "SYNC with master in progress" to all the kind of commands
  146
+#    but to INFO and SLAVEOF.
  147
+#
  148
+slave-serve-stale-data yes
  149
+
  150
+################################## SECURITY ###################################
  151
+
  152
+# Require clients to issue AUTH <PASSWORD> before processing any other
  153
+# commands.  This might be useful in environments in which you do not trust
  154
+# others with access to the host running redis-server.
  155
+#
  156
+# This should stay commented out for backward compatibility and because most
  157
+# people do not need auth (e.g. they run their own servers).
  158
+# 
  159
+# Warning: since Redis is pretty fast an outside user can try up to
  160
+# 150k passwords per second against a good box. This means that you should
  161
+# use a very strong password otherwise it will be very easy to break.
  162
+#
  163
+# requirepass foobared
  164
+
  165
+# Command renaming.
  166
+#
  167
+# It is possilbe to change the name of dangerous commands in a shared
  168
+# environment. For instance the CONFIG command may be renamed into something
  169
+# of hard to guess so that it will be still available for internal-use
  170
+# tools but not available for general clients.
  171
+#
  172
+# Example:
  173
+#
  174
+# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  175
+#
  176
+# It is also possilbe to completely kill a command renaming it into
  177
+# an empty string:
  178
+#
  179
+# rename-command CONFIG ""
  180
+
  181
+################################### LIMITS ####################################
  182
+
  183
+# Set the max number of connected clients at the same time. By default there
  184
+# is no limit, and it's up to the number of file descriptors the Redis process
  185
+# is able to open. The special value '0' means no limits.
  186
+# Once the limit is reached Redis will close all the new connections sending
  187
+# an error 'max number of clients reached'.
  188
+#
  189
+# maxclients 128
  190
+
  191
+# Don't use more memory than the specified amount of bytes.
  192
+# When the memory limit is reached Redis will try to remove keys with an
  193
+# EXPIRE set. It will try to start freeing keys that are going to expire
  194
+# in little time and preserve keys with a longer time to live.
  195
+# Redis will also try to remove objects from free lists if possible.
  196
+#
  197
+# If all this fails, Redis will start to reply with errors to commands
  198
+# that will use more memory, like SET, LPUSH, and so on, and will continue
  199
+# to reply to most read-only commands like GET.
  200
+#
  201
+# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
  202
+# 'state' server or cache, not as a real DB. When Redis is used as a real
  203
+# database the memory usage will grow over the weeks, it will be obvious if
  204
+# it is going to use too much memory in the long run, and you'll have the time
  205
+# to upgrade. With maxmemory after the limit is reached you'll start to get
  206
+# errors for write operations, and this may even lead to DB inconsistency.
  207
+#
  208
+# maxmemory <bytes>
  209
+
  210
+# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  211
+# is reached? You can select among five behavior:
  212
+# 
  213
+# volatile-lru -> remove the key with an expire set using an LRU algorithm
  214
+# allkeys-lru -> remove any key accordingly to the LRU algorithm
  215
+# volatile-random -> remove a random key with an expire set
  216
+# allkeys->random -> remove a random key, any key
  217
+# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  218
+# noeviction -> don't expire at all, just return an error on write operations
  219
+# 
  220
+# Note: with all the kind of policies, Redis will return an error on write
  221
+#       operations, when there are not suitable keys for eviction.
  222
+#
  223
+#       At the date of writing this commands are: set setnx setex append
  224
+#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
  225
+#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
  226
+#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
  227
+#       getset mset msetnx exec sort
  228
+#
  229
+# The default is:
  230
+#
  231
+# maxmemory-policy volatile-lru
  232
+
  233
+# LRU and minimal TTL algorithms are not precise algorithms but approximated
  234
+# algorithms (in order to save memory), so you can select as well the sample
  235
+# size to check. For instance for default Redis will check three keys and
  236
+# pick the one that was used less recently, you can change the sample size
  237
+# using the following configuration directive.
  238
+#
  239
+# maxmemory-samples 3
  240
+
  241
+############################## APPEND ONLY MODE ###############################
  242
+
  243
+# By default Redis asynchronously dumps the dataset on disk. If you can live
  244
+# with the idea that the latest records will be lost if something like a crash
  245
+# happens this is the preferred way to run Redis. If instead you care a lot
  246
+# about your data and don't want to that a single record can get lost you should
  247
+# enable the append only mode: when this mode is enabled Redis will append
  248
+# every write operation received in the file appendonly.aof. This file will
  249
+# be read on startup in order to rebuild the full dataset in memory.
  250
+#
  251
+# Note that you can have both the async dumps and the append only file if you
  252
+# like (you have to comment the "save" statements above to disable the dumps).
  253
+# Still if append only mode is enabled Redis will load the data from the
  254
+# log file at startup ignoring the dump.rdb file.
  255
+#
  256
+# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
  257
+# log file in background when it gets too big.
  258
+
  259
+appendonly no
  260
+
  261
+# The name of the append only file (default: "appendonly.aof")
  262
+# appendfilename appendonly.aof
  263
+
  264
+# The fsync() call tells the Operating System to actually write data on disk
  265
+# instead to wait for more data in the output buffer. Some OS will really flush 
  266
+# data on disk, some other OS will just try to do it ASAP.
  267
+#
  268
+# Redis supports three different modes:
  269
+#
  270
+# no: don't fsync, just let the OS flush the data when it wants. Faster.
  271
+# always: fsync after every write to the append only log . Slow, Safest.
  272
+# everysec: fsync only if one second passed since the last fsync. Compromise.
  273
+#
  274
+# The default is "everysec" that's usually the right compromise between
  275
+# speed and data safety. It's up to you to understand if you can relax this to
  276
+# "no" that will will let the operating system flush the output buffer when
  277
+# it wants, for better performances (but if you can live with the idea of
  278
+# some data loss consider the default persistence mode that's snapshotting),
  279
+# or on the contrary, use "always" that's very slow but a bit safer than
  280
+# everysec.
  281
+#
  282
+# If unsure, use "everysec".
  283
+
  284
+# appendfsync always
  285
+appendfsync everysec
  286
+# appendfsync no
  287
+
  288
+# When the AOF fsync policy is set to always or everysec, and a background
  289
+# saving process (a background save or AOF log background rewriting) is
  290
+# performing a lot of I/O against the disk, in some Linux configurations
  291
+# Redis may block too long on the fsync() call. Note that there is no fix for
  292
+# this currently, as even performing fsync in a different thread will block
  293
+# our synchronous write(2) call.
  294
+#
  295
+# In order to mitigate this problem it's possible to use the following option
  296
+# that will prevent fsync() from being called in the main process while a
  297
+# BGSAVE or BGREWRITEAOF is in progress.
  298
+#
  299
+# This means that while another child is saving the durability of Redis is
  300
+# the same as "appendfsync none", that in pratical terms means that it is
  301
+# possible to lost up to 30 seconds of log in the worst scenario (with the
  302
+# default Linux settings).
  303
+# 
  304
+# If you have latency problems turn this to "yes". Otherwise leave it as
  305
+# "no" that is the safest pick from the point of view of durability.
  306
+no-appendfsync-on-rewrite no
  307
+
  308
+################################ VIRTUAL MEMORY ###############################
  309
+
  310
+# Virtual Memory allows Redis to work with datasets bigger than the actual
  311
+# amount of RAM needed to hold the whole dataset in memory.
  312
+# In order to do so very used keys are taken in memory while the other keys
  313
+# are swapped into a swap file, similarly to what operating systems do
  314
+# with memory pages.
  315
+#
  316
+# To enable VM just set 'vm-enabled' to yes, and set the following three
  317
+# VM parameters accordingly to your needs.
  318
+
  319
+vm-enabled no
  320
+# vm-enabled yes
  321
+
  322
+# This is the path of the Redis swap file. As you can guess, swap files
  323
+# can't be shared by different Redis instances, so make sure to use a swap
  324
+# file for every redis process you are running. Redis will complain if the
  325
+# swap file is already in use.
  326
+#
  327
+# The best kind of storage for the Redis swap file (that's accessed at random) 
  328
+# is a Solid State Disk (SSD).
  329
+#
  330
+# *** WARNING *** if you are using a shared hosting the default of putting
  331
+# the swap file under /tmp is not secure. Create a dir with access granted
  332
+# only to Redis user and configure Redis to create the swap file there.
  333
+vm-swap-file /tmp/redis.swap
  334
+
  335
+# vm-max-memory configures the VM to use at max the specified amount of
  336
+# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
  337
+# is, if there is still enough contiguous space in the swap file.
  338
+#
  339
+# With vm-max-memory 0 the system will swap everything it can. Not a good
  340
+# default, just specify the max amount of RAM you can in bytes, but it's
  341
+# better to leave some margin. For instance specify an amount of RAM
  342
+# that's more or less between 60 and 80% of your free RAM.
  343
+vm-max-memory 0
  344
+
  345
+# Redis swap files is split into pages. An object can be saved using multiple
  346
+# contiguous pages, but pages can't be shared between different objects.
  347
+# So if your page is too big, small objects swapped out on disk will waste
  348
+# a lot of space. If you page is too small, there is less space in the swap
  349
+# file (assuming you configured the same number of total swap file pages).
  350
+#
  351
+# If you use a lot of small objects, use a page size of 64 or 32 bytes.
  352
+# If you use a lot of big objects, use a bigger page size.
  353
+# If unsure, use the default :)
  354
+vm-page-size 32
  355
+
  356
+# Number of total memory pages in the swap file.
  357
+# Given that the page table (a bitmap of free/used pages) is taken in memory,
  358
+# every 8 pages on disk will consume 1 byte of RAM.
  359
+#
  360
+# The total swap size is vm-page-size * vm-pages
  361
+#
  362
+# With the default of 32-bytes memory pages and 134217728 pages Redis will
  363
+# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
  364
+#
  365
+# It's better to use the smallest acceptable value for your application,
  366
+# but the default is large in order to work in most conditions.
  367
+vm-pages 134217728
  368
+
  369
+# Max number of VM I/O threads running at the same time.
  370
+# This threads are used to read/write data from/to swap file, since they
  371
+# also encode and decode objects from disk to memory or the reverse, a bigger
  372
+# number of threads can help with big objects even if they can't help with
  373
+# I/O itself as the physical device may not be able to couple with many
  374
+# reads/writes operations at the same time.
  375
+#
  376
+# The special value of 0 turn off threaded I/O and enables the blocking
  377
+# Virtual Memory implementation.
  378
+vm-max-threads 4
  379
+
  380
+############################### ADVANCED CONFIG ###############################
  381
+
  382
+# Hashes are encoded in a special way (much more memory efficient) when they
  383
+# have at max a given numer of elements, and the biggest element does not
  384
+# exceed a given threshold. You can configure this limits with the following
  385
+# configuration directives.
  386
+hash-max-zipmap-entries 512
  387
+hash-max-zipmap-value 64
  388
+
  389
+# Similarly to hashes, small lists are also encoded in a special way in order
  390
+# to save a lot of space. The special representation is only used when
  391
+# you are under the following limits:
  392
+list-max-ziplist-entries 512
  393
+list-max-ziplist-value 64
  394
+
  395
+# Sets have a special encoding in just one case: when a set is composed
  396
+# of just strings that happens to be integers in radix 10 in the range
  397
+# of 64 bit signed integers.
  398
+# The following configuration setting sets the limit in the size of the
  399
+# set in order to use this special memory saving encoding.
  400
+set-max-intset-entries 512
  401
+
  402
+# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  403
+# order to help rehashing the main Redis hash table (the one mapping top-level
  404
+# keys to values). The hash table implementation redis uses (see dict.c)
  405
+# performs a lazy rehashing: the more operation you run into an hash table
  406
+# that is rhashing, the more rehashing "steps" are performed, so if the
  407
+# server is idle the rehashing is never complete and some more memory is used
  408
+# by the hash table.
  409
+# 
  410
+# The default is to use this millisecond 10 times every second in order to
  411
+# active rehashing the main dictionaries, freeing memory when possible.
  412
+#
  413
+# If unsure:
  414
+# use "activerehashing no" if you have hard latency requirements and it is
  415
+# not a good thing in your environment that Redis can reply form time to time
  416
+# to queries with 2 milliseconds delay.
  417
+#
  418
+# use "activerehashing yes" if you don't have such hard requirements but
  419
+# want to free memory asap when possible.
  420
+activerehashing yes
  421
+
  422
+################################## INCLUDES ###################################
  423
+
  424
+# Include one or more other config files here.  This is useful if you
  425
+# have a standard template that goes to all redis server but also need
  426
+# to customize a few per-server settings.  Include files can include
  427
+# other files, so use this wisely.
  428
+#
  429
+# include /path/to/local.conf
  430
+# include /path/to/other.conf

0 notes on commit 597c515

Please sign in to comment.
Something went wrong with that request. Please try again.