1.基于连接池方式实现对五个数据类型操作,每种数据类型2个操作

2.基于spring-data-redis 基于jedis来实现对五种数据类型操作,每种数据类型实现两个操作,包括事务

以上为基于java语言开发

学员可以采用其它语言进行开发,要求如下:

1.总结你选择的框架的优缺点

2.五种数据类型基本操作,每种数据类型完成3个操作,额外增加事务的实现

3.必须把测试执行成功的效果图截图展示

一.windows+pycharm

1.windows导入python的redis包

C:\Users\Administrator>easy_install redis
Searching for redis
Reading https://pypi.python.org/simple/redis/
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:89: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:93: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
Downloading https://files.pythonhosted.org/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl#sha256=8a1900a9f2a0a44ecf6e8b5eb3e967a9909dfed219ad66df094f27f7d6f330fb
Best match: redis 2.10.6
Processing redis-2.10.6-py2.py3-none-any.whl
Installing redis-2.10.6-py2.py3-none-any.whl to d:\python\python36\lib\site-packages
Adding redis 2.10.6 to easy-install.pth file Installed d:\python\python36\lib\site-packages\redis-2.10.6-py3.6.egg
Processing dependencies for redis
Finished processing dependencies for redis

导入集群包

C:\Users\Administrator>easy_install  redis-py-cluster
Searching for redis-py-cluster
Reading https://pypi.python.org/simple/redis-py-cluster/
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:89: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:93: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
Downloading https://files.pythonhosted.org/packages/f1/dd/4bb27bb3e3d03a01b0afd4a4ba13a4677b0f2d6552ff2841ac56591bfb29/redis-py-cluster-1.3.5.tar.gz#sha256=e7349b1f2487d2c763088d81162e4a2ed91adee975c296bdba2ed96fd7450b36
Best match: redis-py-cluster 1.3.5
Processing redis-py-cluster-1.3.5.tar.gz
Writing C:\Users\ADMINI~1\AppData\Local\Temp\easy_install-q542vr0p\redis-py-cluster-1.3.5\setup.cfg
Running redis-py-cluster-1.3.5\setup.py -q bdist_egg --dist-dir C:\Users\ADMINI~1\AppData\Local\Temp\easy_install-q542vr0p\redis-py-cluster-1.3.5\egg-dist-tmp-dn6h7_rs
warning: no files found matching 'CHANGES'
zip_safe flag not set; analyzing archive contents...
Copying redis_py_cluster-1.3.5-py3.6.egg to d:\python\python36\lib\site-packages
Adding redis-py-cluster 1.3.5 to easy-install.pth file Installed d:\python\python36\lib\site-packages\redis_py_cluster-1.3.5-py3.6.egg
Processing dependencies for redis-py-cluster
Finished processing dependencies for redis-py-cluster

2.安装hiredis

C:\Users\Administrator>easy_install hiredis
Searching for hiredis
Reading https://pypi.python.org/simple/hiredis/
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:89: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
d:\python\python36\lib\site-packages\setuptools\pep425tags.py:93: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
warn=(impl == 'cp')):
Downloading https://files.pythonhosted.org/packages/1b/98/4766d85124b785ff1989ee1c79631a1b6ecfcb444ff39999a87877b2027e/hiredis-0.2.0.tar.gz#sha256=ca958e13128e49674aa4a96f02746f5de5973f39b57297b84d59fd44d314d5b5
Best match: hiredis 0.2.0
Processing hiredis-0.2.0.tar.gz
Writing C:\Users\ADMINI~1\AppData\Local\Temp\easy_install-sjunzzxy\hiredis-0.2.0\setup.cfg
Running hiredis-0.2.0\setup.py -q bdist_egg --dist-dir C:\Users\ADMINI~1\AppData\Local\Temp\easy_install-sjunzzxy\hiredis-0.2.0\egg-dist-tmp-6pm9mu31
warning: no previously-included files found matching 'vendor\hiredis\example*'
warning: no previously-included files found matching 'vendor\hiredis\text*'
error: Setup script exited with error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

http://www.liangchan.net/soft/download.asp?softid=10220&downid=8&id=10288

