"""
  @author: LinTao
  @time: 2022/10/30 11:28
  @desc:
"""

# import socket
#
# s = socket.socket()
# s.connect(('127.0.0.1', 6379))
#
# s.send(b'*3\r\n')
# s.send(b'$3\r\n')
# s.send(b'set\r\n')
# s.send(b'$5\r\n')
# s.send(b'phone\r\n')
# s.send(b'$11\r\n')
# s.send(b'18812345678\r\n')
#
# r = s.recv(1024)
# print(r.decode())


import redis

# 指定Redis服务器的IP地址，端口号和数据库进行连接
# red = redis.Redis(host='127.0.0.1', port=6379, db=0)

# 推荐使用连接池的方式
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, decode_responses=True,
                            db=0, password='redis666')
red = redis.Redis(connection_pool=pool)

red.hmset(name='mykey', mapping={'addr': '孵化园', 'tel': '123456789', 'employee': 200})
red.hset(name='mykey', key='name', value='蜗牛学院')
red.hsetnx(name='mykey', key='name', value='蜗牛学院2')
dict = red.hgetall('mykey')
print(dict)