// SetMulti sets multiple items in cache
SetMulti sets multiple items in cache
// SetMulti sets multiple items in cache
func (c *Cache) SetMulti(items map[string][]byte, expire time.Duration) error {
	conn := c.Pool.Get()
	defer conn.Close()
	var (
		keys   []string
		params []interface{}
		mErr   MultiError
	)
	for key, val := range items {
		keys = append(keys, key)
		params = append(params, key)
		params = append(params, val)
	}
	conn.Send("MSET", params...)
	if expire >= time.Second {
		for _, key := range keys {
			conn.Send("EXPIRE", key, int(expire.Seconds()))
		}
	}
	conn.Flush()
	if _, err := conn.Receive(); err != nil {
		return err
	}
	if expire >= time.Second {
		for _, key := range keys {
			if _, err := conn.Receive(); err != nil {
				mErr[key] = fmt.Errorf("dscache.Cache.SetMulti: EXPIRE %s Error %v", key, err)
			} else {
				mErr[key] = nil
			}
		}
	}
	if mErr.Count() > 0 {
		return mErr
	}
	return nil
}
func ( c * Cache ) SetMulti ( items map [ string ] [ ] byte , expire time . Duration ) error { conn := c . Pool . Get ( ) defer conn . Close ( ) var ( keys [ ] string params [ ] interface { } mErr MultiError ) for key , val := range items { keys = append ( keys , key ) params = append ( params , key ) params = append ( params , val ) } conn . Send ( " " , params ... ) if expire >= time . Second { for _ , key := range keys { conn . Send ( " " , key , int ( expire . Seconds ( ) ) ) } } conn . Flush ( ) if _ , err := conn . Receive ( ) ; err != nil { return err } if expire >= time . Second { for _ , key := range keys { if _ , err := conn . Receive ( ) ; err != nil { mErr [ key ] = fmt . Errorf ( " " , key , err ) } else { mErr [ key ] = nil } } } if mErr . Count ( ) > 0 { return mErr } return nil }
SetMulti sets multiple items in cache
SetMulti sets multiple items in cache