以下是在Ubuntu上安装Redis的步骤:
- 打开终端并输入以下命令以更新软件包列表:
sudo apt update
- 输入以下命令以安装Redis:
sudo apt install redis-server
SET key value
GET key
key & value 区分大小写
127.0.0.1:6379> set name noritake
OK
127.0.0.1:6379> get name
"noritake"
127.0.0.1:6379> set Name Noritake
OK
127.0.0.1:6379> get Name
"Noritake"
value 默认是字符串
127.0.0.1:6379> set age 25
OK
127.0.0.1:6379> get age
"25"
DEL key
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)
EXISTS key
127.0.0.1:6379> exists name
(integer) 0
127.0.0.1:6379> exists age
(integer) 1
KEYS *
*
是匹配,*me
匹配结尾为 me
的 key
127.0.0.1:6379> keys *
1) "age"
2) "Name"
127.0.0.1:6379> keys *me
1) "Name"
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
(empty list or set)
支持中文
127.0.0.1:6379> set name 张三
OK
127.0.0.1:6379> get name
"\xe5\xbc\xa0\xe4\xb8\x89"127.0.0.1:6379> quit$ redis-cli --raw127.0.0.1:6379> get name
张三
TTL(Time to live)
127.0.0.1:6379> TTL name
-1
EXPIRE key
127.0.0.1:6379> expire name 10
1
127.0.0.1:6379> TTL name
3
127.0.0.1:6379> TTL name
2
127.0.0.1:6379> TTL name
1
127.0.0.1:6379> TTL name
0
127.0.0.1:6379> TTL name
-2
127.0.0.1:6379> TTL name
-2
127.0.0.1:6379> get name127.0.0.1:6379> keys name
SETEX key time value
127.0.0.1:6379> SETEX name 5 noritake
OK
127.0.0.1:6379> TTL name
-2
SETNX key value
只有当key存在时才有用
127.0.0.1:6379> SETNX name zz
1
127.0.0.1:6379> get name
zz
127.0.0.1:6379> SETNX age
ERR wrong number of arguments for 'setnx' command