First, download, compile
Redis is released as source code, first download the source code, and then compile under Linux
1.1 http://www.redis.io/download first to download stable stable version, the current version is 2.8.17
1.2 Upload to Linux, and then run the following command to unzip
tar xzf redis-2.8.17.tar.gz
1.3 Compiling
cd redis-2.8.17
make
Note: The make command requires the installation of GCC on Linux, if the machine is not installed in the Gcc,redhat environment, if you can network, you can type
Yum-y Install GCC Installation
(If you have previously installed a different version of GCC, causing the make to fail, try yum-y remove gcc first to delete the old version)
Another: In the compilation if prompted "newer version of Jemalloc required" error, after make add parameter malloc=libc, that is make MALLOC=LIBC
Second, modify the Redis port, adjust the operation mode for the background process daemonize mode of operation
The default port is 6379, if the port on Linux is wall, try a different port
2.1 Refer to the following command (change the port to 7030)
CD $REDIS _home (go to REDIS home directory)
mkdir conf (Create conf directory for storage configuration)
CD conf (enter the Conf directory)
Cp.. /redis.conf redis7030.conf (Copy the redis.conf under the parent directory to the current directory and rename it to redis7030.conf)
VI redis7030.conf (Edit the configuration file with VI)
Found it:
Daemonize No, change No to Yes
Port 7030, change 6379 to 7030
And then save the exit
Third, start Redis
CD $REDIS _HOME/SRC
./redis-server. /conf/redis7030.conf
Iv. using REDIS-CLI Client Authentication
Still remain under "Redis_home home directory \src", enter
./redis-cli-p 7030 Set test ' Hello Redis '
That is: Specify Port 7030, connect to the native Redis, and set a cache entry with key Test,value as ' Hello Redis '
(Note: If you are connecting to a remote Redis server, you can use a similar./redis-cli-h 192.168.1.190-p 8030 get a)
Read cache
./redis-cli-p 7030 Get test cache entry
Delete Cache
./redis-cli-p 7030 del Test
Tip: Redis does not offer a bulk deletion method and can be deleted in bulk using the following tips./redis-cli-p 7030 KEYS "*" | Xargs./redis-cli-p 7030 DEL
In addition, you can also use the
./redis-benchmark-p 7030 for performance testing
V. Stop Redis
./redis-cli-p 7030 Shutdown
For later operations, you can use alias to make a few aliases,
VI ~/.BASHRC
Alias redis= "Cd/opt/app/redis/redis-2.8.17/src"
Alias startredis= "/opt/app/redis/redis-2.8.17/src/redis-server/opt/app/redis/redis-2.8.17/conf/redis7030.conf"
Alias stopredis= "/opt/app/redis/redis-2.8.17/src/redis-cli-p 7030 shutdown"
Specific path, you adjust according to the actual situation, save the exit, reconnect to the Linux terminal
Redis can go directly to the Redis root directory
Startredis that starts Redis
Stopredis Stop Redis
Vi. configuring Redis to be used only as a cache
If you do not plan to use transactions, pipelines and other complex functions, just to use Redis as the cache server, you can find in the configuration file MaxMemory, maxmemory-policy These two items, refer to the following changes
maxmemory 2048mbmaxmemory-policy allkeys-lru
That is: the maximum allowable use of 2G memory, all keys are eliminated by the LRU (least recently used) algorithm, in this case, do not set the expiration time, as long as the memory used to reach the upper limit, the less used key is naturally killed.
Attached: redis.conf configuration of micro-optimization (from Baidu Encyclopedia copied over)
1 daemonize Yes 2 3 pidfile/opt/app/redis/redis-2.8.17/var/redis.pid 4 5 Port 7030 6 7 timeout + 8 9 lo Glevel debug10 logfile/opt/app/redis/redis-2.8.17/var/redis.log12 Databases 1614 Save 900116 + save 3001018 19 Save 601000020 rdbcompression yes22 dump.rdb24 DIR/OPT/APP/REDIS/REDIS-2.8.17/VAR/26 No Appendfsync always30 # slaveof <masterip> <masterport>32 # Masterauth <master-password>33-SL Ave-serve-stale-data yes35 slave-read-only yes37, MaxMemory 1gb39, Maxmemory-policy ALLKEYS-LRU
which
Port, 38 rows-Maximum memory usage, and var directory path, you adjust according to the actual situation
Finally, before writing the code, it is strongly recommended to read the next introduction to Redis data types and abstractions (official website of the entry document), and carefully the text mentioned in the example through the REDIS-CLI run once
(turn) Redis Learning Notes (1)-compile, start, stop