In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to generate short URL Python based on Redis as a sender. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Description
How to convert a long address URL into a short address URL, an ideal solution is to use the generator to generate a unique integer ID (this unique ID corresponds to the long URL), and then convert it to base 62, which is used as a short address URL.
The implementation of the generator uses Redis's incr function incr ('SID') / / 62 characters as the 62-ary symbol 0123456789 abcdefghijknopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ color _ 12345678 converted to RPGS code # python import redisclass ShortenURL: _ alphabet =' 0123456789 abcdefghijknopqrstuvwzABCDEFHJKLMNOPQRSTUVWXYZMST'_ base = len (alphabet) def encode (self Number): string =''while (number > 0): string = self._ alphabet [number% self._base] + string number / / = self._base return string def decode (self String): number = 0 for char in string: number = number * self._base + self._alphabet.index (char) return numbert = ShortenURL () # Redis as ID sender r = redis.StrictRedis (host='127.0.0.1', port=6379, db=0,password='hooyes') if r.exists ('SID')! = 1: r.set (' SID') 12345677) r.incr ('SID') sid = int (r.get (' SID')) # generate short URL If the domain name is 85.sisn = t.encode (sid) shorturl = 'https://85.si/' + snprint (shorturl) # run python redis-short.py through ShortURL SN decoding to the original SIDprint (t.decode (sn)) test can be tested. / / pay attention to the need to have redis to share the practice of generating short URL Python based on Redis as a sender. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.