-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.py
More file actions
28 lines (18 loc) · 639 Bytes
/
db.py
File metadata and controls
28 lines (18 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from utils import base36_encode
def insert_url(redis, url):
short_id = redis.get("reverse-url:" + url)
if short_id is not None:
return short_id
url_num = redis.incr("last-url-id")
short_id = base36_encode(url_num)
redis.set("url-target:" + short_id, url)
redis.set("reverse-url:" + url, short_id)
return short_id
def get_url(redis, short_id):
return redis.get("url-target:" + short_id)
def increment_url(redis, short_id):
redis.incr("click-count:" + short_id)
def get_count(redis, short_id):
return int(redis.get("click-count:" + short_id) or 0)
def get_list_urls(redis):
pass