设置主从库: 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长度
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
判断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
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