Redis 基础
Redis入门
#
简介- key-value存储系统,非关系数据库
- 高性能,单线程机制(没有并发问题,这一点可以被充分利用)
#
基本指令SET <PARAM> "STRING"GET <PARAM>INCR <PARAM>INCRBY <PARAM> 10DECR <PARAM>DECRBY <PARAM> 10
// for listLPUSH <ARR> XXRPUSH <ARR> XXLEN <ARR>LPOP <ARR>RPOP <ARR>LRANGE <ARR> 0 -1
// for setSADD <SET> XXSREM <SET> XXSISMEMBER <SET> XXSMEMBERS <SET>SUNION <SET1> <SET2>
// for sorted set / zsetZADD <ZET> ZRANGE <ZET> 0 -1
// for hashes (Object in JS)HSET <HASH> <KEY> <VALUE>HGETALL <HASH>HMSET <HASH> <KEY> <VALUE> <KEY> <VALUE> <KEY> <VALUE> ...HGET <HASH> <KEY>HINCRBYHDEL
#
数据类型#
注意- 指令不分大小写,参数名/HASH KEY分
#
规范以下来自StackOverflow
What are the normal naming convention for keys in redis? I've seen values separated by : but I'm not sure what the normal convention is, or why.
Yes, 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🆔field" can be a nice idea, like in "user:1000:password". I like to use dots for multi-words fields, like in "comment🔢reply.to".
Are you able to query for just the beginning of the key to return all users?
If you mean someting like directly querying for all keys which starts with user: there is a keys command for that. This command should be however used only for debugging purpose since it's O(N) because it's searching through all keys strored in database.
More appropriate solution for this problem is to create dedicated key, let's name is users, which will store all the users keys, for example, in list or set data structure.