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. 在Spring Boot使用H2内存数据库

    文章目录 添加依赖配置 数据库配置 添加初始数据 访问H2数据库 在Spring Boot使用H2内存数据库 在之前的文章中我们有提到在Spring Boot中使用H2内存数据库方便开发和测试.本文我 ...

  2. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  3. webpack打包多入口配置

    在它的entry入口设置多文件入口即可,例: entry: { core: './src/core.js', design: './src/design.js' }, 单一出口输出: output: ...

  4. python 类C数组的两种形式:list -->内容可变, tuple --->内容不可变

    python 中的列表相当与 C 中的数组,列表:list 初始化使用[ ], 元组:tuple 初始化使用(): 一.列表list 1 #!/usr/bin/python  2   3 #list初 ...

  5. 贪心--HDU 2021 发工资咯

    Description 作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵,但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就 ...

  6. 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)

    Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...

  7. postman(环境设置)

    1.点击小齿轮进入到环境变量添加页面,点击add添加环境变量 2.新增环境输入变量名称和变量值 3.添加成功 4.接口中设置变量,切换环境进行传参 5.调用环境变量断言 调用环境变量中的phone变量 ...

  8. Python安装第三方模块出错 No module named setuptools

    在安装 zabbix-alerta 第三方模块时候报错 python setup.py install 此时需要安装 setuptools 模块, 这里用自动化脚本安装 wget https://bo ...

  9. 题目分享X

    题意:一张票有n位数,如果这张票的前一半数字的和等于后一半数字的和(n一定是偶数),就称这张票为快乐票.有些数被擦除了,标记为’?’(’?‘的个数也是偶数),现在Monocarp 和 Bicarp 进 ...

  10. Unix的I/O模型

    对于一次I/O操作(以read为例),数据首先被拷贝到内核的某个缓冲区,然后再从内核缓冲区拷贝到应用进程缓冲区. 因此,一次I/O操作通常包含两个阶段: (1) 等待数据准备好 (2) 从内核向进程复 ...