# syntax 1 : connect using host & port, followed by password$ redis-cli -h host -p port
> AUTH password
OK
# example 1$ redis-cli -h redis15.localnet.org -p 6390> AUTH myUnguessablePassword
OK
# syntax 2 : connect using uri$ redis-cli -u redis://user:password@host:port/dbnum
# example 2$ redis-cli -u redis://LJenkins:p%40ssw0rd@redis-16379.hosted.com:16379/0
•基本的 CLI/RedisInsight 工作台命令
# syntax : Check specific keys> KEYS pattern
# example> KEYS *
#------------# syntax : Check number of keys in database> DBSIZE
#------------# syntax : set a key value> SET key value EX expirySeconds
# example> SET company redis EX 60#------------# syntax : get value by key> GET key
# example> GET company
#------------# syntax : delete keys> DEL key1 key2 key3 ... keyN
# example> DEL company
#------------# syntax : Check if key exists> EXISTS key1
# example> EXISTS company
#------------# syntax : set expiry to key> EXPIRE key seconds
# example> EXPIRE lastname 60#------------# syntax : remove expiry from key> PERSIST key
# example> PERSIST lastname
#------------# syntax : find (remaining) time to live of a key> TTL key
# example> TTL lastname
#------------# syntax : increment a number> INCR key
# example> INCR counter
#------------# syntax : decrement a number> DECR key
# example> DECR counter
# syntax> FT.CREATE {index_name} ON JSON PREFIX {count}{prefix} SCHEMA {json_path} AS {attribute}{type}# NOTE: attribute = logical name, json_path = JSONPath expressions# example> FT.CREATE userIdx ON JSON PREFIX 1 users: SCHEMA $.user.name AS name TEXT $.user.hobbies AS hobbies TAG $.user.age as age NUMERIC
# NOTE: You can search by any attribute mentioned in the above index for keys that start with users: (e.g. users:1).
# search all user documents with name 'John'> FT.SEARCH userIdx '@name:(John)'1)(integer)12)"myDoc"3)1)"$"2){"user":{"name":"John Smith","hobbies":"foo,bar","age":23}}"
•搜索并投影所需字段
# search documents with name 'John' & project only age field> FT.SEARCH userIdx '@name:(John)' RETURN 1 $.user.age
1)(integer)12)"myDoc"3)1)"$.user.age"2)"23"
# project multiple fields> FT.SEARCH userIdx '@name:(John)' RETURN 2 $.user.age $.user.name
1)(integer)12)"myDoc"3)1)"$.user.age"2)"23"3)"$.user.name"4)"John Smith"#------------# project with alias name> FT.SEARCH userIdx '@name:(John)' RETURN 3 $.user.age AS userAge
1)(integer)12)"myDoc"3)1)"userAge"2)"23"#------------# multi field query> FT.SEARCH userIdx '@name:(John) @hobbies:{foo | me} @age:[20 30]'1)(integer)12)"myDoc"3)1)"$"2){"user":{"name":"John Smith","hobbies":"foo,bar","age":23}}"
# Reserve a new leaderboard filter> TOPK.RESERVE trending-stocks 125040.9"OK"# Add a new entries to the leaderboard> TOPK.ADD trending-stocks AAPL AMD MSFT INTC GOOG FB NFLX GME AMC TSLA
1)"null"...
# Get the leaderboard> TOPK.LIST trending-stocks
1)"AAPL"2)"AMD"2)"MSFT"...
# Get information about the leaderboard> TOPK.INFO trending-stocks
1)"k"2)"12"3)"width"4)"50"5)"depth"6)"4"7)"decay"8)"0.90000000000000002"
# Create new time-series, for example temperature readings> TS.CREATE temperature:raw DUPLICATE_POLICY LAST
"OK"# Create a bucket for monthly aggregation> TS.CREATE temperature:monthly DUPLICATE_POLICY LAST
"OK"# Automatically aggregate based on time-weighted average> TS.CREATERULE temperature:raw temperature:monthly AGGREGATION twa 2629800000"OK"# Add data to the raw time-series> TS.MADD temperature:raw 162166680000052...
1)"1621666800000"...
# View the monthly time-weighted average temperatures> TS.RANGE temperature:monthly 0 +
1)1)"1621666800000"2)"52"...
# Delete compaction rule> TS.DELETERULE temperature:raw temperature:monthly
"OK"# Delete partial time-series> TS.DEL temperature:raw 01621666800000(integer)1