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. 2019-2020-1 20199325《Linux内核原理与分析》第十一周作业

    实验简介: Set-UID 是 Unix 系统中的一个重要的安全机制.当一个 Set-UID 程序运行的时候,它被假设为具有拥有者的权限.例如,如果程序的拥有者是root,那么任何人运行这个程序时都会 ...

  2. Oracle 11g 精简客户端

    通常开发人员会装上一个 oracle客户端,但一般不会在自己的机器上安装Oracle database Oracle 客户端安装体积很大,但是装上去了基本上就用2个功能:TNS配置服务名和sqlplu ...

  3. CentOS 7.4 安装网易云音乐

    1.下包–>网易云音乐 Ubuntu14.04(推荐14.04依赖包网上能找到) 提示:16.04有部分依赖包还找不到,有兴趣可以自行打包RPM安装. 2.解包 (1)使用 ar -vx解压ub ...

  4. [Windows] Diskpart Scripts and Examples

    https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart-scripts-and ...

  5. 第十二章Linux文件系统与日志

    1.inode 包含文件的元信息(1)inode 内容:文件的字节数.拥有者的 UID.GID.文件的读写执行权限.时间戳等,但不包含文件名.文件名是储存在目录的目录项中.(2)查看文件的 inode ...

  6. 李宏毅机器学习--PM2.5预测

    一.说明 给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量. 训练集介绍: (1).CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天的 ...

  7. 用C++模拟蚊子的运动来检验概率论内容

    背景:在一个很大的方形透明容器内,从某个位置放入适量的蚊子,等待几分钟后观察蚊子的分布. #include <iostream> #include <cstdlib> #inc ...

  8. 【Linux网络基础】TCP/IP协议簇的详细介绍(三次握手四次断开,11种状态)

    一.TCP/IP协议簇(DoD参考模型) 用于简化OSI层次,以及相关的标准. 传输控制协议(tcp/ip)簇是相关国防部DoD所创建的,主要用来确保数据的完整性以及在毁灭性战争中维持通信 是由一组不 ...

  9. 基于规则的分类——RIPPER算法

    在<分类:基于规则的分类技术>中已经比较详细的介绍了基于规则的分类方法,RIPPER算法则是其中一种具体构造基于规则的分类器的方法.在RIPPER算法中,有几个点是算法的重要构成部分,需要 ...

  10. python笔记 函数初识

    1. 函数: 封装一个功能 def    my_len(形参):          ->  def  声明定义一个函数   my_len 函数名命名规则同变量 ······          - ...