1. Preface
Redis is a common memory-based Key-value database that is more advanced than memcache and supports a variety of data structures, efficiently and quickly. Redis makes it easy to solve high-concurrency data access problems, and it is also very good to monitor signal processing at all times. 2. Installation
Installing the Redis server-side sudo apt-get install redis-server in the terminal
After the installation is complete, the Redis server starts automatically and we check the Redis server program
To check the Redis server system process in the terminal
Ps-aux|grep Redis
can see:
Check Redis server Status by starting command in Terminal
Netstat-nlt|grep 6379
Display: 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
Display: Redis-server is running 3, accessing Redis via 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-cli
redis 127.0.0.1:6379>
# command line help
Redis 127.0.0.1:6379> helps
redis-cli 2.2.12
Type: ' Help @ ' to get a list of commands in ' help ' for ' help ' on
' help ' to get a list of possible Help topics
"Quit" to exit
# View all key list
Redis 127.0.0.1:6379> keys *
(empty list or set)
The basic Redis Client command operation adds a string record Key1
# Add a record key1
Redis 127.0.0.1:6379> set key1 "Hello"
OK
# print record
Redis 127.0.0.1:6379> get key1< c15/> "Hello"
2. Add a digital record Key2
# Add a digital record Key2
set key2 1
OK
# let digital self-increment
redis 127.0.0.1:6379> INCR key2
(integer) 2
Redis 127.0.0.1:6379> INCR key2
(integer) 3
# Print records
Redis 127.0.0.1:6379> get Key2
"3"
3. Add a list record Key3
# Add a list record Key3
Redis 127.0.0.1:6379> lpush key3 a
(integer) 1
# Insert list from left
Redis 127.0.0.1:6379> Lpush Key3 b
(integer) 2
# from the right insert list
Redis 127.0.0.1:6379> rpush key3 C
(integer) 3
# Print List records, By left-to-right sequence
redis 127.0.0.1:6379> lrange key3 0 3
1) "B"
2) "a"
3) "C"
4. Add a hash table record Key4
# Add a hash record Key4
redis 127.0.0.1:6379> hset key4 name "John Smith"
(integer) 1
# Inserted in the hash table, e-mail key and value
Redis 127.0.0.1:6379> hset key4 Email "abc@gmail.com"
(integer) 1
# Print hash table, Name is the value of key
Redis 127.0.0.1:6379> hget key4 name
"John Smith"
# Print entire hash table
Redis 127.0.0.1:6379 > Hgetall key4
1) "Name"
2) "John Smith"
3) "Email"
4) "Abc@gmail.com"
5. Add a hash table record Key5
# Add a hash table record KEY5, insert multiple key and value values at once
redis 127.0.0.1:6379> hmset key5 username Antirez password p1pp0 age 3
ok< c2/># print hash table, username and age are key values for
Redis 127.0.0.1:6379> hmget key5 username age
1) "Antirez"
2) "3"
# Print the full hash table record for
Redis 127.0.0.1:6379> hgetall key5
1) "username"
2) "Antirez"
3) "Password"
4) " P1pp0 "
5)" Age "
6)" 3 "
6. Deleting records
# View all key list
Redis 127.0.0.1:6379> keys *
1) "Key2"
2) "Key3"
3) "Key4"
4) "Key5"
5) " Key1 "
# delete key1,key5
redis 127.0.0.1:6379> del key1
(integer) 1
redis 127.0.0.1:6379> del Key5
(integer) 1
# View all key list
Redis 127.0.0.1:6379> keys *
1) "Key2"
2) "Key3"
3) " Key4 "
4. Modify the Redis configuration
1 . Access account using Redis
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 for Redis.
Open the configuration file for Redis server with VI redis.conf
~ sudo vi/etc/redis/redis.conf
#取消注释requirepass
requirepass Redis
2. 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/redis.conf
#注释bind
#bind 127.0.0.1
After modification, restart the Redis server.
~ sudo/etc/init.d/redis-server Restart
stopping redis-server:redis-server.
Starting Redis-server:redis-server.
Login to Redis server with no password
~ REDIS-CLI
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-a Redisredis
redis 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 Port
~ netstat-nlt|grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
We saw from the network monitoring from 127.0.0.1:6379 to 0 0.0.0.0:6379, which means that Redis has allowed remote login access.
We access the Redis server from another Linux remote
~ redis-cli-a redisredis-h 192.168.1.199
redis 192.168.1.199:6379> keys *
1) "Key2"
2) "Key3"
3) "Ke Y4 "
Remote access is OK. With the above operation, we will install the Redis database server in Linux Ubuntu system.
Original link