Redis 字符串(String)介绍以及操作

存储内容:字符串,整数,浮点数

命令 操作
set 存储给定键的值
get 获取给定键的值
del 删除给定键的值
incr 给键存储的值加1
decr 给键存储的值减1
incrby 给键存储的值加指定的大小
decrby 给键存储的值减去特定的大小
incrbyfloat 给键存储的值加指定的浮点数大小(Redis版本必须大于2.6)
append 将值追加到给定键的末尾
setrange 将一个偏移量为start开始的设置为给定值
getrange 获取一个偏移量在start到end所有字符组成的子串
getbit 获取二进制的值
setbit 设置一个位串的二进制的值
bitcount 统计二进制位串里面值位1的数量,可以给定偏移量
bittop 统计二进制位串里面值位1的数量,可以给定偏移量
--基本增删改操作
redis 127.0.0.1:6379> set myKey test
OK
redis 127.0.0.1:6379> get myKey
"test"
redis 127.0.0.1:6379> del myKey
(integer) 1
redis 127.0.0.1:6379> get myKey
(nil)
--增减操作
redis 127.0.0.1:6379> set test-key 25
OK
redis 127.0.0.1:6379> get test-key
"25"
redis 127.0.0.1:6379> incr test-key
(integer) 26
redis 127.0.0.1:6379> decr test-key
(integer) 25
redis 127.0.0.1:6379> incrby test-key 666
(integer) 691
redis 127.0.0.1:6379> decrby test-key 690
(integer) 1
redis 127.0.0.1:6379> set test-key-float 25.0
OK
redis 127.0.0.1:6379> incrbyfloat test-key-float 54.54
(error) ERR unknown command 'incrbyfloat'
--其他操作
redis 127.0.0.1:6379> get test-key
"55"
redis 127.0.0.1:6379> append test-key 5
(integer) 3
redis 127.0.0.1:6379> get test-key
"555"
redis 127.0.0.1:6379> setrange test-key 0 HH
(integer) 3
redis 127.0.0.1:6379> get test-key
"HH5"
redis 127.0.0.1:6379> set test-key helloworld
OK
redis 127.0.0.1:6379> setrange test-key 2 L
(integer) 10
redis 127.0.0.1:6379> get test-key
"heLloworld"
redis 127.0.0.1:6379> getrange test-key 0 3
"heLl"
redis 127.0.0.1:6379> append test-key this is a append sentence.
(error) ERR wrong number of arguments for 'append' command
redis 127.0.0.1:6379> append test-key this is a append sentence
(error) ERR wrong number of arguments for 'append' command
redis 127.0.0.1:6379> append test-key  6
(integer) 11
redis 127.0.0.1:6379> get test-key
"heLloworld6"
redis 127.0.0.1:6379> set bit-key 5
OK
redis 127.0.0.1:6379> getbit bit-key
(error) ERR wrong number of arguments for 'getbit' command
redis 127.0.0.1:6379> getbit bit-key 2
(integer) 1
redis 127.0.0.1:6379> getbit bit-key 3
(integer) 1
redis 127.0.0.1:6379> getbit bit-key 0
(integer) 0
redis 127.0.0.1:6379> setbit bit-key 0 1
(integer) 0
redis 127.0.0.1:6379> get bit-key
"\xb5"
redis 127.0.0.1:6379>

你可能感兴趣的:(redis)