【Redis四】Redis数据类型
Redis  /  管理员 发布于 3年前   319
Redis是一个高性能的数据结构服务器,称之为数据结构服务器的原因是,它提供了丰富的数据类型以满足不同的应用场景,本文对Redis的数据类型以及对这些类型可能的操作进行总结。
Redis常用的数据类型包括string、set、list、hash以及sorted set.Redis本身是K/V系统,这里的数据类型指的是value的类型,而不是key的类型,key的类型只有一种即string,Redis要求key这个字符串的长度必须大于1。
Redis提供了type命令用于判断key对应的value的类型,例如 type key,返回值有如下几种,
none,string,hash,set,sortedset,list,其中none表示value是nil。
string提供了如下操作:
localhost:6381> set key1 10OKlocalhost:6381> set key2 abcOKlocalhost:6381> set key3 this is a book(error) ERR syntax errorlocalhost:6381> set key3 "this is a book"OKlocalhost:6381> get key1"10"localhost:6381> ket ke2(error) ERR unknown command 'ket'localhost:6381> get key3"this is a book"localhost:6381> get key2"abc"localhost:6381>
localhost:6381> INCR count(integer) 1localhost:6381> set key1 abcOKlocalhost:6381> INCR key1(error) ERR value is not an integer or out of range
localhost:6381> INCRBY key4 10(integer) 10localhost:6381> INCRBY key4 100(integer) 110localhost:6381> INCRBY key4 -100(integer) 10localhost:6381> INCRBY key4 -200(integer) -190localhost:6381>
localhost:6381> getset abc 1"2"localhost:6381> getset key5 1(nil)localhost:6381> get key5"1"localhost:6381> getset key5 2"1"localhost:6381> get key5"2"localhost:6381>
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号