将来的你
一定会感谢现在拼命努力的自己

连接到Redis各种方式

连接到Redis

主要分为运维人员的连接和程序的连接

本机非密码连接

#redis-cli

1 #redis-cli
跨主机非密码连接

redis-cli -h HOSTNAME/IP -p PORT

1 redis - cli - h HOSTNAME / IP - p PORT
跨主机密码连接

redis-cli -h HOSTNAME/IP -p PORT -a PASSWORD

1 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完成"

1 2 3 4 5 6 7 8 9 10 [ 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>

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 [ 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 >

赞(0) 打赏
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除,联系邮箱:contact@3yyy.top。文章观点不代表本站立场。本站原创内容未经允许不得转载:三叶运维 » 连接到Redis各种方式
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

https://beian.miit.gov.cn/