C:\Users\Administrator>pip install hiredis
Collecting hiredis
Using cached https://files.pythonhosted.org/packages/1b/98/4766d85124b785ff1989ee1c79631a1b6ecfcb444ff39999a87877b2027e/hiredis-0.2.0.tar.gz
Installing collected packages: hiredis
Running setup.py install for hiredis ... done
Successfully installed hiredis-0.2.0

3.更新pip

python -m pip install --upgrade pip
C:\Users\Administrator>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 228kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-18.0

二.python增删改查

2.1普通string值增删改查

# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import hiredis
import redis
rds=redis.StrictRedis(host='172.16.10.142',port=6379,password='foobared')
rds.set('k1','v1')
rds.set('k2','v2')
k1=rds.get('k1')
k2=rds.get('k2')
rds.mset({'k3':'v3','k4':'v4'})
rds.set('k5','123456')
print(k1);
print(rds.mget('k1','k2','k3','k4'));
print(rds.getrange('k5',0,2))
rds.delete('k1')
print(rds.get('k1'))
#
D:\Python\Python36\python.exe D:/04python/01_course/02redis/01redis_operate.py
b'v1'
[b'v1', b'v2', b'v3', b'v4']
b'123'
None

2.2hash

import redis
rds=redis.StrictRedis(host='172.16.10.142',port=6379,password='foobared')
rds.hset("h1_name","a1","aa")
print(rds.hget("h1_name","a1"))
print(rds.hgetall("h1_name"))
dict1={"d1":"v1","d2":"v2"}
rds.hmset("hd",dict1)
print(rds.hgetall("hd"))
print(rds.hlen("hd"))
#
b'aa'
{b'a1': b'aa'}
{b'd1': b'v1', b'd2': b'v2'}
2

2.3list

# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import redis
rds=redis.StrictRedis(host="172.16.10.142",password="foobared",port=6379)
rds.lpush('l1',2)
rds.lpush('l1',3,4,5)
rds.rpush('l2',1)
rds.rpush('l2',2,3,4)
print(rds.lrange('l1',0,-1))
print(rds.lrange('l2',0,-1))
print(rds.llen('l1'))
rds.delete("l1","l2")
# print(rds.lrange('l1',0,-1))
# print(rds.lrange('l2',0,-1))
#
[b'5', b'4', b'3', b'2']
[b'1', b'2', b'3', b'4']
4

2.4set和zset

# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import redis
rds=redis.StrictRedis(host='172.16.10.142',password='foobared',port=6379)
rds.sadd('sset1',1)
print(rds.smembers('sset1'))
rds.sadd('sset1',1,1,2,3)
print(rds.smembers('sset1'))
print(rds.scard('sset1'))
rds.delete('sset1')
rds.zadd('zset2',k1=2,k2=5,k3=3)
print(rds.zrange('zset2',0,-1))
print(rds.zcount('zset2',1,2))
#
{b'1'}
{b'3', b'1', b'2'}
3
[b'k1', b'k3', b'k2']
1

2.5事务

# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import redis
import time
from concurrent.futures import ProcessPoolExecutor
r=redis.StrictRedis(host='172.16.10.142',password='foobared',port=6379)
def try_pipeline():
start = time.time()
with r.pipeline(transaction=False) as p:
p.sadd('seta', 1).sadd('seta', 2).srem('seta', 2).lpush('lista', 1).lrange('lista', 0, -1)
p.execute()
print(r.smembers('seta'))
print(time.time() - start)
try_pipeline()
#
D:\Python\Python36\python.exe D:/04python/01_course/02redis/redisset.py
{b'1'}
0.017011165618896484
# type key 查看类型

python连接redis cluster

from rediscluster import StrictRedisCluster
import sys def redis_cluster():
redis_nodes = [{'host':'192.168.222.66','port':6378},
{'host':'192.168.222.66','port':6380},
{'host':'192.168.222.66','port':6381},
{'host':'192.168.222.66','port':6382},
{'host':'192.168.222.66','port':6383},
{'host':'192.168.222.66','port':6384},
{'host':'192.168.222.66','port':6385}
]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
except Exception,e:
print "Connect Error!"
sys.exit(1) redisconn.set('name','admin')
redisconn.set('age',18)
print "name is: ", redisconn.get('name')
print "age is: ", redisconn.get('age') redis_cluster()

