我正在寻找如何使用
hedis通过Unix域套接字连接到redis服务器,如hackage页面中所宣传的那样:
Connect via TCP or Unix Domain Socket:
TCP sockets are the default way
to connect to a Redis server. For connections to a server on the same
machine,Unix domain sockets offer higher performance than the
standard TCP connection.
从ConnectInfo
的构造函数,以及defaultConnectInfo
,似乎我们应该填写connectPort,因为它的类型PortID有一个名为UnixSocket的构造函数.但它只显示UnixSocket是一个字符串,没有格式细节等.
那么如何通过Unix域套接字填写connectPort进行连接?谢谢.
更新:我试了一下,发现并不难.以下是我的问候世界.
{-# LANGUAGE OverloadedStrings #-} import Control.Monad.Trans import Database.Redis myConnectInfo :: ConnectInfo myConnectInfo = defaultConnectInfo { connectPort = UnixSocket "/tmp/redis.sock" } main :: IO () main = do conn <- connect myConnectInfo runRedis conn $do set "hello" "hello" set "world" "world" hello <- get "hello" world <- get "world" liftIO $print (hello,world)
我根本不是Haskell用户,我无法测试它,但我会说你必须在这个字符串中提供套接字文件的路径.
代替:
connectPort = PortNumber 6379
你将会拥有:
connectPort = UnixSocket "/tmp/redis.sock"
当然,应使用以下参数在服务器端Redis配置文件中声明/tmp/redis.sock:
# Specify the path for the unix socket that will be used to listen for # incoming connections. There is no default,so Redis will not listen # on a unix socket when not specified. # unixsocket /tmp/redis.sock unixsocketperm 755
原文地址:https://www.jb51.cc/bash/384942.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。