[root@dev-server-1 master-slave]# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> set site blog.jboost.cn
OK
127.0.0.1:6379> get site
"blog.jboost.cn"
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=7001,state=online,offset=13364738,lag=1
slave1:ip=127.0.0.1,port=7002,state=online,offset=13364738,lag=0
...
127.0.0.1:6379> exit
[root@dev-server-1 master-slave]# redis-cli -p 7001
127.0.0.1:7001> auth 123456
OK
127.0.0.1:7001> get site
"blog.jboost.cn"
[root@dev-server-1 cluster]# redis-cli -p 7100 -c -a passw0rd
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:7100> set site blog.jboost.cn
-> Redirected to slot [9421] located at 127.0.0.1:7200
OK
127.0.0.1:7200> get site
"blog.jboost.cn"
127.0.0.1:7200>
注意添加 -c 参数表示以集群模式,否则报 (error) MOVED 9421 127.0.0.1:7200 错误, 以 -a 参数指定密码,否则报(error) NOAUTH Authentication required错误。
从上面命令看到key为site算出的slot为9421,落在7200节点上,所以有Redirected to slot [9421] located at 127.0.0.1:7200,集群会自动进行跳转。因此客户端可以连接任何一个节点来进行数据的存取。
比如: “-“.join(str(n) for n in range(100))语句执行3趟,每趟10000次的时间统计如下测试:
一、 终端命令行方式:
python -m timeit -n 10000 -r 3 -v ‘”-“.join(str(n) for n in range(100))’
raw times: 0.345 0.351 0.329
10000 loops, best of 3: 32.9 usec per loop
每次执行了10000次,共执行3次,最好的1次,平均每loop是32.9 usec(32.9微秒,10000 loops,best of 3的意思是一共repeat了3次,每一次10000 loops,取最好的那一次来平均)。32.9 usec就是这一行python表达式的执行时间。
二、python模块内方式:
>>> import timeit
>>> timeit.timeit(‘”-“.join(str(n) for n in range(100))’, number = 10000)
0.3615691661834717
>>> timeit.repeat(‘”-“.join(str(n) for n in range(100))’, number = 10000, repeat=3)[0.37982702255249023, 0.3650989532470703, 0.3783681392669678]
三、jupyter note使用方式
%timeit -n 1000 -r 3 “-“.join(str(n) for n in range(100))
05-2417:17:47.3352444724478 D EventBusActivity: 2447805-2417:17:48.3412444724478 D EventBusActivity: this is first message ! onEventBackground thread:2447805-2417:17:48.3412444724498 D EventBusActivity: this is first message ! onEventAsync thread:2449805-2417:17:48.3422444724447 D EventBusActivity: this is first message ! onEventMain thread:2444705-2417:17:48.3422444724447 D EventBusActivity: this is first message ! onEventMainOrdered thread:2444705-2417:17:48.3442444724478 D EventBusActivity: this is first message ! onEventPosting thread:24478
/**
* Start an image request using the specified path. This is a convenience method for calling
* {@link #load(Uri)}.
* <p>
* This path may be a remote URL, file resource (prefixed with {@code file:}), content resource
* (prefixed with {@code content:}), or android resource (prefixed with {@code
* android.resource:}.
* <p>
* Passing {@code null} as a {@code path} will not trigger any request but will set a
* placeholder, if one is specified.
*
* @see #load(Uri)
* @see #load(File)
* @see #load(int)
* @throws IllegalArgumentException if {@code path} is empty or blank string.
*/publicRequestCreatorload(String path){if(path ==null){returnnewRequestCreator(this,null,0);}if(path.trim().length()==0){thrownewIllegalArgumentException("Path must not be empty.");}returnload(Uri.parse(path));}
Transformation 这就是Picasso的一个非常强大的功能了,它允许你在load图片 -> into ImageView 中间这个过成对图片做一系列的变换。比如你要做图片高斯模糊、添加圆角、做度灰处理、圆形图片等等都可以通过Transformation来完成。
来看一个高斯模糊的例子:
1,首先定义一个转换器继承 Transformation
publicstaticclassBlurTransformationimplementsTransformation{RenderScript rs;publicBlurTransformation(Context context){super();
rs =RenderScript.create(context);}@OverridepublicBitmaptransform(Bitmap bitmap){// Create another bitmap that will hold the results of the filter.Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888,true);// Allocate memory for Renderscript to work withAllocation input =Allocation.createFromBitmap(rs, blurredBitmap,Allocation.MipmapControl.MIPMAP_FULL,Allocation.USAGE_SHARED);Allocation output =Allocation.createTyped(rs, input.getType());// Load up an instance of the specific script that we want to use.ScriptIntrinsicBlur script =ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
script.setInput(input);// Set the blur radius
script.setRadius(25);// Start the ScriptIntrinisicBlur
script.forEach(output);// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();return blurredBitmap;}@OverridepublicStringkey(){return"blur";}}
LRU memory cache of 15% the available application RAM
Disk cache of 2% storage space up to 50MB but no less than 5MB. (Note: this is only
available on API 14+ <em>or</em> if you are using a standalone library that provides a disk cache on all API levels like OkHttp)
Three download threads for disk and network access.
/** Describes where the image was loaded from. */publicenumLoadedFrom{MEMORY(Color.GREEN),DISK(Color.BLUE),NETWORK(Color.RED);finalint debugColor;privateLoadedFrom(int debugColor){this.debugColor = debugColor;}}
/**
* Created by zhouwei on 17/2/26.
*/publicclassCustomDownloaderimplementsDownloader{@OverridepublicResponseload(Uri uri,int networkPolicy)throwsIOException{returnnull;}@Overridepublicvoidshutdown(){}}
/**
* Set the global instance returned from {@link #with}.
* <p>
* This method must be called before any calls to {@link #with} and may only be called once.
*/publicstaticvoidsetSingletonInstance(Picasso picasso){synchronized(Picasso.class){if(singleton !=null){thrownewIllegalStateException("Singleton instance already exists.");}
singleton = picasso;}}
jar -cvfM0 spingboot-ouu-test.jar . //(M后面是数字0,如果只使用参数cf,java -jar spingboot-ouu-test.jar启动springboot jar项目时将提示“没有主清单属性”)
附:
jar -tvf spingboot-ouu-test.jar //查看jar包文件结构
jar命令常用参数:
c :创建一个 jar 包
t :显示 jar 包里面的内容
x :解压 jar 包
u :添加文件到 jar包
f :指定 jar 包的文件名
v :在 CMD 显示详细执行过程(报告)
m :指定 manufest.mf 文件(该文件可以对jar包及其内容做设置)
0 :打包 jar包 时不压缩
M :不产生 manufest.mf 文件,覆盖 m 参数的设置
i :为打包的 jar包 创建索引文件
c :进入某目录后再执行 jar 命令,相当于 cd 进入目录然后不带 c 参数执行 jar命令