Redis : Basic Usage#12016/07/20 |
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.
⇒ http://redis.io/commands |
|
[1] | Connect to Redis Server like follows. |
# connect to local server # password is the one you set on redis.conf [root@dlp ~]# redis-cli -a password # exit from connection 127.0.0.1:6379> quit # possible to authenticate after connecting to Server [root@dlp ~]# redis-cli 127.0.0.1:6379> auth password OK # connect to a Database with specifying Database-ID explicitly # if Database-ID is not specified, connect to Database-ID "0" [root@dlp ~]# redis-cli -a password -n 1 127.0.0.1:6379[1]> # change to Database-ID "2" 127.0.0.1:6379[1]> select 2 OK 127.0.0.1:6379[2]> # for connecting to Redis on another Host, specify "-h [hostname]" [root@dlp ~]# redis-cli -h node01.srv.world -a password 10.0.0.51:6379> # possible to get results with non-interactively with redis-cli # for example, get Value of a Key [root@dlp ~]# redis-cli -a password get key01 "value02" |
[2] | This is the basic Usage of control Redis Server itself. |
[root@dlp ~]#
redis-cli -a password # refer to statics 127.0.0.1:6379> info # Server redis_version:2.8.19 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:c0359e7aa3798aa2 redis_mode:standalone os:Linux 3.10.0-327.22.2.el7.x86_64 x86_64 arch_bits:64 ..... ..... # show connected clients 127.0.0.1:6379> client list id=3 addr=127.0.0.1:44474 fd=5 name= age=447 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client id=4 addr=10.0.0.31:43668 fd=6 name= age=10 idle=10 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth # kill connection of a client 127.0.0.1:6379> client kill 10.0.0.31:43668 OK # dump all requests after the command below 127.0.0.1:6379> monitor OK 1469078099.850114 [0 10.0.0.31:43666] "get" "key01" 1469078112.319154 [0 10.0.0.31:43666] "set" "key02" "value02" ..... ..... # save data on disk with foreground 127.0.0.1:6379> save OK # save data on disk with 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) 1469078407 # save data on disk and shutdown Redis 127.0.0.1:6379> shutdown not connected> quit [root@dlp ~]# ps aux | grep [r]edis |
Sponsored Link |