The invention discloses an identifier generation method and device based on Redis, and relates to the technical field of computers. A specific embodiment of the method comprises the steps of receivingan identifier generation request, and detecting whether a current main
database runs normally or not; if so, setting the main / standby switching flag bit as a first numerical value, and generating anidentifier by utilizing the main
database based on the
sign bit, the first numerical value and the serial number; and if soothe current main
database runs abnormally, setting the main / standby switching flag bit as a second numerical value, carrying out main / standby switching on the main database and a normally running standby database, and further generating an identifier by utilizing the standbydatabase based on the
sign bit, the second numerical value and the serial number. According to the embodiment, the values of the main and standby switching flag bits are different when the main database or the standby database is used, so that the uniqueness and
high availability of identifier generation are ensured, the disaster tolerance capability is high, and a single-point fault is avoided. By setting the idle bits, the ID length can be shortened, the occupation amount of the storage space is reduced, and subsequent dynamic expansion of other identification bits is facilitated.