Serwer Redis przechowujący struktury danych może być używany jako baza danych czy też cache. W Redis można przechowywać nie tylko wartoście tekstowe, lecz również bardziej złożonej struktury jak listy czy zbiory danych. Poniżej przedstawię jak szybko zainstalować serwer Redis w systemie OS X, a także kilka podstawowych poleceń. Więcej informacji można znaleźć w oficjalnej dokumentacji.
Instalacja serwera Redis oraz klienta CLI
bash-3.2$ brew install redis ==> Downloading https://homebrew.bintray.com/bottles/redis-3.2.0.el_capitan.bottle.tar.gz ######################################################################## 100,0% ==> Pouring redis-3.2.0.el_capitan.bottle.tar.gz ==> Caveats To have launchd start redis now and restart at login: brew services start redis Or, if you don't want/need a background service you can just run: redis-server /usr/local/etc/redis.conf ==> Summary 🍺 /usr/local/Cellar/redis/3.2.0: 10 files, 1.7M
Uruchomienie serwera Redis
MacBook-Pro-Sebastian:~ seba$ redis-server 1096:C 14 Aug 13:18:33.830 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 1096:M 14 Aug 13:18:33.831 * Increased maximum number of open files to 10032 (it was originally set to 256). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.0 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1096 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 1096:M 14 Aug 13:18:33.835 # Server started, Redis version 3.2.0 1096:M 14 Aug 13:18:33.836 * The server is now ready to accept connections on port 6379
Połączenie klienta CLI do serwera Redis
bash-3.2$ redis-cli 127.0.0.1:6379> ping PONG
Zapis i odczyt wartości parametru przechowywanego w Redis
127.0.0.1:6379> get mykey (nil) 127.0.0.1:6379> set mykey somevalue OK 127.0.0.1:6379> get mykey "somevalue"