/**
 * Copyright 2024 Beijing Baolande Software Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Runtime Library Exception to the Apache 2.0 License:
 *
 * As an exception, if you use this Software to compile your source code and
 * portions of this Software are embedded into the binary product as a result,
 * you may redistribute such product without providing attribution as would
 * otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.
 */

package string_example

import redis_sdk.client.api.*
import redis_sdk.client.commands.*
import redis_sdk.client.*

main() {
    let redisClient = RedisClientBuilder.builder().host("127.0.0.1").port(6379).password("mypassword").respVersion(3).
        readTimeout(Duration.second * 60).writeTimeout(Duration.second * 30).receiveBufferSize(32768).sendBufferSize(
        32768).build()

    let key1 = "redis_example_test_key1"
    let value1 = "redis_example_test_value1"
    let timeoutInSeconds = 10 // 10秒钟后过期
    println("SET ${key1} ${value1} EX ${timeoutInSeconds}")
    var status = redisClient.set(key1, value1, SetParams().ex(timeoutInSeconds))
    println(status.getOrThrow())

    println("GET ${key1}")
    var result = redisClient.get(key1)
    println(result.getOrThrow())

    let key2 = "redis_example_test_key2"
    let value2 = "redis_example_test_value2"
    let timeoutInMillSeconds = 5000 // 5000毫秒钟后过期
    println("SET ${key2} ${value2} PX ${timeoutInSeconds}")
    status = redisClient.set(key2, value2, SetParams().px(timeoutInMillSeconds))
    println(status.getOrThrow())

    println("GET ${key2}")
    result = redisClient.get(key2)
    println(result.getOrThrow())
}