连接到Redis
主要分为运维人员的连接和程序的连接
本机非密码连接
#redis-cli
跨主机非密码连接
redis-cli -h HOSTNAME/IP -p PORT
跨主机密码连接
redis-cli -h HOSTNAME/IP -p PORT -a PASSWORD
shell脚本写入数据到Redis
[root@centos8 ~]##cat redis_test.sh
#!/bin/bash
NUM=100000
PASS=123456
for i in seq $NUM
;do
redis-cli -h 127.0.0.1 -a "PASS" set key{i} value{i}
echo "key{i} value{i} 写入完成"
done
echo "NUM个key写入到Redis完成"
python连接方式
[root@centos8 ~]#yum -y install python3 python3-redis
[root@centos8 ~]#cat redis_test.py
#!/bin/env python3
import redis
#import time
pool = redis.ConnectionPool(host="127.0.0.1", port=6379,password="")
r = redis.Redis(connection_pool=pool)
for i in range(100):
r.set("k%d" % i,"v%d" % i)
# time.sleep(1)
data=r.get("k%d" % i)
print(data)
[root@centos8 ~]# python3 redis_test.py
......
b'v94'
b'v95'
b'v96'
b'v97'
b'v98'
b'v99'
[root@centos8 ~]#redis-cli
127.0.0.1:6379> get k10
"v10"
127.0.0.1:6379>
本文链接:http://www.yunweipai.com/35496.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/52776.html