Redis

From GeilThings

Jump to: navigation, search
Redis
General
Version 2.6.11
Stable 2.6.14
Function Database
SQL NoSQL
Port 6379
Files
Config File /etc/redis.conf
Data File /opt/redis/dump.rdb
Log File /var/log/redis.log
Scripts
Version Script /usr/local/bin/redis-cli -v
Start redis-server /etc/redis.conf
Stop redis-cli -a password SHUTDOWN
Cli redis-cli


Contents

General

http://redis.io/documentation

http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.html

http://blog.grayproductions.net/articles/setting_up_the_redis_server

http://simonwillison.net/static/2010/redis-tutorial/

  • Determine Redis Version: /usr/local/bin/redis-cli -v

Installation

# CentOS 5.6
cd /opt
wget http://redis.googlecode.com/files/redis-2.2.11.tar.gz
tar zxvf redis-2.2.11.tar.gz
cd redis-2.2.11
make
make test
# Error:
# /bin/sh: tclsh8.5: command not found
# So, tclsh8.5 seems to be missing; "yum install tcl" gave: "Package tcl-8.4.13-4.el5.x86_64 already installed and latest version".
# tcl 8.4 is there, Redis make test looks for tcl 8.5. I am not going to upgrade tcl to 8.5 for now.
make install
 
# Create softlink to facilitate administration.
cd /opt
ln -s redis-2.2.11 /opt/redis
  • CentOS 6.2
# To run make test.
yum install tcl
 
cd /opt
wget http://redis.googlecode.com/files/redis-2.4.8.tar.gz
tar zxvf redis-2.4.8.tar.gz
cd redis-2.4.8
make
make test
make install
 
# Create softlink to facilitate administration.
cd /opt
ln -s redis-2.4.8 /opt/redis

Configuration

  • Redis in "small memory" mode.
# Where is the redis.conf file?
find / -name redis.conf
## /opt/redis-x.x.x/redis.conf
# Creating default file as /etc/redis.conf
cp /opt/redis-x.x.x/redis.conf /etc/
# Following own needs and advices from http://blog.grayproductions.net/articles/setting_up_the_redis_server
# Edit /etc/redis.conf
## bind 127.0.0.1
## daemonize yes
## loglevel warning
## logfile /var/log/redis.log
## databases 1
## #save 60 10000
## dir /opt/redis/
## requirepass mypassword
## maxclients 25
## maxmemory 50mb
## maxmemory-policy noeviction

Running

# Using Redis-cli
# SAVE and QUIT to save all changes
 
redis-cli
 
auth redispassword
> OK
 
# The authorization works calling redis-cli like:
# redis-cli -a redispassword
 
info
# Lots of interesting infos.
> redis_version:2.2.11, uptime_in_days:0, used_cpu_sys:0.05, used_memory:792256, used_memory_human:773.69K, used_memory_rss:1449984
 
dbsize
> (integer) 0
 
# Using Hashes
# HSET key field value
HSET HelloWorld java "Hello World from Java and Redis"
HSET HelloWorld php "Hello World from PHP and Redis"
HSET HelloWorld perl "Hello World from Perl and Redis"
HSET HelloWorld python "Hello World from Python and Redis"
HSET HelloWorld ruby "Hello World from Ruby and Redis"
HSET HelloWorld clojure "Hello World from Clojure and Redis"
HSET HelloWorld node.js "Hello World from Node.js and Redis"
 
HGET HelloWorld language
> "PHP"
 
# Delete Key.
DEL HelloWorld
 
# Stop server (it quits all clients): 
SHUTDOWN
 
save
 
quit

Backup

# I don't need hot backups.
# Stop.
redis-cli -a password SHUTDOWN
 
APP=redis 
RAWVERSION=`/usr/local/bin/redis-cli -v`
OLDVERSION=${RAWVERSION:10}
cp /opt/redis/dump.rdb /home/backup/redis/redis_${OLDVERSION}_${DATE}/dump.rdb
 
# Start.
redis-server /etc/redis.conf

Upgrade Redis

# Variants of the script worked for 2.2.11 to xxx to 2.4.7 
# 2.4.8 (new installation) to whatever:
 
######### START EDIT #########
 
APPNAME=redis
APPPWD=the_application_password
APPLOG=/var/log/redis.log
# The directory where I want to download the .zip files from the MediaWiki site.
DOWNLOADDIRECTORY=/opt
# If ISBACKUP=TRUE a backup of the database and the configuration files will take place.
# All other values will not trigger a backup.
ISBACKUP=TRUE
# BACKUPROOTDIR is only relevant if ISBACKUP=TRUE
BACKUPROOTDIR=/home/backup
 
######### END EDIT #########
 
DATE=`date +%Y-%m-%d` 
 
# Determine current Redis version.
# As of 2.2.x, 2.4.x, 2.6.x, output will be in the format 
# redis-cli 2.2.13
RAWOLDVERSION=`/usr/local/bin/redis-cli -v`
OLDVERSION=${RAWOLDVERSION:10}
# Check.
echo $OLDVERSION
 
