新增魅力值和财富值查询脚本
This commit is contained in:
82
python/peko_user_level_charm.py
Normal file
82
python/peko_user_level_charm.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import json
|
||||
|
||||
import redis
|
||||
|
||||
|
||||
class RedisUtil:
|
||||
def __init__(self, host, port, db, password):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
self.password = password
|
||||
|
||||
def scan(self, match: str):
|
||||
keys = []
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
cursor = 0
|
||||
while True:
|
||||
tup = res.scan(cursor=cursor, match=match, count=1000)
|
||||
print(tup)
|
||||
if isinstance(tup[0], int):
|
||||
cursor = tup[0]
|
||||
if isinstance(tup[1], list):
|
||||
keys.extend(tup[1])
|
||||
if cursor == 0:
|
||||
break
|
||||
except Exception as e:
|
||||
print('scan is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
return keys
|
||||
|
||||
def delete(self, name: str):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.delete(name)
|
||||
except Exception as e:
|
||||
print('delete ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
def hgetall(self, name: str):
|
||||
data = None
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
data = res.hgetall(name)
|
||||
except Exception as e:
|
||||
print('hget ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
return data
|
||||
|
||||
def hincrby(self, name: str, field, increment):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.hincrby(name, field, increment)
|
||||
except Exception as e:
|
||||
print('hincrby ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
def hdel(self, name: str, field):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.hdel(name, field)
|
||||
except Exception as e:
|
||||
print('hdel ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
util = RedisUtil(host='172.22.0.8', port=6379, db=0, password='pc8DphhaXwTe2jyv')
|
||||
charm = util.hgetall('peko_user_level_charm')
|
||||
if len(charm) == 0:
|
||||
print('charm is empty')
|
||||
else:
|
||||
print(charm)
|
||||
for keyByte, valueByte in charm.items():
|
||||
key = keyByte.decode('utf-8')
|
||||
value = valueByte.decode('utf-8')
|
||||
print(key, ',', value)
|
82
python/peko_user_level_exper.py
Normal file
82
python/peko_user_level_exper.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import json
|
||||
|
||||
import redis
|
||||
|
||||
|
||||
class RedisUtil:
|
||||
def __init__(self, host, port, db, password):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
self.password = password
|
||||
|
||||
def scan(self, match: str):
|
||||
keys = []
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
cursor = 0
|
||||
while True:
|
||||
tup = res.scan(cursor=cursor, match=match, count=1000)
|
||||
print(tup)
|
||||
if isinstance(tup[0], int):
|
||||
cursor = tup[0]
|
||||
if isinstance(tup[1], list):
|
||||
keys.extend(tup[1])
|
||||
if cursor == 0:
|
||||
break
|
||||
except Exception as e:
|
||||
print('scan is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
return keys
|
||||
|
||||
def delete(self, name: str):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.delete(name)
|
||||
except Exception as e:
|
||||
print('delete ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
def hgetall(self, name: str):
|
||||
data = None
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
data = res.hgetall(name)
|
||||
except Exception as e:
|
||||
print('hget ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
return data
|
||||
|
||||
def hincrby(self, name: str, field, increment):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.hincrby(name, field, increment)
|
||||
except Exception as e:
|
||||
print('hincrby ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
def hdel(self, name: str, field):
|
||||
res = redis.StrictRedis(host=self.host, port=self.port, db=self.db, password=self.password)
|
||||
try:
|
||||
res.hdel(name, field)
|
||||
except Exception as e:
|
||||
print('hdel ', name, ' is error.', e)
|
||||
finally:
|
||||
res.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
util = RedisUtil(host='172.22.0.8', port=6379, db=0, password='pc8DphhaXwTe2jyv')
|
||||
exper = util.hgetall('peko_user_level_exper')
|
||||
if len(exper) == 0:
|
||||
print('exper is empty')
|
||||
else:
|
||||
print(exper)
|
||||
for keyByte, valueByte in exper.items():
|
||||
key = keyByte.decode('utf-8')
|
||||
value = valueByte.decode('utf-8')
|
||||
print(key, ',', value)
|
Reference in New Issue
Block a user