redis

 

介紹

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

It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence,

and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
 


資料

 

port: 127.0.0.1:6379
user: redis

# check version

redis-server -v

redis-cli -v

 


Compile from source

 

yum install jemalloc-devel lua-devel hiredis-devel

$ tar -xzf redis-*.tar.gz
$ cd redis-*
$ make

Troubleshoot

cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directory

# solve by run

make distclean

cp -f redis-benchmark /usr/bin/redis-benchmark
cp -f redis-cli /usr/bin/redis-cli
cp -f redis-sentinel /usr/bin/redis-sentinel

# 這 3 個 file 是一樣

cp -f redis-server /usr/bin/redis-server
cp -f redis-check-aof /usr/bin/redis-check-aof
cp -f redis-check-rdb /usr/bin/redis-check-rdb

 


Test

 

# Start Server

src/redis-server

# Client

redis-cli ping

$ src/redis-cli

redis> set foo bar
OK
redis> get foo
"bar"

 


System File

 

/etc/systemd/system/redis.service.d/limit.conf

[Service]
LimitNOFILE=10240

/etc/logrotate.d/redis

/var/log/redis/*.log {
    weekly
    rotate 10
    copytruncate
    delaycompress
    compress
    notifempty
    missingok
}

/usr/lib/systemd/system/redis.service

[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target