RAWNEWVERSION=`curl -sd "action=ask&query=[[Redis]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
# Get Version as Substring.  
# Using grep to sed to extract STRING between first occurrence of MATCH1 and next occurrence of MATCH2:  
# http://stackoverflow.com/questions/4392106/sed-extract-string-between-first-occurrence-of-match1-and-next-occurrence-of-m  
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
if [[ ${OLDVERSION} != ${NEWVERSION} ]]; then
  echo ${APPNAME}: installed: ${OLDVERSION}, actual: ${NEWVERSION}
  echo "You could update ${APPNAME} to ${NEWVERSION}"
  echo "Would you like to install ${APPNAME} ${NEWVERSION} y/n?"
  read item
  if [[ "$item" == "y" || "$item" == "Y" ]]; then
    echo "Installing ${APPNAME} ${NEWVERSION}. Follow instructions."
  else
    echo "Exit"
  fi
else
  echo "You don't need to update ${APPNAME}; it is uptodate (${NEWVERSION})"
fi
 
# Start Backup.
if [[ ${ISBACKUP} == "TRUE" ]]; then
  # The script breaks if variable names are not enclosed with {}
  BACKUPDIR=${BACKUPROOTDIR}/${APPNAME}/${APPNAME}_${OLDVERSION}_${DATE}
 
  # Create backup directory if it does not exist.
  if [ ! -d "${BACKUPDIR}" ]
  then
    mkdir -m 755 -p ${BACKUPDIR}
  fi
  # Backup configuration and data files.
  # I don't need hot backups.
  # TODO: If the server has been idle for some time, redis-cli is not able to connect to the server???
  # I can only use it after waking up the server through connecting with other applications???
  redis-cli -a $APPPWD SHUTDOWN
  # Check.
  ps aux | grep redis
  cp /opt/redis-${OLDVERSION}/dump.rdb ${BACKUPDIR}/dump.rdb
  cp /etc/redis.conf ${BACKUPDIR}/redis.conf
fi
# End Backup.
 
# Download and install the new version.
cd ${DOWNLOADDIRECTORY}
wget http://redis.googlecode.com/files/redis-${NEWVERSION}.tar.gz
 
tar zxvf redis-${NEWVERSION}.tar.gz
cd redis-${NEWVERSION}
 
# Read Release Notes.
vi 00-RELEASENOTES
:q
 
# Read Readme file.
vi README
:q
 
make
make test
make install
 
# TODO: Inspect Ubuntu, Debian script:
# cd utils
# /install_server
 
# Replace the old redis.conf file with the new one.
# cp is an alias for /bin/cp which always ask if I want to overwrite. To avoid answering yes, use /bin/cp -fr
/bin/cp -fr /opt/redis-${NEWVERSION}/redis.conf /etc/redis.conf
 
# Edit /etc/redis.conf (See section "Configuration") with previously used settings (as in the backup file).
# ...
 
# Copy the database file to the desired location.
cp /opt/redis-${OLDVERSION}/dump.rdb /opt/redis-${NEWVERSION}/dump.rdb
 
# Modify the redis soft link.
rm -f /opt/redis
ln -s /opt/redis-${NEWVERSION} /opt/redis
 
# Start
redis-server /etc/redis.conf
 
# Check that the server is running.
ps aux | grep redis
## ... redis-server /etc/redis.conf
 
# Check version.
/usr/local/bin/redis-cli -v
 
# Check log file.
tail -10 ${APPLOG}
 
# Check that applications work.
# ...
 
# Rename the old version directory and delete it some time later.
mv /opt/redis-${OLDVERSION} /opt/old_redis-${OLDVERSION}

Issues

Redis 2.6.6: make test

  • After make test
    • [err]: Turning off AOF kills the background writing child if any in tests/unit/aofrw.tcl
    • Can't find 'Killing AOF child' into recent logs. Solution: ???

Redis 2.6.10 CentOS 6.3 After CLIENT SETNAME, connection can still be closed

  • After make test:
    •  !!! WARNING The following tests failed:
    • [err]: After CLIENT SETNAME, connection can still be closed in tests/unit/introspection.tcl
    • Solution: ???

Programming Redis


Cloud

Redis hosted on the cloud:

Provider Website Wikipedia
Engine Yard engineyard.com Engine Yard
Redis4You redis4you.com

Versions

Software name Version number Version date
Redis 2.6.5
2.6.6
2.6.7
2.6.8
2.2.13
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.6
2.4.7
2.4.5
2.6.9
2.6.10
2.6.11
22 November 2012
1 December 2012
8 December 2012
12 January 2013
15 October 2011
22 October 2011
28 October 2011
22 November 2011
2 December 2011
23 December 2011
2 February 2012
22 February 2012
12 January 2012
17 January 2013
13 February 2013
13 March 2013

Comments

blog comments powered by Disqus