这里只整理里项目中常用的操作
1、hash操作
要存储一个项目表记录,id:2008030628 xm_name:"宝鸡市XX项目" time:"2008-06-28"
执行命令:
登陆
redis-cli -h 1.2.3.4 -p 6379
插入数据
hmset id:2008030628 xm_name "宝鸡市XX项目" time 2008-06-28
1.2.3.4:6379> hmset id:2008030628 xm_name "宝鸡市XX项目" time 2008-06-28
OK
hset id:2008030628 xm_name "宝鸡市XX项目1"
获取Key的值
hget id:2008030628 xm_name
1.2.3.4:6379> hget id:2008030628 xm_name
"\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82XX\xe9\xa1\xb9\xe7\x9b\xae1"
获取字段
hkeys id:2008030628
1.2.3.4:6379> hkeys id:2008030628
1) "xm_name"
2) "time"
获取字段键值对
hvals id:2008030628
1.2.3.4:6379> hgetall id:2008030628
1) "xm_name"
2) "\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82XX\xe9\xa1\xb9\xe7\x9b\xae1"
3) "time"
4) "2008-06-28"
2、字符串操作
获得符合规则的键名列表
1.2.3.4:6379> keys *
1) "test"
2) "id:2008030628"
3) "1"
判断键是否存在
1.2.3.4:6379> exists id:2008030628
(integer) 1
根据键删除
1.2.3.4:6379> keys *
1) "test"
2) "id:2008030628"
3) "1"
10.160.29.5:6379> del 1
(integer) 1
查看键所属类型
1.2.3.4:6379> type id:2008030628
hash
阅读(2141) | 评论(0) | 转发(1) |