redis python操作的更多相关文章

  1. Redis - Python操作Redis

    目录 Python操作Redis 一. Redis安装和基本使用 二. Python操作Redis API使用 1.操作模式 2.连接池 3.Django配置Redis 4.操作 Python操作Re ...

  2. redis python 操作 Python操作Redis数据库

    原文章于此:https://www.cnblogs.com/cnkai/p/7642787.html 有个人修改与改正 Python操作Redis数据库   连接数据库 StrictRedisfrom ...

  3. redis -- python操作连接redis简单示例

    1.先安装 redis,pyredis sudo pip install redis sudo pip install python-redis 2.示例: importredis >>& ...

  4. [ecmagent][redis学习][1初识redis] python操作redis

    #1 连接redis # 连接redis -- import redis -- 使用端口连接redis conn = redis.Redis(host=) -- 使用套接字连接 r = redis.R ...

  5. redis python操作api

    redis单例数据库 #redis单例连接 ''' redis-server redis_diy.conf ''' import redis conn=redis.StrictRedis(host=' ...

  6. python运维开发(十一)----python操作缓存memcache、redis

    内容目录: 缓存 memcache redis memcache Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数 ...

  7. Python 操作redis 常用方法

    Python 操作redis 1.字符串 #!/usr/bin/env python # -*- coding:utf-8 -*- import redis # python 操作str class ...

  8. python 操作redis之——HyperLogLog (八)

    #coding:utf8 import redis # python 操作redis之——HyperLogLog r =redis.Redis(host=") # 1.Pfadd 命令将所有 ...

  9. python操作Redis方法速记

    redis有5种数据结构,分别如下: 5种数据结构 python语言对5种数据结构的增删改查 全局函数 redis 连接 import redis pool = redis.ConnectionPoo ...

随机推荐

  1. Zabbix3.4安装部署

    Zabbix3.4安装部署 一.系统环境 cat /etc/redhat-release  CentOS Linux release 7.3.1611 (Core)  关闭防火墙及selinux sy ...

  2. rabbitMQ安装docker版 /权限管理命令

    1.进入docker hub镜像仓库地址:https://hub.docker.com/ 2.搜素rabbitMQ 查询镜像,可以看到多种类型,选择带有web页面的(managment) 3.拉取镜像 ...

  3. 【linux题目】第二关

    1.创建目录/data/oldboy,并且在该目录下创建文件oldboy.txt,然后在文件oldboy.txt里写入内容”inet addr:10.0.0.8 Bcast:10.0.0.255 Ma ...

  4. 在服务器本地监控服务端口命令之ss

    在服务器本地监控服务端口命令之ss 当服务器的socket连接数量变得非常大时,无论是使用netstat命令还是直接cat /proc/net/tcp,执行速度都会很慢.可能你不会有 切身的感受,但当 ...

  5. Eclipse Collections:让Java Streams更上一层楼

    \ 关键要点 \\ Eclipse Collections是一个高性能的Java集合框架,为原生JDK集合增加了丰富的功能.\\t Streams是JDK的一个非常受欢迎的功能,但它缺少了一些特性,严 ...

  6. 01-复杂度2 Maximum Subsequence Sum

    01-复杂度2 Maximum Subsequence Sum   (25分) 时间限制:200ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 htt ...

  7. Frame Relay Voice Traffic Shaping and Frament

    本文全称应该是:Frame Relay Voice-Adaptive Traffic Shaping and Fragmentation,标题限制字数,没办法了   帧中继的流量整型向来是个头疼的地方 ...

  8. POJ2421 Constructing Roads 最小生成树

    修路 时限: 2000MS   内存限制: 65536K 提交总数: 31810   接受: 14215 描述 有N个村庄,编号从1到N,您应该修建一些道路,使每两个村庄可以相互连接.我们说两个村庄A ...

  9. 一只简单的网络爬虫(基于linux C/C++)————线程相关

    爬虫里面采用了多线程的方式处理多个任务,以便支持并发的处理,把主函数那边算一个线程的话,加上一个DNS解析的线程,以及我们可以设置的max_job_num值,最多使用了1+1+max_job_num个 ...

  10. 网络流中的图像转化为OpenCV中的Mat类型

    1,从网络中读取到的图像流,不支持查找,不能直接转化为Mat类型 2,例子如下: string Url = "http://192.168.0.110/cgi-bin/camera?reso ...