使用场景:
给任意的项目提供原子的unique ID。
解决方案:
使用Redis内建的INCR函数
示例如下:
$redis-cli INCR<next_object_id>
(integer)1
$redis-cli INCR<next_object_id>
(integer)2
$redis-cli INCR<another_next_object_id>
(integer)1
$redis-cli GET<next_object_id>
2
$redis-cli GET<another_next_object_id>
1
说明:
使用INCR创建unique ID是Redis的核心功能。常用与关系型数据库主键上,用来替代关系型数据库中途类似功能的函数。
参考:rediscookbook
written by liuyu
文章转载自bestpaydata,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




