-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
35 lines (25 loc) · 973 Bytes
/
db.py
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
29
30
31
32
33
34
35
# 存cookie和accounts
import redis
import random
from Cookies_pool.configs import *
class RedisClient:
def __init__(self, types, website, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD):
self.db = redis.StrictRedis(host=host, port=port, password=password, decode_responses=True)
self.type = types
self.website = website
def name(self):
return '{}:{}'.format(self.type, self.website)
def set(self, username, value):
return self.db.hset(self.name(), username, value)
def get(self, username):
return self.db.hget(self.name(), username)
def delete(self, username):
return self.db.hdel(self.name(), username)
def count(self):
return self.db.hlen(self.name())
def random(self):
return random.choice(self.db.hvals(self.name()))
def usernames(self):
return self.db.hkeys(self.name())
def all(self):
return self.db.hgetall(self.name())