+ [1.13 INCRBYFLOAT:对浮点数进行加法操作](#113_INCRBYFLOAT_291)
+ - [1.13.1 命令格式](#1131__292)
+ [1.14](#114_299)
一、字符串
字符串是redis最基本的类型,一个key对应一个value。String类型可以包含任何数据,包括普通的文字数据、图片、视频、音频、压缩文件等。
String类型是Redis最基本的数据类型,一个redis中字符串value最多是512M。
1.1 SET: 为字符串设置值
1.1.1 命令格式
SET key value [EX seconds] [PX milliseconds] [NX|XX]
设置key的值,如果 key 已经有值, SET 就覆写旧值,无视类型。
对于某个原本带有生存时间(TTL)的键来说, 当 SET 命令成功在这个键上执行时, 这个键原有的 TTL 将被清除。
1.1.2 可选参数
- EX second :设置键的过期时间为 second 秒。 SET key value EX second 效果等同于 SETEX key second value 。
- PX millisecond :设置键的过期时间为 millisecond 毫秒。 SET key value PX millisecond 效果等同于 PSETEX key millisecond value 。
- NX :只在键不存在时,才对键进行设置操作。 SET key value NX 效果等同于 SETNX key value 。
- XX :只在键已经存在时,才对键进行设置操作。
1.1.3 返回值
SET命令如果设置成功返回OK,如果设置失败则返回nil
1.1.4 使用实例
// 设置key
> set name "zhangsan"
OK
> get name
zhangsan
// 对已存在的key进行设置
> set name "lisi"
OK
> get name
lisi
// 设置过期时间秒
> set expire "hello"EX 10000
ERR unknown command `set expire "hello"ex 10000`, with args beginning with:
> set expire "hello" EX 10000
OK
> ttl expire
9993
> ttl expire
9992
> get expire
hello
// 设置过期时间毫秒
> set expirepx "hello" PX 10000
OK
> pttl expirepx
3000
> pttl expirepx
1172
> get expirepx
null
// N