CentOS Stream 10
Sponsored Link

Valkey : Basic Operation for Server2025/02/03

 

This is the Basic Usage of Valkey with [valkey-cli] client program.

[1] Connect to Valkey Server like follows.
# connect to local Valkey server

[root@dlp ~]#
valkey-cli


# authenticate ⇒ specify [password] you set in [valkey.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 ~]# valkey-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 ~]# valkey-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 valkey on another Host, specify [-h (hostname)]
[root@dlp ~]# valkey-cli -h node01.srv.world 
node01.srv.world:6379>

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

# refer to statics
127.0.0.1:6379> info 
# Server
redis_version:7.2.4
server_name:valkey
valkey_version:8.0.2
redis_git_sha1:00000000
redis_git_dirty:1
redis_build_id:93b69bf03863bc8c
server_mode:standalone
os:Linux 6.12.0-39.el10.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
gcc_version:14.2.1
process_id:1841
process_supervised:systemd
run_id:c947857742ab4e83cc1d9c00fdbb9976f7f8f5fe
tcp_port:6379
server_time_usec:1738541974833838
uptime_in_seconds:112
uptime_in_days:0
.....
.....

# show connected clients now
127.0.0.1:6379> client list 
id=8 addr=127.0.0.1:43268 laddr=127.0.0.1:6379 fd=11 name= age=43 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=10 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=1946 events=r cmd=client|list user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=138 tot-net-out=5957 tot-cmds=2

# dump all requests after the command below
127.0.0.1:6379> monitor 
OK
1738542363.191580 [0 10.0.0.51:43366] "set" "key03" "value03"
1738542369.808122 [0 10.0.0.51:43366] "set" "key04" "value04"
.....
.....

# 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) 1738542428

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

[root@dlp ~]# ps aux | grep [v]alkey 

Matched Content