Ubuntu 16.04 install redis

Install redis

apt-get installl redis-server

Install PHP redis

apt-get installl php-redis

Check redis process

ps -aux|grep redis

Accessing redis basic operations from the command line

root@ubuntu16:~# redis-cli

# View all key lists
127.0.0.1:6319>keys *
(empty list or set)
# Add a record key1
127.0.0.1:6379> set key1 "hello world"
OK
# Print record
redis 127.0.0.1:6379> get key1
"hello world"

# Add a digital record
127.0.0.1:6379> set key2 1
OK

# Let the number increase by itself
127.0.0.1:6379> INCR key2
(integer) 2

#Add a list record key3
127.0.0.1:6379> LPUSH key3 a
(integer) 1

# Insert list from left
127.0.0.1:6379> LPUSH key3 b
(integer) 2

# Insert list from right
127.0.0.1:6379> RPUSH key3 c
(integer) 3

# Print list records in left to right order
127.0.0.1:6379> LRANGE key3 0 3
1) "b"
2) "a"
3) "c"

# Delete key1,key2
127.0.0.1:6379> del key1
(integer) 1
127.0.0.1:6379> del key2
(integer) 1

Set redis password 123456

vi /etc/redis/redis.conf

#Uncomment requirepass foobared
requirepass 123456

#Save exit

Password login redis

redis-cli -h 127.0.0.1 -a 123456 -p 6379

# Remember that spaces after - h -a -p must have

Enable redis remote connection

vi /etc/redis/redis.conf

#Comment bind 127.0.0.1
#bind 127.0.0.1

Restart Redis server

service redis restart

# perhaps

/etc/init.d/redis-server restart

Check the port occupied by Redis server

root@ubuntu16:~# netstat -nlt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN

Remote connection redis

root@ubuntu:~# redis-cli -h 192.168.159.129 -a 123456 -h 6379
192.168.129.129:6379>

Command No. connecting redis without password

root@ubuntu:~# redis-cli -h 192.168.159.129 -h 6379
192.168.129.129:6379>auth 123456
OK
192.168.129.129:6379>keys *
1) "key2"
1) "key1"

Using authentication password in Redis cluster

If the Redis server uses a cluster. In addition to configuring the password in the master, you also need to configure it in the slave. Find the following line in the slave configuration file, remove the comment and modify the same password as the master

# masterauth master-password

Tags: Redis PHP Ubuntu

Posted on Mon, 06 Jan 2020 06:48:33 -0800 by xyn