redis命令集

$ ./redis-cli -h 192.168.228.174  表示连接 192.168.228.174的redis服务器

查看redis信息: info
ping服务器: ping
退出客户端: quit

事务:
MULTI : 开启事物
* some redis command *
EXEC. : 执行事物

DISCARD :取消事物
WATCH : 监视key ,如果在事务执行之前 key 被其他命令所改动,那么事务将被打断

判断Key 是否存在 : exists key
查看所有的keys : keys * // *通配符 s*表示s开头的key,区分大小写
判断Key的类型 : type key

清空所有数据库:flushall
清空当前数据库:flushdb  //

设置主从库: slaveof 192.168.228.174 6379  // 本地数据库会同步到主库
取消跟从: slaveof no noe

server:

client kill ip:port -> Kill the connection of a client
client list   -> Get the list of client connections
client getname -> Get the current connection name
client set name connection-name -> Set the current connection name

time          -> Return the current server time
save          -> Synchronously save the dataset to disk
bgsave -> Asynchronously save the dataset to disk
lastsave -> Get the UNIX time stamp of the last successful save to disk
dbsize -> Return the number of keys in the selected database

sync -> Internal command used for replication
shutdown -> Synchronously save the dataset to disk and then shut down the server

?? monitor -> Listen for all requests received by the server in real time

config get parameter -> Get the value of a configuration parameter
config set paramater value -> Set a configuration parameter to the given value
config resetstat -> Reset the stats returned by INFO
config rewrite -> Rewrite the configuration file with the in memory configuration

debug object key -> Get debugging information about a key
debug segfault -> Make the server crash

Connection:
echo message -> Echo the given string
auth password -> Authenticate to the server

what is channel  ? how publish & subscribe ?
 
字符串命令:
get key ->  get foo
set key value -> set foo bar
append key value -> append foo bar2  如果 foo之前是bar 执行后foo成为 barbar2
strlen key -> 获取value长度

decr key -> 要求value是整数
decrby key decrement
incr key
incrby key increment

incrbyfloat key increment -> Increment the float value of a key

getset key value -> 返回旧值

mget key [key ...] ->  多个get/set
mset key value [key value ...]

getrange key start end -> getter/setter部分子串
setrange key offset value 

如果key不存在,才设置value,即不会把覆盖原有的key值
setnx key value -> Set the value of a key, only if the key does not exist
msetnx key value [key value ...] 

设置会过期的key
setex key seconds value -> Set the value and expiration of a key
psetex key milliseconds value -> Set the value and expiration in milliseconds of a key

比特位相关的命令:
setbit key offset value -> Sets or clears the bit at offset in the string value stored at key
getbit key offset -> Returns the bit value at offset in the string value stored at key
bitcount key [start] [end] -> Count set bits in a string
bitpos key bit [start] [end] -> Find first bit set or clear in a string

bitop and destkey key [key ...] 对一个或多个 key 求逻辑并,并将结果保存到 destkey
bitop or destkey key [key ...] 对一个或多个 key 求逻辑或,并将结果保存到 destkey
bitop xor destkey key [key ...] 对一个或多个 key 求逻辑异或,并将结果保存到 destkey
bitop not destkey key 对给定 key 求逻辑非,并将结果保存到 destkey


Hashes命令:
查看hash的所有字段: hkeys key
查看hash的所有value:hvals key
获取所有字段和值: hgetall key
查看hash有多少个字段:hlen key

判断hash的字段是否存在: hexists key field
获取hash对应字段的值:hget key field
设置hash对应字段的值:hset key field value
                      hmget key field [field ...]
                      hmset key field value [field value ...] 

当不存在才设置字段的值,即不覆盖已有的值:hsetnx key field value
删除hash的字段:hdel key field [field ...]

hincrby key field increment -> Increment the integer value of a hash field
hincrbyfloat key field increment -> Increment the float value of a hash field

Lists: 列表
lpush key value [value ..] -> Prepend one or multiple values to a list
rpush key value [value ..] -> Append one or multiple values to a list
lpop key -> Remove and get the first element in a list
rpop key -> Remove and get the last element in a list
lindex key index -> Get an element from a list by its index
linsert key before|after pivot value -> Insert an element before or after another element in a list
lset key index value -> Set the value of an element in a list by its index
lrange key start stop -> Get a range of elements from a list
llen key -> Get the length of a list
lpushx key value -> Prepend a value to a list, only if the list exists
rpushx key value -> Append a value to a list, only if the list exists
rpoplpush source dest -> Remove the last element in a list, append it to another list and return it

blpop key [key ...] timeout -> Remove and get the first element in a list, or block until one is available
brpop key [key ...] timeout -> Remove and get the last element in a list, or block until one is available
brpoplpush source dest timeout -> Pop a value from a list, push it to another list and return it; or block until one is available

Sets:   集合
sadd key member [member ..]  -> Add one or more members to a set
scard key -> Get the number of members in a set
smembers key -> Get all the members in a set
sismember key member -> Determine if a given value is a member of a set
spop key -> Remove and return a random member from a set
srem key member [member..] -> Remove one or more members from a set
srandmember key [count] -> Get one or multiple random members from a set

sdiff key [key ...] -> Subtract multiple sets
sinter key [key ...] ->Intersect multiple sets
sunion key [key ...] -> Add multiple sets

Sorted Sets:  有序集合
zadd key score member [score member ...] -> Add one or more members to a sorted set, or update its score if it already exists
zcard key -> Get the number of members in a sorted set 
zscore key member -> Get the score associated with the given member in a sorted set

你可能感兴趣的:(redis)