Skip to content
iman daneshi edited this page Feb 19, 2016 · 5 revisions

"Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker."

We use redis for group bans,global bans,chat stats and ...

Issues

Can't Connect With Redis install/configure it!

You just need to start the redis server

sudo service redis-server start

Backup

1- Save your DB

redis-cli save

2- Backup it

sudo cp /var/lib/redis/dump.rdb /backup/location/you/want/to/save/your/database

For example

sudo cp /var/lib/redis/dump.rdb /home/teleseed

Restore

In case it is not AOF mode. ('no') the process is quite straight forward. First, just stop redis server

/etc/init.d/redis-server stop

Then, remove the current dumb.rdb file

rm -f /var/lib/redis/dump.rdb

And now the snapshot file has gone, therefore we definitely want the backup one back in.

cp /backup/dump.rdb

Remember to set it to be owned by redis user/group

chown redis:redis dump.rdb

Now, just start the Redis server.

/etc/init.d/redis-server start

Done.


In case it is AOF mode. ('yes'),* it involes a bit more process. The first thing to do is the same as previos case, just stop the redis server

/etc/init.d/redis-server stop

Go inside directory where dump.rdb is located

cd /var/lib/redis/

After that, clean dump.rb and appendonly.aof files up

rm -f dump.rdb appendonly.aof

Copy the backup file in the place, along the line, correct its permission.

chown redis:redis /var/lib/redis/dump.rdb```

The important part is to disable AOF by editing /etc/redis/redis.conf file, set appendonly as no

```appendonly no```

Run the following command to create new appendonly.aof file

Next, start the Redis server and issue the BGREWRITEAOF command:

```/etc/init.d/redis-server start
redis-cli BGREWRITEAOF```

Check the progress (0 - done, 1 - not yet)

```redis-cli info | grep aof_rewrite_in_progress```

You should see a new appendonly.aof file. Next, stop the server.

```/etc/init.d/redis-server stop```

After it finished, enable AOF again by changing appendonly in /etc/redis/redis.conf file to yes

```appendonly yes```

Then start the redis server again.

```/etc/init.d/redis-server start```

And we are done.

# Security

[How To Secure Your Redis Installation](https://www.digitalocean.com/community/tutorials/how-to-secure-your-redis-installation-on-ubuntu-14-04)

# Stablize

[Redis high traffic connection issue](http://redis4you.com/articles.php?id=012&name=redis)

**Snapshotting**

By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb. You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset, or you can manually call the SAVE or BGSAVE commands.
For example, this configuration will make Redis automatically dump the dataset to disk every 60 seconds if at least 1000 keys changed:

```save 60 1000```

_This strategy is known as snapshotting._

How it works
* Whenever Redis needs to dump the dataset to disk, this is what happens:
* Redis forks. We now have a child and a parent process.
* The child starts to write the dataset to a temporary RDB file.
* When the child is done writing the new RDB file, it replaces the old one.
* This method allows Redis to benefit from copy-on-write semantics.

**Append-only file**

Snapshotting is not very durable. If your computer running Redis stops, your power line fails, or you accidentally kill -9 your instance, the latest data written on Redis will get lost. While this may not be a big deal for some applications, there are use cases for full durability, and in these cases Redis was not a viable option.

The append-only file is an alternative, fully-durable strategy for Redis. It became available in version 1.1.
You can turn on the AOF in your configuration file:

`appendonly yes`

From now on, every time Redis receives a command that changes the dataset (e.g. SET) it will append it to the AOF. When you restart Redis it will re-play the AOF to rebuild the state.

[Redis Persistence](http://redis.io/topics/persistence)
Clone this wiki locally