查找键,参数支持正则 127.0.0.1:6379> keys pattern 127.0.0.1:6379> keys * 127.0.0.1:6379> keys "*n*" 判断键是否存在,如果存在返回1,不存在返回0 127.0.0.1:6379> exists key [key ...] 127.0.0.1:6379> exists name 查看键对应的value值的类型 127.0.0.1:6379> type key 127.0.0.1:6379> type name 删除键及对应的值 127.0.0.1:6379> del key [key ...] 127.0.0.1:6379> del name 127.0.0.1:6379> del ccc ddd 设置过期时间,以秒为单位。创建时没有设置过期时间则一直存在,直到使用del移除 127.0.0.1:6379> expire key seconds 127.0.0.1:6379> expire name 600 查看有效时间,以秒为单位 127.0.0.1:6379> ttl key 127.0.0.1:6379> ttl name
设置单个键值 127.0.0.1:6379> set key value 127.0.0.1:6379> set "name" "liu" 设置单个键值及过期时间,以秒为单位 127.0.0.1:6379> setex key seconds value 127.0.0.1:6379> setex "name" 3 "liu" 设置多个键值 127.0.0.1:6379> mset key value [key value ...] 127.0.0.1:6379> mset "ccc" "111" "ddd" "222" 根据键获取值,如果不存在此键则返回nil 127.0.0.1:6379> get key 127.0.0.1:6379> get name 根据多个键获取多个值 127.0.0.1:6379> mget key [key ...] 127.0.0.1:6379> mget ccc ddd 追加值 127.0.0.1:6379> append key value 127.0.0.1:6379> append name " hai" 获取值长度 127.0.0.1:6379> strlen key 127.0.0.1:6379> strlen name 运算要求:值是数字 将key对应的value加1 127.0.0.1:6379> incr key 127.0.0.1:6379> incr ccc 将key对应的value加整数 127.0.0.1:6379> incrby key increment 127.0.0.1:6379> incrby ccc 6 将key对应的value减1 127.0.0.1:6379> decr key 127.0.0.1:6379> decr ccc 将key对应的value减整数 127.0.0.1:6379> decrby key decrement 127.0.0.1:6379> decrby ccc 6
如对本文有疑问, 点击进行留言回复!!
修复 Mac brew 安装 mongodb 报 Error: No available formula with the name ‘mongodb’ 问题详解
MongoDB中数据的替换方法实现类Replace()函数功能详解
网友评论