Installing the Redis server side
sudo Install Redis-server
After the installation is complete, the Redis server starts automatically and we check the Redis server program
Check Redis Server System processes
~PS-aux|grepRedisredis4162 0.1 0.0 10676 1420? Ss at: - 0:xx/usr/bin/redis-server/etc/redis/Redis.confconan4172 0.0 0.0 11064 924pts/0S+ at: - 0:xx grep--color=auto Redis
Check Redis server Status by starting command
~ netstat-nlt| grep 6379 TCP 0 0 127.0. 0.1:6379 0.0. 0.0:* LISTEN
Check Redis server Status by starting command
~$sudo/etc/init.d/redis-Server Status Redis-server.service-advanced key-Value Store loaded:loaded (/lib/systemd/system/redis-server.service; Vendor preset:enabled) Active:active (running) since four .- One- the A: A: theCST; 59s ago Docs:http://Redis.io/documentation, Mans: Redis-server (1) Main PID:5394(redis-server) CGroup:/system.slice/redis-server.service└─5394/usr/bin/redis-server127.0.0.1:6379November the A: A: theZzf systemd[1]: Starting Advanced key-Value Store ... November the A: A: theZzf run-parts[5388]: run-parts:executing/etc/redis/Redi...le11 Month the A: A: theZzf run-parts[5395]: run-parts:executing/etc/redis/Redi...le11 Month the A: A: theZzf systemd[1]: Started Advanced key-value Store. Hint:some lines were ellipsized, use-L to showinchFull.
Accessing Redis from a command-line client
Installing the Redis server will automatically install the Redis command-line client program together.
The native Input redis-cli command can be started, and the client program accesses the Redis server.
~ redis-Cliredis127.0.0.1:6379># command-line help Redis127.0.0.1:6379>Helpredis-cli2.2. AType:"Help @"To get a list of commandsinch " Help" for Help on" Help"To get a list of possible Help topics"quit"to exit# View all key list Redis127.0.0.1:6379> Keys *(empty list or set)
Basic Redis Client Command operations
Add a record Key1
127.0. 0.1:6379"hello"127.0. 0.1:6379> get key1"hello"
Add a digital record
1127.0. 0.1:6379>2127.0. 0.1:6379>3127.0. 0.1:6379> get key2"3"
Add a list record Key3
Redis127.0.0.1:6379>lpush Key3 A (integer)1# Insert List from left Redis127.0.0.1:6379>lpush Key3 B (integer)2# Insert List from right Redis127.0.0.1:6379>rpush key3 C (integer)3# Print List records, by left-to-right in the order of Redis127.0.0.1:6379> Lrange Key30 31)"b"2)"a"3)"C"
Add a hash record Key4
Redis127.0.0.1:6379> Hset key4 Name"John Smith"(integer)1# Insert in hash table, email key and value Redis127.0.0.1:6379> Hset key4 Email"[email protected]"(integer)1# Print Hash table, name is the value of key Redis127.0.0.1:6379>hget Key4 name"John Smith"# Print entire hash table Redis127.0.0.1:6379>Hgetall Key41)"name"2)"John Smith"3)"Email"4)"[email protected]"
Add a hash table record Key5
# Add a hash table record KEY5, insert multiple keys and value at a time Redis127.0.0.1:6379> hmset key5 username antirez Password P1pp0 age3ok# print hash table, username and the value of age key Redis127.0.0.1:6379>hmget key5 username age1)"Antirez"2)"3"# Print full hash table record for Redis127.0.0.1:6379>Hgetall Key51)"username"2)"Antirez"3)"Password"4)"p1pp0"5)" Age"6)"3"
Deleting records
# View all key list Redis127.0.0.1:6379> Keys *1)"Key2"2)"Key3"3)"Key4"4)"Key5"5)"Key1"# Delete Key1,key5redis127.0.0.1:6379>del key1 (integer)1Redis127.0.0.1:6379>del key5 (integer)1# View all key list Redis127.0.0.1:6379> Keys *1)"Key2"2)"Key3"3)"Key4"
Modifying Redis's configuration using Redis's access account
By default, access to the Redis server does not require a password, and for added security we need to set the access password for the Redis server. Set the access password to Redisredis.
Open the configuration file for Redis server with VI redis.conf
sudo vi /etc/redis/redis.conf# uncomment requirepassrequirepass Redisredis
Let Redis server be accessed remotely
By default, the Redis server does not allow remote access and allows only native access, so we need to set the ability to turn on remote access.
Open the configuration file for Redis server with VI redis.conf
sudo vi /etc/redis/127.0. 0.1
After modification, restart the Redis server
sudo /etc/init.d/redis-server restartstopping redis-server:redis-server. Starting Redis-server:redis-server.
Login to Redis server with no password
~ redis-127.0. 0.1:6379> Keys *(Error) ERR operation not permitted
Found to be able to log on, but could not execute command.
Login to Redis server and enter your password
~ redis-cli-127.0. 0.1:6379> Keys *1"key2"2"Key3 "3"key4 "
After landing, everything is fine.
We check Redis's network listening port
Check Redis server footprint ports
~ netstat-nlt| grep 6379 TCP 0 0 0.0. 0.0:6379 0.0. 0.0:* LISTEN
We saw that the network listener changed from the previous 127.0.0.1:3306 to 0 0.0.0.0:3306, which means that Redis has allowed remote login access.
We access the Redis server from another Linux remote
192.168. 1.199 192.168. 1.199:6379> Keys *1"key2"2" Key3"3"key4 "
Remote access is OK. With the above operation, we will install the Redis database server in Linux Ubuntu system.
Ubuntu16.04 Installing Redis