forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.py
More file actions
115 lines (95 loc) · 2.87 KB
/
redis.py
File metadata and controls
115 lines (95 loc) · 2.87 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Ultroid - UserBot
# Copyright (C) 2020 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}setredis key | value`
Redis Set Value.
e.g :
`{i}setredis hi there`
`{i}setredis hi there | ultroid here`
• `{i}getredis key`
Redis Get Value
• `{i}delredis key`
Delete Key from Redis DB
• `{i}renredis old keyname | new keyname`
Update Key Name
• `{i}getkeys`
Get the list of keys stored in Redis
"""
import re
from . import *
@ultroid_cmd(
pattern="setredis ?(.*)",
)
async def _(ult):
ok = await eor(ult, "`...`")
try:
delim = " " if re.search("[|]", ult.pattern_match.group(1)) is None else " | "
data = ult.pattern_match.group(1).split(delim)
udB.set(data[0], data[1])
redisdata = Redis(data[0])
await ok.edit(
"Redis Key Value Pair Updated\nKey : `{}`\nValue : `{}`".format(
data[0], redisdata
)
)
except BaseException:
await ok.edit("`Something Went Wrong`")
@ultroid_cmd(
pattern="getredis ?(.*)",
)
async def _(ult):
ok = await eor(ult, "`Fetching data from Redis`")
val = ult.pattern_match.group(1)
if val == "":
return await ult.edit(f"Please use `{hndlr}getkeys <keyname>`")
try:
value = Redis(val)
await ok.edit("Key: `{}`\nValue: `{}`".format(val, value))
except BaseException:
await ok.edit("`Something Went Wrong`")
@ultroid_cmd(
pattern="delredis ?(.*)",
)
async def _(ult):
ok = await eor(ult, "`Deleting data from Redis ...`")
try:
key = ult.pattern_match.group(1)
udB.delete(key)
await ok.edit(f"`Successfully deleted key {key}`")
except BaseException:
await ok.edit("`Something Went Wrong`")
@ultroid_cmd(
pattern="renredis ?(.*)",
)
async def _(ult):
ok = await eor(ult, "`...`")
delim = " " if re.search("[|]", ult.pattern_match.group(1)) is None else " | "
data = ult.pattern_match.group(1).split(delim)
if Redis(data[0]):
try:
udB.rename(data[0], data[1])
await ok.edit(
"Redis Key Rename Successful\nOld Key : `{}`\nNew Key : `{}`".format(
data[0], data[1]
)
)
except BaseException:
await ok.edit("Something went wrong ...")
else:
await ok.edit("Key not found")
@ultroid_cmd(
pattern="getkeys$",
)
async def _(ult):
ok = await eor(ult, "`Fetching Keys ...`")
keys = udB.keys()
msg = ""
for x in keys:
msg += "• `{}`".format(x) + "\n"
await ok.edit("**List of Redis Keys :**\n{}".format(msg))
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=Var.HNDLR)}"})