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>keys *
(empty list or set)
# Add a record key1> set key1 "hello world"
# Print record
redis> get key1
"hello world"

# Add a digital record> set key2 1

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

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

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

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

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

# Delete key1,key2> del key1
(integer) 1> 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 -a 123456 -p 6379

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

Enable redis remote connection

vi /etc/redis/redis.conf

#Comment bind

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  *               LISTEN

Remote connection redis

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

Command No. connecting redis without password

root@ubuntu:~# redis-cli -h -h 6379>auth 123456
OK>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