- Read String,list,set,sort_set,hash type of data
ImportRedisclassDataBase:def __init__(self, host, port): Self.host=host Self.port=Portdefread_string (self, key):Try: R= Redis. Strictredis (Host=self.host, port=self.port) Result=r.get (Key)returnresultexceptException as Exception:Print(Exception)defread_list (self, key, N):Try: R= Redis. Strictredis (Host=self.host, port=self.port)ifn >R.llen (key): Result= R.lrange (0,-1) Else: Result=R.lrange (key, 0, N)returnresultexceptException as Exception:Print(Exception)defRead_set (self, key):Try: R= Redis. Strictredis (Host=self.host, port=self.port) Result=r.smembers (Key)returnresultexceptException as Exception:Print(Exception)defRead_hash (self, key):Try: R= Redis. Strictredis (Host=self.host, port=self.port) Result=R.hgetall (Key)returnresultexceptException as Exception:Print(Exception)defRead_sort_set (self, key, N):Try: R= Redis. Strictredis (Host=self.host, port=self.port)ifn >R.zcard (key): Result= R.zrange (0,-1) Else: Result=r.zrange (0, N)returnresultexceptException as Exception:Print(Exception)
python-reading data from the Redis database