redis Installation Guide:
Features: The main feature is the operation is atomic;
use: for use as a queue, for sharing the session, for storing as a chat, a prestored used;
1. Download http://www.redis.cn/documentation.html
2.
mv redis-4.0.11.tar.gz /usr/local/
tar -zxvf redis-4.0.11.tar.gz
cd redis-4.0.11/
make
cd src
make install
After compilation, in the Src directory, there are four executable redis-server, redis-benchmark, redis-cli redis.conf and copy it to a directory.
mkdir -p /usr/local/redis
cp /usr/local/redis-4.0.11/src/redis-server /usr/local/redis
cp /usr/local/redis-4.0.11/src/redis-cli /usr/local/redis
cp /usr/local/redis-4.0.11/redis.conf /usr/local/redis
cd /usr/local/redis
3.
vim redis.conf
before bind 127.0.0.1 add "#" to comment out the
default protection mode, the protected-mode yes instead protected-mode no
default is not daemon mode, the daemonize no change daemonize yes
the pre-requirepass foobared "#" removed, changed the password to the password you want to set (I used to practice, set to 123456)
requirepass 111111
Set boot
vim /etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 80 90
# description: Start and Stop redis
#PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/redis-server
REDIS_CLI=/usr/local/redis/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/redis.conf"
AUTH="111111"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
vim /etc/rc.local
加入service redis start
chmod 755 /etc/init.d/redis
chkconfig --add redis
4. 测试
service redis start
ps -ef|grep redis
ln -s /usr/local/redis/redis-cli /usr/bin/redis
5. Start
/ usr / local / Redis / Server-/usr/local/redis/redis.conf Redis
Redis
General reading method need to add @Cacheable, and delete need to use @CacheEvict, add and modify using @CachePut
@CachePut must have a return value, the return value must be the same type of @Cacheable;
Use:
0. redis increase in the configuration in propertise
1. On the Application
@EnableCaching
2. Create a new class redisConfig
3. 在Service中
@Cacheable(value = Array("getResponseById"), key = "#id") //建立缓存
@CachePut(value = Array("getResponseById"), key = "#map_.get(\"id\").toString()") //更新缓存
@CacheEvict(value = Array("getResponseById"), key = "#id") //清理缓存
redisTemplate.opsForValue().set("1","2")
redisTemplate.opsForValue().get("1").toString