redis 基础

2019-03-05  本文已影响0人  cityhash123

查询 keys 的数量

127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=941148,expires=28981,avg_ttl=1157938465
db1:keys=33621,expires=31024,avg_ttl=668524770

查询 DB 的 key 数量

127.0.0.1:6379> DBSIZE
(integer) 391

切换 db

127.0.0.1:6379> select 14
OK

By default there are 16 databases (indexed from 0 to 15) and you can navigate between them using select command. Number of databases can be changed in redis config file with databases setting.
By default, it selects the database 0. To select a specified one, use redis-cli -n 2 (selects db 2)

分隔符 delimiter

127.0.0.1:6379[2]> set /user/123/goods/345/count 1000
OK
127.0.0.1:6379[2]> keys *user*
1) "/user/123/goods/345/count"

suggest

We use a colon (:) as namespace separator and a hash (#) for id-parts of keys, e.g.:

logistics:building#23

colon sign : is a convention when naming keys. In this tutorial on redis website is stated: *Try to stick with a schema. For instance object-type:id:field can be a nice idea, like in user:1000:password. I like to use dots for multi-words fields, like in comment:1234:reply.to.*

上一篇下一篇

猜你喜欢

热点阅读