-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
53 lines (38 loc) · 1.21 KB
/
controller.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from settings import REDIS_DB, REDIS_HOST, REDIS_PORT
from core.helpers import RedisHelper
"""
make redis connection with redis helper
"""
redis = RedisHelper(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
# Get all keys with expression
def get_keys(search_key_expression):
all_keys = redis.get_all_keys(search_key_expression)
return all_keys, "array"
# Get one value by key
def get_value(key):
value = redis.get_value(key)
return value, "string"
# Set one value to key, create new one or update exist one
def set_value(key, value):
is_set = redis.set_value(key, value)
return is_set, "bool"
# Set key with expire time
def set_value_expire_time(key, value, expire_time):
is_set = redis.set_value_expire_time(key, value, expire_time)
return is_set, "bool"
# Check is key exist
def key_exist(key):
is_key_exist = redis.is_key_exists(key)
if is_key_exist:
status_code = 200
else:
status_code = 204
return status_code
# Delete one key
def delete_key(key):
is_deleted = redis.delete_key(key)
return is_deleted, "bool"
# Delete all key, in redis means flush db
def delete_all_keys():
is_deleted = redis.delete_all_keys()
return is_deleted, "bool"