AWS RDS 跨区域同步

Read full article  | 评论关闭

 

CALL mysql.rds_set_external_master (‘mymasterserver.mydomain.com’, 3306, ‘repl_user’, ‘<password>’, ‘mysql-bin-changelog.000031′, 107, 0);

CALL mysql.rds_start_replication;

 

Read More

redis key 迁移

Read full article  | 评论关闭

 

当slave, migrate 等方法不能用时,直接用dump/restore

redis-cli  -h cn-vpc-redis-session.aftjvu.0001.cnn1.cache.amazonaws.com.cn -n 1 keys “*”  | while read key  ;do redis-cli -h cn-vpc-redis-session.aftjvu.0001.cnn1.cache.amazonaws.com.cn -n 1 –raw dump $key  | head -c-1 | redis-cli -n 0 -x restore  $key  0 ;done

Read More

json 序列化

Read full article  | 评论关闭

 

 

Json反序列化如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
#coding: utf-8
import json
dict = {'name':'zhangsan', 'age':33, 'address':'红星路'}
print('未序列化前的数据类型为:', type(dict))
print('为序列化前的数据:', dict)
#对dict进行序列化的处理
dict_xu = json.dumps(dict,ensure_ascii=False#添加ensure_ascii=False进行序列化
print('序列化后的数据类型为:', type(dict_xu))
print('序列化后的数据为:', dict_xu)
#对dict_xu进行反序列化处理
dict_fan = json.loads(dict_xu)
print('反序列化后的数据类型为:', type(dict_fan))
print('反序列化后的数据为: ', dict_fan)

Read More

RAP2-delos 添加API参数500错误

Read full article  | 评论关闭

原因是

数据库表Properties中的字段priority, 其属性为int(11)

但传入的数据为:1524666729233   (这个值应该是时间戳)

 

可以将priority的属性调整一下,比如 bigint(50)

 

Read More

GITLAB /var/opt/gitlab/.ssh/authorized_keys 未更新

Read full article  | 评论关闭

 

用户添加public key 后,/var/opt/gitlab/.ssh/authorized_keys 未更新, 重启sidekiq即可!

$ sudo gitlab-ctl kill sidekiq

$ sudo gitlab-ctl start sidekiq

Read More

GITLAB 修改DNS

Read full article  | 评论关闭

 

修改文件 “/var/opt/gitlab/gitlab-rails/etc/gitlab.yml”

修改成如下的样子就好了哦。

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.ops.ac.cn
    port: 80
    https: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Read More

mongoengine 更新

Read full article  | 评论关闭

mongoengine 更新

collection.update({‘userid’:int(float(item))},{‘$set’:{‘status’:1}},upsert=False,multi=True)

有兴趣可以研究一下update的四个参数:

第一个为匹配

第二个为条件(条件上可以大作文章),

第三个为没找到是否插入,

第四个为是否支持多操作

Read More

python dict 合并

Read full article  | 评论关闭

a = [{"id":"1","name":"test001"},{"id":"2","name":"test002"}]

b = [{"id":"1","score":"9"},{"id":"2","score":"8"}]

list(map(lambda x,y:dict(x,**y),a,b))

Read More

django view太大,切分到不同的目录

Read full article  | 评论关闭

(新增目录下面一定得有__init__.py,    方法1,需要修改__init__.py,  方法2可以将__init__.py 保持为空)

备注:view 子目录引用model, 可用 from app_name.models import * 方式引用, 记得加上 app_name

方法1:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/__init__.py

This is an important step: import all the modules inside each view file.

from .alpha import *
from .beta import *

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]

方法2:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]



Read More

virtualenv 准备django 环境

Read full article  | 评论关闭

virtualenv ./env_chq -p /opt/apps/python/bin/python

pip install django

django-admin startproject pj_chq .

python manage.py startapp app_chq

Read More