Skip to content

Instantly share code, notes, and snippets.

@marinsagovac
Created July 4, 2018 14:12
Show Gist options
  • Save marinsagovac/641bb9ad7074b5a6e5aba58cf7abbe72 to your computer and use it in GitHub Desktop.
Save marinsagovac/641bb9ad7074b5a6e5aba58cf7abbe72 to your computer and use it in GitHub Desktop.
REDIS
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install redis-server
sudo apt-get install php-redis
# Cache
sudo nano /etc/redis/redis.conf
# add
maxmemory 128mb
maxmemory-policy allkeys-lru
# Redis will remove any key according to the LRU algorithm when the max memory of 128mb is reached
# Restart service
sudo systemctl restart redis-server.service
# Enable on boot
sudo systemctl enable redis-server.service
# Monitor
redis-cli monitor
# Purge cache
redis-cli
flushall
exit
# Start server or check server
redis-server
# Ping service
redis-cli ping
PONG
# Set keys
$ redis-cli
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"
# Shutdown redis
redis-cli shutdown
# Run on server, copy redis-server to redis-cli, 6379 is port
sudo mkdir /etc/redis
sudo mkdir /var/redis
sudo cp utils/redis_init_script /etc/init.d/redis_6379
sudo vi /etc/init.d/redis_6379
sudo cp redis.conf /etc/redis/6379.conf
sudo mkdir /var/redis/6379
# Change configurations:
daemonize=yes
pidfile=/var/run/redis_6379.pid
port=6379
loglevel=<change>
logfile=/var/log/redis_6379.log
dir=/var/redis/6379
# Set init runlevel
sudo update-rc.d redis_6379 defaults
# Run instance
sudo /etc/init.d/redis_6379 start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment