CentOS Stream 9
Sponsored Link

Redis 6 : Basic Operation for Server2022/07/04

 
This is the Basic Usage of Redis with [redis-cli] client program.
Following examples are basic one, you can see more commands on Official Site below.
⇒ https://redis.io/commands
[1] Connect to Redis Server like follows.
# connect to local Redis server

[root@dlp ~]#
redis-cli


# authenticate  ⇒ specify [password] you set in [redis.conf]
127.0.0.1:6379> auth password 
OK

# exit from connection
127.0.0.1:6379> quit 

# connect with password and database ID
# -a [password] -n [database ID]
# -a [password] on terminal is not safe, so warnings is shown
# if database ID is not specified, connect to database ID [0]
[root@dlp ~]# redis-cli -a password -n 1 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

# if not display auth warnings above, add [--no-auth-warning] option
[root@dlp ~]# redis-cli -a password -n 1 --no-auth-warning 

# change to Database-ID [2]
127.0.0.1:6379[1]> select 2 
OK
127.0.0.1:6379[2]> quit 

# to connect to Redis on another Host, specify [-h (hostname)]
[root@dlp ~]# redis-cli -h node01.srv.world 
node01.srv.world:6379>

# possible to get results with non-interactively with [redis-cli]
# for example, set and get Value of a Key
[root@dlp ~]# redis-cli -a password --no-auth-warning set key01 value01 
[root@dlp ~]# redis-cli -a password --no-auth-warning get key01 
"value01"
[2] This is the basic Usage of control Redis Server itself.
[root@dlp ~]#
redis-cli
127.0.0.1:6379> auth password 
OK

# refer to statics
127.0.0.1:6379> info 
# Server
redis_version:6.2.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ec192bdd77ecd321
redis_mode:standalone
os:Linux 5.14.0-115.el9.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:11.3.1
process_id:1546
process_supervised:systemd
run_id:08442cdd5658d3f559c569f71a7f3eaf8d06460f
tcp_port:6379
server_time_usec:1656659048284519
.....
.....

# show connected clients now
127.0.0.1:6379> client list 
id=10 addr=127.0.0.1:58984 laddr=127.0.0.1:6379 fd=8 name= age=66 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=40928 argv-mem=10 obl=0 oll=0 omem=0 tot-mem=61466 events=r cmd=client user=default redir=-1
id=11 addr=10.0.0.51:47556 laddr=10.0.0.30:6379 fd=9 name= age=5 idle=5 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 argv-mem=0 obl=0 oll=0 omem=0 tot-mem=20496 events=r cmd=command user=default redir=-1

# kill connection of a client
127.0.0.1:6379> client kill 10.0.0.51:47556 
OK

# dump all requests after the command below
127.0.0.1:6379> monitor 
OK
1656659298.186056 [0 10.0.0.51:56750] "auth" "(redacted)"
1656659311.236011 [0 10.0.0.51:56750] "set" "key01" "value01"
1656659315.908359 [0 10.0.0.51:56750] "get" "key01"
1656659319.925218 [0 10.0.0.51:56750] "del" "key01"
.....
.....

# save data on disk on foreground
127.0.0.1:6379> save 
OK

# save data on disk on background
127.0.0.1:6379> bgsave 
Background saving started

# get UNIX time stamp of the last save to disk
127.0.0.1:6379> lastsave 
(integer) 1656659377

# save data on disk and shutdown Redis
127.0.0.1:6379> shutdown 
not connected> quit 

[root@dlp ~]# ps aux | grep [r]edis 

Matched Content