“Redis基础数据结构”的版本间的差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
Jihongchang(讨论 | 贡献)  (建立内容为“=== string(字符串) ===  ==== 键值对 ====  === list(列表) ===  === hash(字典) ===  === set(集合) ===  === zset(有序集合) ===”的新页面)  | 
				Jihongchang(讨论 | 贡献)   | 
				||
| 第2行: | 第2行: | ||
==== 键值对 ====  | ==== 键值对 ====  | ||
| + | <syntaxhighlight lang="powershell">  | ||
| + | F:\下载目录\Redis-x64-5.0.14.1>redis-cli  | ||
| + | 127.0.0.1:6379> set test_key test_value  | ||
| + | OK  | ||
| + | 127.0.0.1:6379> get test_key  | ||
| + | "test_value"  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | ==== 批量键值对 ====  | ||
| + | <syntaxhighlight lang="powershell">  | ||
| + | 127.0.0.1:6379> set test_key1 test_value1  | ||
| + | OK  | ||
| + | 127.0.0.1:6379> set test_key2 test_value2  | ||
| + | OK  | ||
| + | 127.0.0.1:6379> mget test_key test_key1 test_key2  | ||
| + | 1) "test_value"  | ||
| + | 2) "test_value1"  | ||
| + | 3) "test_value2"  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | ==== 过期和 set 命令扩展 ====  | ||
| + | <syntaxhighlight lang="powershell">  | ||
| + | 127.0.0.1:6379> set name codehole  | ||
| + | OK  | ||
| + | 127.0.0.1:6379> get name  | ||
| + | "codehole"  | ||
| + | 127.0.0.1:6379> expire name 5    # 5s 后过期  | ||
| + | (integer) 1  | ||
| + | ...           #等候 5s  | ||
| + | 127.0.0.1:6379> get name  | ||
| + | (nil)  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | |||
=== list(列表) ===  | === list(列表) ===  | ||
2022年8月12日 (五) 11:04的版本
string(字符串)
键值对
F:\下载目录\Redis-x64-5.0.14.1>redis-cli
127.0.0.1:6379> set test_key test_value
OK
127.0.0.1:6379> get test_key
"test_value"
批量键值对
127.0.0.1:6379> set test_key1 test_value1
OK
127.0.0.1:6379> set test_key2 test_value2
OK
127.0.0.1:6379> mget test_key test_key1 test_key2
1) "test_value"
2) "test_value1"
3) "test_value2"
过期和 set 命令扩展
127.0.0.1:6379> set name codehole
OK
127.0.0.1:6379> get name
"codehole"
127.0.0.1:6379> expire name 5    # 5s 后过期
(integer) 1
...           #等候 5s
127.0.0.1:6379> get name
(nil)