cqlsh timezone设置

cqlsh timezone设置

Scylla/Cassandra 的timestamp 读取时间会默认使用UTC,cqlsh查询的时候默认时区默认+0,
如要在使用cqlsh的时候,查询时间戳按照本时区显示,需要如下设置:
1.安装依赖

pytz
By default, cqlsh displays all timestamps with a UTC timezone. To support display of timestamps with another timezone, the pytz library must be installed. See the timezone option in cqlshrc for specifying a timezone to use.

sudo pip install pytz

2.新建或在已有的cqlshrc文件中添加如下配置

[ui]
timezone = Asia/Shanghai

具体需要的时区可以在这里查阅:https://docs.djangoproject.com/zh-hans/2.2/_modules/pytz/

3.cqlsh执行配置–cqlshrc

cqlsh --cqlshrc=./cqlshrc

通过查询timestamp一列:
操作之前:

[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cassandra@cqlsh>select timestamp  from user_action.test where device_id='c64dc532'
 timestamp
--------------------------
 2019-04-21 22:11:55+0000

操作之后:

[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cassandra@cqlsh> select timestamp  from user_action.realtime_user_action where  device_id = 'c64dc532';
 timestamp
--------------------------
 2019-04-22 06:11:55+0800

可以观察到时区+08。如果需要以Driver的方式进行时区转换就是对应Driver API的事情啦。

你可能感兴趣的:(Cassandra)